Class: ViewComponent::Storybook::Controls::CustomConfig

Inherits:
ControlConfig
  • Object
show all
Defined in:
lib/view_component/storybook/controls/custom_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ControlConfig

#description, #initialize, #name, #prefix_param

Constructor Details

This class inherits a constructor from ViewComponent::Storybook::Controls::ControlConfig

Instance Attribute Details

#value_method_argsObject (readonly)

Returns the value of attribute value_method_args.



7
8
9
# File 'lib/view_component/storybook/controls/custom_config.rb', line 7

def value_method_args
  @value_method_args
end

Instance Method Details

#param(new_param = nil) ⇒ Object



17
18
19
20
# File 'lib/view_component/storybook/controls/custom_config.rb', line 17

def param(new_param = nil)
  value_method_args.with_param_prefix(new_param) unless new_param.nil?
  super(new_param)
end

#to_csf_paramsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/view_component/storybook/controls/custom_config.rb', line 22

def to_csf_params
  validate!
  # TODO: Figure out if we can use 'category' with the args table
  # export default {
  #   argTypes: {
  #     foo: {
  #       table: { category: 'cat', subcategory: 'sub' }
  #     }
  #   }
  # }
  value_method_args.controls.reduce({}) do |csf_params, control|
    csf_params.deep_merge(control.to_csf_params)
  end
end

#value_from_params(params) ⇒ Object



37
38
39
# File 'lib/view_component/storybook/controls/custom_config.rb', line 37

def value_from_params(params)
  value_method_args.call(params)
end

#with_value(*args, **kwargs, &block) ⇒ Object



11
12
13
14
15
# File 'lib/view_component/storybook/controls/custom_config.rb', line 11

def with_value(*args, **kwargs, &block)
  @value_method_args = MethodArgs::ControlMethodArgs.new(block, *args, **kwargs)
  @value_method_args.with_param_prefix(param)
  self
end