Class: StimulusPlumbers::Components::List::Section

Inherits:
Plumber::Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/components/list/section.rb

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#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

#initialize(template, heading_level: nil) ⇒ Section

Returns a new instance of Section.



7
8
9
10
# File 'lib/stimulus_plumbers/components/list/section.rb', line 7

def initialize(template, heading_level: nil)
  super(template)
  @heading_level = heading_level
end

Instance Method Details

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



28
29
30
# File 'lib/stimulus_plumbers/components/list/section.rb', line 28

def item(content = nil, **kwargs, &block)
  List::Item.new(template).render(content, **kwargs, &block)
end

#render(title: nil, description: nil, **kwargs, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stimulus_plumbers/components/list/section.rb', line 12

def render(title: nil, description: nil, **kwargs, &block)
  html_options = merge_html_options(theme.resolve(:list_section), kwargs)
  template.(:li, **html_options) do
    template.safe_join(
      [
        render_section_header(title, description),
        render_section_body(title, &block)
      ]
    )
  end
end

#sectionObject



24
25
26
# File 'lib/stimulus_plumbers/components/list/section.rb', line 24

def section(...)
  List::Section.new(template, heading_level: (@heading_level || 0) + 1).render(...)
end