Module: UI::ButtonBehavior
- Included in:
- Button, ButtonComponent, InputGroupButton
- Defined in:
- app/behaviors/ui/button_behavior.rb
Overview
UI::ButtonBehavior
Instance Method Summary collapse
-
#button_classes ⇒ Object
Returns combined CSS classes for the button.
-
#button_html_attributes ⇒ Object
Returns HTML attributes for the button element.
-
#render_button(&content_block) ⇒ String
Renders the button HTML This method can be used by both ERB partials and ViewComponents.
Instance Method Details
#button_classes ⇒ Object
Returns combined CSS classes for the button
55 56 57 58 59 60 61 62 63 |
# File 'app/behaviors/ui/button_behavior.rb', line 55 def classes_value = respond_to?(:classes, true) ? classes : @classes TailwindMerge::Merger.new.merge([ , , , classes_value ].compact.join(" ")) end |
#button_html_attributes ⇒ Object
Returns HTML attributes for the button element
46 47 48 49 50 51 52 |
# File 'app/behaviors/ui/button_behavior.rb', line 46 def { class: , type: @type || "button", disabled: @disabled ? true : nil }.compact end |
#render_button(&content_block) ⇒ String
Renders the button HTML This method can be used by both ERB partials and ViewComponents
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/behaviors/ui/button_behavior.rb', line 28 def (&content_block) all_attributes = # Merge classes with TailwindMerge before deep_merge if @attributes&.key?(:class) = all_attributes[:class] || "" attr_class = @attributes[:class] || "" merged_class = TailwindMerge::Merger.new.merge([, attr_class].join(" ")) all_attributes = all_attributes.merge(class: merged_class) end # Deep merge other attributes (excluding class which we already handled) all_attributes = all_attributes.deep_merge(@attributes&.except(:class) || {}) content_tag(:button, **all_attributes, &content_block) end |