Class: Practical::Views::ButtonComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Practical::Views::Button::Styling
Defined in:
app/components/practical/views/button_component.rb

Direct Known Subclasses

OpenDialogButtonComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ElementHelper

#grab, #mix

Constructor Details

#initialize(type:, appearance: nil, color_variant: nil, size: nil, options: {}) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



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

def initialize(type:, appearance: nil, color_variant: nil, size: nil, options: {})
  @type = type
  @options = options
  initialize_style_utilities(appearance: appearance, color_variant: color_variant, size: size)
end

Instance Attribute Details

#appearanceObject

Returns the value of attribute appearance.



5
6
7
# File 'app/components/practical/views/button_component.rb', line 5

def appearance
  @appearance
end

#color_variantObject

Returns the value of attribute color_variant.



5
6
7
# File 'app/components/practical/views/button_component.rb', line 5

def color_variant
  @color_variant
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'app/components/practical/views/button_component.rb', line 5

def options
  @options
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'app/components/practical/views/button_component.rb', line 5

def size
  @size
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'app/components/practical/views/button_component.rb', line 5

def type
  @type
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/practical/views/button_component.rb', line 13

def call
  defaults = {
    type: type,
    class: css_classes_from_style_utilities
  }

  if type.to_sym == :submit
    defaults[:data] = { disable: true }
  end

  finalized_options = mix(defaults, options)

  tag.button(content, **finalized_options)
end