Class: Optics::Button::Component
Constant Summary
collapse
- SIZES =
%w[small medium large].freeze
- STYLES =
%w[default primary secondary delete].freeze
Instance Method Summary
collapse
accepts, #class_for, #class_names, #class_names_for, #container_class, #data_for, #data_method, #data_target, #data_values, #identifier, inherited, #initialize, requires
Instance Method Details
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
|
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
|
#call ⇒ Object
20
21
22
23
24
|
# File 'app/components/optics/button/component.rb', line 20
def call
build_button do
content || label
end
end
|
#classes ⇒ Object
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_class ⇒ Object
52
53
54
55
56
|
# File 'app/components/optics/button/component.rb', line 52
def size_class
return if size == 'medium'
"btn--#{size}"
end
|