Class: BackpackUi::ButtonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/backpack_ui/button_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, icon:, type: 'button', options: {}) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



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

def initialize(text:, icon:, type: 'button', options: {})
  @text = text
  @icon = icon
  @type = type
  @options = options.reverse_merge(defaults)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#sizeObject



27
28
29
30
31
32
33
# File 'app/components/backpack_ui/button_component.rb', line 27

def size
  {
    small: "sm-btn-small",
    medium: "sm-btn-medium",
    large: "sm-btn-large",
  }
end

#styleObject



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

def style
  {
    primary: "sm-btn-primary",
    secondary: "sm-btn-secondary",
    tertiary: "sm-btn-tertiary",
    outline: "sm-btn-outline",
    outline_dark: "sm-btn-outline-dark",
    link: "sm-btn-link",
    delete: "sm-btn-delete",
    no_outline: "sm-btn-no-outline",
  }[options[:classification].to_sym] + " " + "sm-btn" + " " + size[options[:size].to_sym]
end