Class: ViewComponent::Storybook::Controls::Number

Inherits:
SimpleControl show all
Defined in:
lib/view_component/storybook/controls/number.rb

Constant Summary collapse

TYPES =
%i[number range].freeze

Instance Attribute Summary collapse

Attributes inherited from Control

#default, #description, #name, #param

Instance Method Summary collapse

Methods inherited from SimpleControl

#to_csf_params

Methods inherited from Control

#to_csf_params

Constructor Details

#initialize(param, type:, default: nil, min: nil, max: nil, step: nil, name: nil, description: nil, **opts) ⇒ Number

Returns a new instance of Number.



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

def initialize(param, type:, default: nil, min: nil, max: nil, step: nil, name: nil, description: nil, **opts)
  super(param, default: default, name: name, description: description, **opts)
  @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.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.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.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.rb', line 9

def type
  @type
end

Instance Method Details

#parse_param_value(value) ⇒ Object



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

def parse_param_value(value)
  if value.is_a?(String) && value.present?
    (value.to_f % 1) > 0 ? value.to_f : value.to_i
  else
    value
  end
end