Class: ActionView::Storybook::Controls::OptionsConfig

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

Constant Summary collapse

TYPES =
%i[select multi-select radio inline-radio check inline-check].freeze

Instance Attribute Summary collapse

Attributes inherited from ControlConfig

#name, #param, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ControlConfig

#to_csf_params

Constructor Details

#initialize(type, param, options, default_value, name: nil) ⇒ OptionsConfig

Returns a new instance of OptionsConfig.


27
28
29
30
31
32
# File 'lib/action_view/storybook/controls/options_config.rb', line 27

def initialize(type, param, options, default_value, name: nil)
  super(param, default_value, name: name)
  @type = type
  @options = options
  @symbol_value = default_value.is_a?(Symbol)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.


21
22
23
# File 'lib/action_view/storybook/controls/options_config.rb', line 21

def options
  @options
end

#symbol_valueObject (readonly)

Returns the value of attribute symbol_value.


21
22
23
# File 'lib/action_view/storybook/controls/options_config.rb', line 21

def symbol_value
  @symbol_value
end

#typeObject (readonly)

Returns the value of attribute type.


21
22
23
# File 'lib/action_view/storybook/controls/options_config.rb', line 21

def type
  @type
end

Class Method Details

.inclusion_in(config) ⇒ Object

support the options being a Hash or an Array. Storybook supports either.


9
10
11
12
13
14
15
16
# File 'lib/action_view/storybook/controls/options_config.rb', line 9

def inclusion_in(config)
  case config.options
  when Hash
    config.options.values
  when Array
    config.options
  end
end

Instance Method Details

#value_from_param(param) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/action_view/storybook/controls/options_config.rb', line 34

def value_from_param(param)
  if param.is_a?(String) && symbol_value
    param.to_sym
  else
    super(param)
  end
end