Class: ViewComponent::Storybook::Controls::SimpleControlConfig

Inherits:
ControlConfig
  • Object
show all
Defined in:
lib/view_component/storybook/controls/simple_control_config.rb

Overview

A simple Control Config maps to one Storybook Control It has a value and pulls its value from params by key

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ControlConfig

#description, #name, #param, #prefix_param

Constructor Details

#initialize(default_value, param: nil, name: nil, description: nil) ⇒ SimpleControlConfig

Returns a new instance of SimpleControlConfig.



12
13
14
15
# File 'lib/view_component/storybook/controls/simple_control_config.rb', line 12

def initialize(default_value, param: nil, name: nil, description: nil)
  super(param: param, name: name, description: description)
  @default_value = default_value
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



10
11
12
# File 'lib/view_component/storybook/controls/simple_control_config.rb', line 10

def default_value
  @default_value
end

Instance Method Details

#to_csf_paramsObject



17
18
19
20
21
22
23
24
25
# File 'lib/view_component/storybook/controls/simple_control_config.rb', line 17

def to_csf_params
  validate!
  {
    args: { param => csf_value },
    argTypes: {
      param => { control: csf_control_params, name: name, description: description }.compact
    }
  }
end

#value_from_params(params) ⇒ Object



27
28
29
# File 'lib/view_component/storybook/controls/simple_control_config.rb', line 27

def value_from_params(params)
  params.key?(param) ? params[param] : default_value
end