Class: Optics::Button::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/optics/button/component.rb

Constant Summary collapse

SIZES =
%w[small medium large].freeze
STYLES =
%w[default primary secondary delete].freeze

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

accepts, #class_for, #class_names, #class_names_for, #container_class, #data_for, #data_method, #data_target, #data_values, #identifier, inherited, #initialize, requires

Constructor Details

This class inherits a constructor from Optics::ApplicationViewComponent

Instance Method Details

#build_buttonObject



26
27
28
29
30
# File 'app/components/optics/button/component.rb', line 26

def build_button(&)
  return link_to(url, class: classes, **@attributes.except(:class), &) if url && !disabled

  tag.button(class: classes, disabled:, **@attributes.except(:class), &)
end

#button_classObject



32
33
34
35
36
# File 'app/components/optics/button/component.rb', line 32

def button_class
  return 'btn' if variant == 'default'

  "btn-#{variant}"
end

#callObject



20
21
22
23
24
# File 'app/components/optics/button/component.rb', line 20

def call
  build_button do
    content || label
  end
end

#classesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/optics/button/component.rb', line 38

def classes
  class_names(
    @attributes[:class],
    button_class,
    size_class,
    'btn--active': active,
    'btn--disabled': disabled,
    'btn--icon': icon,
    'btn--icon-with-label': icon_with_label,
    'btn--no-border': !border,
    'btn--pill': pill
  ).join(' ')
end

#size_classObject



52
53
54
55
56
# File 'app/components/optics/button/component.rb', line 52

def size_class
  return if size == 'medium'

  "btn--#{size}"
end