Class: ViewComponent::Storybook::Controls::SimpleControlConfig
- Inherits:
-
ControlConfig
- Object
- ControlConfig
- ViewComponent::Storybook::Controls::SimpleControlConfig
- 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
Direct Known Subclasses
BaseOptionsConfig, BooleanConfig, ColorConfig, DateConfig, NumberConfig, ObjectConfig, TextConfig
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
Instance Method Summary collapse
-
#initialize(default_value, param: nil, name: nil, description: nil) ⇒ SimpleControlConfig
constructor
A new instance of SimpleControlConfig.
- #to_csf_params ⇒ Object
- #value_from_params(params) ⇒ Object
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_value ⇒ Object (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_params ⇒ Object
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 |