Class: DesignSystem::Generic::ButtonComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/design_system/generic/button_component.rb

Overview

Submit button rendered by ds_button_tag. Brand subclasses add their button classes and style modifiers. Content can be supplied via the first argument or a block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CssHelper

#css_class_options_merge

Methods included from BrandDerivable

#brand

Constructor Details

#initialize(content_or_options = nil, options = nil) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



7
8
9
10
11
# File 'app/components/design_system/generic/button_component.rb', line 7

def initialize(content_or_options = nil, options = nil)
  super()
  @content_or_options = content_or_options
  @options = options
end

Instance Attribute Details

#content_or_optionsObject (readonly)

Returns the value of attribute content_or_options.



13
14
15
# File 'app/components/design_system/generic/button_component.rb', line 13

def content_or_options
  @content_or_options
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'app/components/design_system/generic/button_component.rb', line 13

def options
  @options
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/design_system/generic/button_component.rb', line 15

def call
  button_options = prep_button_options(content_or_options, options)
  style = button_options.delete('style')
  button_options['aria-disabled'] = true if button_options['disabled']
  button_options = css_class_options_merge(button_options, ["#{brand}-button"]) do |classes|
    style_class = style_class_hash[style]
    classes << style_class if style_class
  end
  if content.present?
    button_tag(button_options) { content }
  else
    button_tag(content_or_options, button_options)
  end
end