Class: StimulusPlumbers::Components::Button

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

Defined Under Namespace

Classes: Group

Constant Summary

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#merge_data_options, #merge_html_options, #merge_string_option, #normalize_part

Constructor Details

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

Instance Method Details

#group(alignment: :left, direction: :row, **kwargs, &block) ⇒ Object



22
23
24
# File 'lib/stimulus_plumbers/components/button.rb', line 22

def group(alignment: :left, direction: :row, **kwargs, &block)
  Button::Group.new(template).render(alignment: alignment, direction: direction, **kwargs, &block)
end

#render(content = nil, url: nil, external: false, variant: :primary, size: :md, **kwargs, &block) ⇒ Object



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

def render(content = nil, url: nil, external: false, variant: :primary, size: :md, **kwargs, &block)
  content      = template.capture(&block) if block_given?
  html_options = merge_html_options(
    { classes: theme.resolve(:button, variant: variant, size: size).fetch(:classes, "") },
    kwargs
  )

  if url
    html_options[:target] = "_blank" if external
    template.(:a, content, href: url, **html_options)
  else
    html_options[:type] ||= "button"
    template.(:button, content, **html_options)
  end
end