Class: Tramway::ButtonComponent
Overview
Constant Summary
collapse
- DEFAULT_BUTTON_CLASSES =
%w[
inline-flex items-center justify-center rounded-md font-medium ring-offset-background transition-colors
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2
disabled:pointer-events-none disabled:opacity-50
].freeze
ColorsMethods::TYPE_COLOR_MAP
Helpers::ViewsHelper::FORM_SIZES
Instance Method Summary
collapse
#tooltip_options
#normalized_type, #resolved_color, #type_color
#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_chat, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title, #tramway_tooltip
#component
#tramway_decorate
Instance Method Details
#before_render ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/components/tramway/button_component.rb', line 54
def before_render
validate_tooltip!
return if tag.present?
@tag = if tag_button?
:button
elsif tag_a?
:a
else
:form
end
end
|
#classes ⇒ Object
83
84
85
86
87
88
89
|
# File 'app/components/tramway/button_component.rb', line 83
def classes
(default_button_classes +
size_classes.split +
color_classes +
(@tag == :a ? [] : [cursor_class]) +
options[:class].to_s.split).compact.join(' ')
end
|
#color_classes ⇒ Object
91
92
93
|
# File 'app/components/tramway/button_component.rb', line 91
def color_classes
theme_classes classic: color_classes_collection
end
|
#color_classes_collection ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/components/tramway/button_component.rb', line 95
def color_classes_collection
return %w[bg-gray-800 text-gray-500 shadow-inner] if disabled?
case normalized_type
when :default, :life, :secondary
['hover:bg-zinc-200', 'bg-zinc-50', 'text-zinc-950']
when :inverse
['hover:bg-zinc-800', 'bg-zinc-950', 'text-zinc-50', 'border', 'border-zinc-800']
else
["hover:bg-#{resolved_color}-900 bg-#{resolved_color}-900/30 text-#{resolved_color}-400"]
end
end
|
79
80
81
|
# File 'app/components/tramway/button_component.rb', line 79
def default_button_classes
DEFAULT_BUTTON_CLASSES
end
|
#disabled? ⇒ Boolean
108
109
110
|
# File 'app/components/tramway/button_component.rb', line 108
def disabled?
options[:disabled] || false
end
|
#render_options ⇒ Object
112
113
114
115
116
117
|
# File 'app/components/tramway/button_component.rb', line 112
def render_options
base_options = options.except(:class)
return base_options unless stop_cell_propagation?
base_options.merge(onclick: merged_onclick(base_options[:onclick]))
end
|
#size_classes ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/components/tramway/button_component.rb', line 67
def size_classes
unless normalized_size.in?(%i[small medium large])
raise ArgumentError, "Invalid size: #{size}. Valid sizes are :small, :medium, :large."
end
{
small: 'text-sm py-1 px-2 rounded',
medium: 'text-sm py-2 px-4 h-10',
large: 'text-xl px-5 py-3 h-12'
}[normalized_size]
end
|