Class: Avo::ButtonComponent
Constant Summary
Concerns::FindAssociationField::ASSOCIATIONS
Instance Method Summary
collapse
#has_with_trial
#find_association_field
Instance Method Details
#args ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/components/avo/button_component.rb', line 19
def args
if @args[:loading]
@args[:"data-controller"] = "loading-button"
@args[:"data-action"] = "click->loading-button#attemptSubmit"
end
@args[:class] = button_classes
@args[:aria] = @aria
@args
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/components/avo/button_component.rb', line 31
def button_classes
classes = "button-component inline-flex flex-grow-0 items-center font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 transform transition duration-100 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70 justify-center #{@class}"
classes += " border active:outline active:outline-1" unless is_icon?
classes += " rounded" if @rounded.present?
classes += style_classes
classes += horizontal_padding_classes
classes += vertical_padding_classes
classes += text_size_classes
classes
end
|
#call ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/components/avo/button_component.rb', line 74
def call
if is_link?
output_link
else
output_button
end
end
|
#full_content ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/components/avo/button_component.rb', line 58
def full_content
result = ""
icon_classes = class_names(@icon_class, "pointer-events-none", icon_size_classes, "mr-1": content.present? && is_not_icon?)
result += helpers.svg(@icon, class: icon_classes) if @icon.present?
if is_not_icon? && content.present?
result += content
end
result.html_safe
end
|
#is_icon? ⇒ Boolean
50
51
52
|
# File 'app/components/avo/button_component.rb', line 50
def is_icon?
@style == :icon
end
|
#is_link? ⇒ Boolean
46
47
48
|
# File 'app/components/avo/button_component.rb', line 46
def is_link?
@is_link
end
|
#is_not_icon? ⇒ Boolean
54
55
56
|
# File 'app/components/avo/button_component.rb', line 54
def is_not_icon?
!is_icon?
end
|
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/components/avo/button_component.rb', line 88
def output_button
if args.dig(:method).present? || args.dig(:data, :turbo_method).present?
button_to args[:url], **args do
full_content
end
else
button_tag(**args) do
full_content
end
end
end
|
#output_link ⇒ Object
82
83
84
85
86
|
# File 'app/components/avo/button_component.rb', line 82
def output_link
link_to @path, **args do
full_content
end
end
|