Class: ViewComponent::Storybook::Slots::SlotConfig

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, ContentConcern
Defined in:
lib/view_component/storybook/slots/slot_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentConcern

#content, #resolve_content_block

Constructor Details

#initialize(slot_name, slot_method_args, param, content_block) ⇒ SlotConfig

Returns a new instance of SlotConfig.



14
15
16
17
18
19
# File 'lib/view_component/storybook/slots/slot_config.rb', line 14

def initialize(slot_name, slot_method_args, param, content_block)
  @slot_name = slot_name
  @slot_method_args = slot_method_args
  @param = param
  @content_block = content_block
end

Instance Attribute Details

#content_blockObject (readonly)

Returns the value of attribute content_block.



10
11
12
# File 'lib/view_component/storybook/slots/slot_config.rb', line 10

def content_block
  @content_block
end

#paramObject (readonly)

Returns the value of attribute param.



10
11
12
# File 'lib/view_component/storybook/slots/slot_config.rb', line 10

def param
  @param
end

#slot_method_argsObject (readonly)

Returns the value of attribute slot_method_args.



10
11
12
# File 'lib/view_component/storybook/slots/slot_config.rb', line 10

def slot_method_args
  @slot_method_args
end

#slot_nameObject (readonly)

Returns the value of attribute slot_name.



10
11
12
# File 'lib/view_component/storybook/slots/slot_config.rb', line 10

def slot_name
  @slot_name
end

Class Method Details

.from_component(component_class, slot_name, param, *args, **kwargs, &block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/view_component/storybook/slots/slot_config.rb', line 21

def self.from_component(component_class, slot_name, param, *args, **kwargs, &block)
  new(
    slot_name,
    slot_method_args(component_class, slot_name, *args, **kwargs).with_param_prefix(param),
    param,
    block
  )
end

Instance Method Details

#content_paramObject



42
43
44
# File 'lib/view_component/storybook/slots/slot_config.rb', line 42

def content_param
  "#{param}__content".to_sym
end

#controlsObject



36
37
38
39
40
# File 'lib/view_component/storybook/slots/slot_config.rb', line 36

def controls
  list = slot_method_args.controls.dup
  list << content_control if content_control
  list
end

#slot(component, params) ⇒ Object



30
31
32
33
34
# File 'lib/view_component/storybook/slots/slot_config.rb', line 30

def slot(component, params)
  resolved_method_args = slot_method_args.resolve_method_args(params)
  story_content_block = resolve_content_block(params)
  Slot.new(component, slot_name, resolved_method_args, story_content_block)
end