Class: StimulusPlumbers::Components::List::Item

Inherits:
Plumber::Base show all
Defined in:
lib/stimulus_plumbers/components/list/item.rb,
lib/stimulus_plumbers/components/list/item/slots.rb

Defined Under Namespace

Classes: Slots

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::Renderer

#set_slots, #slot_block_for, #slot_kwargs_for, #slot_renderable?

Methods included from Plumber::Options::Aria

#labelled_aria

Methods included from Plumber::Options::Html

#merge_html_options

Constructor Details

This class inherits a constructor from StimulusPlumbers::Plumber::Base

Instance Method Details

#build(**kwargs, &block) ⇒ Object



20
21
22
23
# File 'lib/stimulus_plumbers/components/list/item.rb', line 20

def build(**kwargs, &block)
  html_options = merge_html_options(theme.resolve(:list_item), kwargs)
  template.capture(html_options, &block)
end

#render(content = nil, **kwargs) {|slots| ... } ⇒ Object

Yields:

  • (slots)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/stimulus_plumbers/components/list/item.rb', line 7

def render(content = nil, **kwargs, &block)
  slots = List::Item::Slots.new
  slots.with_title(content) if content
  slots.with_icon_trailing("external-link") if kwargs[:url].present? && kwargs[:target] == "_blank"
  yield slots if block_given?

  template.(:li) do
    build(**kwargs) do |attrs|
      render_link_or_button(**attrs) { render_item_slots(slots) }
    end
  end
end