Class: ActionView::Storybook::Controls::NumberConfig

Inherits:
ControlConfig
  • Object
show all
Defined in:
lib/action_view/storybook/controls/number_config.rb

Constant Summary collapse

TYPES =
%i[number range].freeze

Instance Attribute Summary collapse

Attributes inherited from ControlConfig

#name, #param, #value

Instance Method Summary collapse

Methods inherited from ControlConfig

#to_csf_params

Constructor Details

#initialize(type, param, value, min: nil, max: nil, step: nil, name: nil) ⇒ NumberConfig

Returns a new instance of NumberConfig.



14
15
16
17
18
19
20
# File 'lib/action_view/storybook/controls/number_config.rb', line 14

def initialize(type, param, value, min: nil, max: nil, step: nil, name: nil)
  super(param, value, name: name)
  @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/action_view/storybook/controls/number_config.rb', line 9

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



9
10
11
# File 'lib/action_view/storybook/controls/number_config.rb', line 9

def min
  @min
end

#stepObject (readonly)

Returns the value of attribute step.



9
10
11
# File 'lib/action_view/storybook/controls/number_config.rb', line 9

def step
  @step
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/action_view/storybook/controls/number_config.rb', line 9

def type
  @type
end

Instance Method Details

#value_from_param(param) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/action_view/storybook/controls/number_config.rb', line 22

def value_from_param(param)
  if param.is_a?(String) && param.present?
    (param.to_f % 1) > 0 ? param.to_f : param.to_i
  else
    super(param)
  end
end