Class: StimulusPlumbers::Components::Button

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

Defined Under Namespace

Classes: Group, 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(type: :default, variant: :primary, size: :md, **kwargs, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/stimulus_plumbers/components/button.rb', line 20

def build(type: :default, variant: :primary, size: :md, **kwargs, &block)
  html_options = merge_html_options(
    theme.resolve(:button, type: type, variant: variant, size: size),
    kwargs
  )
  template.capture(html_options, &block)
end

#render(content = nil, icon_leading: nil, icon_trailing: nil, **kwargs, &block) ⇒ Object



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

def render(content = nil, icon_leading: nil, icon_trailing: nil, **kwargs, &block)
  slots = Button::Slots.new
  slots.with_icon_leading(icon_leading) if icon_leading
  slots.with_icon_trailing(icon_trailing) if icon_trailing

  build(**kwargs) do |html_options|
    template.(:button, type: "button", **html_options) do
      build_layout(slots) do
        build_button(content, &block)
      end
    end
  end
end