Class: StimulusPlumbers::Components::Checklist

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

Defined Under Namespace

Classes: Item

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

#item(content = nil, **kwargs, &block) ⇒ Object



19
20
21
22
# File 'lib/stimulus_plumbers/components/checklist.rb', line 19

def item(content = nil, **kwargs, &block)
  @item_states << kwargs[:checked] if @item_states && !kwargs[:readonly]
  Checklist::Item.new(template).render(content, **kwargs, &block)
end

#render(label: nil, labelledby: nil, select_all: false, select_all_label: "Select all", **kwargs, &block) ⇒ Object



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

def render(label: nil, labelledby: nil, select_all: false, select_all_label: "Select all", **kwargs, &block)
  @item_states = [] if select_all
  captured = template.capture(self, &block)
  master = select_all ? render_select_all(select_all_label) : nil
  html_options = merge_html_options(
    theme.resolve(:checklist),
    kwargs,
    { role: "group", aria: labelled_aria(label, labelledby: labelledby) }
  )
  html_options = merge_html_options(html_options, select_all_wrapper_attrs) if select_all
  template.(:div, template.safe_join([master, captured].compact), **html_options)
end