Class: Coco::Button
Constant Summary
collapse
- SIZES =
[:xs, :sm, :md, :lg, nil]
- SIZE_ALIASES =
{
default: [:sm, {xl: :md}]
}
- THEMES =
[
"primary",
"text-primary",
"secondary",
"text-secondary",
"positive",
"text-positive",
"negative",
"text-negative",
"warning",
"text-warning",
"info",
"text-info",
"toolbar",
"toolbar-floating",
"text-toolbar",
"neutral-dark",
"neutral-light",
"text-neutral-light",
"text-neutral-dark",
"blank",
nil
]
- DEFAULT_THEME =
"primary"
Concerns::AcceptsTagAttributes::TAG_ATTRIBUTE_NAMES
Instance Attribute Summary collapse
Instance Method Summary
collapse
coco_avatar, coco_button, coco_button_group, coco_embed, coco_icon, coco_image, coco_link_to_modal, coco_modal, coco_modal_data_attributes, coco_modal_dialog, coco_modal_frame_id, coco_modal_lightbox, coco_placeholder, coco_prose, coco_spacer, coco_stack, coco_svg, coco_tag
#accepted_options, #get_option_group
Methods inherited from Component
#accepts_options?, after_initialize, before_initialize, before_render, new
#x_attrs, #x_data
Methods included from TagHelper
#prefix_attr_keys, #random_id, #style_str
#coco_component, #resolve_component
Methods included from AppHelper
#coco_app_header, #coco_color_picker_button, #coco_confirm_button, #coco_dropdown_button, #coco_fields, #coco_form_for, #coco_form_with, #coco_image_picker_button, #coco_layout, #coco_layout_picker_button, #coco_link, #coco_menu_button, #coco_menu_item, #coco_notice, #coco_page, #coco_panel, #coco_seamless_textarea, #coco_sidebar_nav, #coco_sidebar_nav_menu, #coco_snackbar, #coco_stamp, #coco_system_banner, #coco_toast, #coco_toolbar
Methods included from BookHelper
#coco_editable_slide, #coco_media_slide
#tt
#component_name
#tag_attrs
Constructor Details
#initialize(click: nil, resize: nil, states: nil, loading: false, active: false, static: nil, **kwargs) ⇒ Button
Returns a new instance of Button.
76
77
78
79
80
81
82
83
|
# File 'app/components/coco/shared/button/button.rb', line 76
def initialize(click: nil, resize: nil, states: nil, loading: false, active: false, static: nil, **kwargs)
@on_click = click
@resize = resize.to_h
@states = states.to_h
@loading = loading
@static = static
@active = active
end
|
Instance Attribute Details
#on_click ⇒ Object
Returns the value of attribute on_click.
74
75
76
|
# File 'app/components/coco/shared/button/button.rb', line 74
def on_click
@on_click
end
|
#resize ⇒ Object
Returns the value of attribute resize.
74
75
76
|
# File 'app/components/coco/shared/button/button.rb', line 74
def resize
@resize
end
|
Instance Method Details
#active? ⇒ Boolean
121
122
123
|
# File 'app/components/coco/shared/button/button.rb', line 121
def active?
@active == true
end
|
#alpine_data ⇒ Object
184
185
186
|
# File 'app/components/coco/shared/button/button.rb', line 184
def alpine_data
{tooltips: state_tooltips} if state_tooltips.present?
end
|
#alpine_wrapper_attrs ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'app/components/coco/shared/button/button.rb', line 150
def alpine_wrapper_attrs
if dropdown? || confirm?
{
data: x_data("buttonDropdown"),
dropdown: jsify_data({placement: get_option_value(:dropdown, :placement)}.compact),
bind: "root"
}
end
end
|
141
142
143
|
# File 'app/components/coco/shared/button/button.rb', line 141
def button?
button_tag == :button
end
|
101
102
103
|
# File 'app/components/coco/shared/button/button.rb', line 101
def button_tag
tag_attr(:href).present? ? :a : :button
end
|
#button_text ⇒ Object
105
106
107
|
# File 'app/components/coco/shared/button/button.rb', line 105
def button_text
text&.to_s || content&.to_s || ""
end
|
#confirm? ⇒ Boolean
125
126
127
|
# File 'app/components/coco/shared/button/button.rb', line 125
def confirm?
get_option_value(:confirm)
end
|
#disabled? ⇒ Boolean
133
134
135
|
# File 'app/components/coco/shared/button/button.rb', line 133
def disabled?
get_option_value(:disabled)
end
|
#icon_only? ⇒ Boolean
145
146
147
148
|
# File 'app/components/coco/shared/button/button.rb', line 145
def icon_only?
(@states.none? && button_text.blank?) ||
!states.find { _2[:text].present? }
end
|
#link? ⇒ Boolean
137
138
139
|
# File 'app/components/coco/shared/button/button.rb', line 137
def link?
button_tag == :a
end
|
#loading? ⇒ Boolean
117
118
119
|
# File 'app/components/coco/shared/button/button.rb', line 117
def loading?
@loading == true
end
|
178
179
180
181
182
|
# File 'app/components/coco/shared/button/button.rb', line 178
def state_tooltips
@_tooltips = states.map do |name, props|
[name, props[:tooltip]] if props[:tooltip].present?
end.compact.to_h
end
|
#states ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'app/components/coco/shared/button/button.rb', line 160
def states
@_states ||= begin
states = default_states.deep_merge(@states)
states.each do |name, props|
if props.key?(:icon)
if props[:icon] == false
props.except!(:icon) else
props[:icon] = render_icon(props[:icon])
end
elsif icon?
props[:icon] = icon end
end.compact.transform_keys { _1.to_s.camelcase(:lower) }
end
end
|
#static? ⇒ Boolean
109
110
111
112
113
114
115
|
# File 'app/components/coco/shared/button/button.rb', line 109
def static?
@_static ||= if @static.nil?
!(confirm? || dropdown? || tooltip? || @states.any? || on_click.present? || get_option_value(:collapsible) || tag_attrs.key?(:x))
else
@static
end
end
|
#toggle? ⇒ Boolean
93
94
95
|
# File 'app/components/coco/shared/button/button.rb', line 93
def toggle?
toggle_direction.present? && button_text.present?
end
|
#toggle_direction ⇒ Object
97
98
99
|
# File 'app/components/coco/shared/button/button.rb', line 97
def toggle_direction
get_option_value(:toggle)
end
|
129
130
131
|
# File 'app/components/coco/shared/button/button.rb', line 129
def tooltip?
get_option_value(:tooltip, :content).present?
end
|
#with_confirmation ⇒ Object
89
90
91
|
# File 'app/components/coco/shared/button/button.rb', line 89
def with_confirmation(...)
with_dropdown_confirmation(...)
end
|
#with_dropdown ⇒ Object
85
86
87
|
# File 'app/components/coco/shared/button/button.rb', line 85
def with_dropdown(...)
with_dropdown_content(...)
end
|