Class: ViewComponent::Storybook::Controls::NumberConfig

Inherits:
SimpleControlConfig show all
Defined in:
lib/view_component/storybook/controls/number_config.rb

Constant Summary collapse

TYPES =
%i[number range].freeze

Instance Attribute Summary collapse

Attributes inherited from SimpleControlConfig

#default_value

Instance Method Summary collapse

Methods inherited from SimpleControlConfig

#to_csf_params

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

#maxObject (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

#minObject (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

#stepObject (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

#typeObject (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