Class: Trek::ButtonComponent
- Defined in:
- app/components/trek/button_component.rb
Instance Method Summary collapse
- #call ⇒ Object
- #classes ⇒ Object
- #data_attributes ⇒ Object
- #render? ⇒ Boolean
- #rendered_content ⇒ Object
Methods included from StimulusHelpers
#stimulus_action, #stimulus_class, #stimulus_class_hash, #stimulus_class_key, #stimulus_target, #stimulus_target_hash, #stimulus_target_key, #stimulus_value, #stimulus_value_hash, #stimulus_value_key
Methods included from CssClassesHelpers
#class_for, #class_names_for, #root_class
Methods included from IdentifierHelper
Instance Method Details
#call ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/components/trek/button_component.rb', line 52 def call if link? link_to rendered_content, href, class: classes, data: data_attributes, rel: rel, target: target, title: title elsif to? # TODO: find how to replace with `button_to` (and use `data-turbo-confirm`) link_to rendered_content, to, class: classes, data: data_attributes.merge(turbo_method: method), form: form, form_class: form_class, params: params else content_tag tag, rendered_content, class: classes, data: data_attributes, form:, type:, value: end end |
#classes ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/trek/button_component.rb', line 27 def classes class_names_for( root_class, classnames, "has-icon": icon.present?, "color-#{color}": color, "position-#{position}": position, "size-#{size}": size ) end |
#data_attributes ⇒ Object
38 39 40 41 42 |
# File 'app/components/trek/button_component.rb', line 38 def data_attributes attributes = {} attributes["accent-color"] = color if color attributes.merge(data) end |
#render? ⇒ Boolean
81 82 83 |
# File 'app/components/trek/button_component.rb', line 81 def render? text? end |
#rendered_content ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/components/trek/button_component.rb', line 44 def rendered_content safe_join([ icon, content_tag(:span, text, class: class_for("text")), content ]) end |