Class: ViewComponent::Storybook::Controls::NumberConfig
- Inherits:
-
SimpleControlConfig
- Object
- ControlConfig
- SimpleControlConfig
- ViewComponent::Storybook::Controls::NumberConfig
- Defined in:
- lib/view_component/storybook/controls/number_config.rb
Constant Summary collapse
- TYPES =
%i[number range].freeze
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from SimpleControlConfig
Instance Method Summary collapse
-
#initialize(type, default_value, min: nil, max: nil, step: nil, param: nil, name: nil, description: nil) ⇒ NumberConfig
constructor
A new instance of NumberConfig.
- #value_from_params(params) ⇒ Object
Methods inherited from SimpleControlConfig
Methods inherited from ControlConfig
#description, #name, #param, #prefix_param, #to_csf_params
Constructor Details
#initialize(type, default_value, min: nil, max: nil, step: nil, param: nil, name: nil, description: nil) ⇒ NumberConfig
Returns a new instance of NumberConfig.
14 15 16 17 18 19 20 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 14 def initialize(type, default_value, min: nil, max: nil, step: nil, param: nil, name: nil, description: nil) super(default_value, param: param, name: name, description: description) @type = type @min = min @max = max @step = step end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 9 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 9 def min @min end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
9 10 11 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 9 def step @step end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 9 def type @type end |
Instance Method Details
#value_from_params(params) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/view_component/storybook/controls/number_config.rb', line 22 def value_from_params(params) params_value = super(params) if params_value.is_a?(String) && params_value.present? (params_value.to_f % 1) > 0 ? params_value.to_f : params_value.to_i else params_value end end |