Class: UI::InputGroupButton

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ButtonBehavior, InputGroupButtonBehavior
Defined in:
app/components/ui/input_group_button.rb

Overview

Button - Phlex implementation

A button component specifically styled for use within input groups. Uses both ButtonBehavior and InputGroupButtonBehavior for styling.

Examples:

Basic button

render UI::Button.new { "Search" }

Icon button

render UI::Button.new(size: "icon-xs") { unsafe_raw "<svg>...</svg>" }

Instance Method Summary collapse

Methods included from InputGroupButtonBehavior

#input_group_button_attributes, #input_group_button_classes, #input_group_button_html_attributes

Methods included from ButtonBehavior

#button_classes, #button_html_attributes, #render_button

Constructor Details

#initialize(size: "xs", variant: "ghost", type: "button", classes: "", **attributes) ⇒ InputGroupButton

Returns a new instance of InputGroupButton.

Parameters:

  • size (String) (defaults to: "xs")

    Size variant: “xs”, “sm”, “icon-xs”, “icon-sm”

  • variant (String) (defaults to: "ghost")

    Button variant (default: “ghost”)

  • type (String) (defaults to: "button")

    Button type attribute (default: “button”)

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



22
23
24
25
26
27
28
# File 'app/components/ui/input_group_button.rb', line 22

def initialize(size: "xs", variant: "ghost", type: "button", classes: "", **attributes)
  @size = size
  @variant = variant
  @type = type
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/ui/input_group_button.rb', line 30

def view_template(&block)
  # Merge classes from @attributes[:class] with input_group_button_classes
  # This is needed when as_child patterns pass classes through attributes
  merged_classes = TailwindMerge::Merger.new.merge([
    input_group_button_classes,
    @attributes[:class]
  ].compact.join(" "))

  # Use input_group_button_classes which includes button behavior + input group styling
  button(
    type: @type,
    class: merged_classes,
    **@attributes.except(:type, :variant, :size, :class)
  ) do
    yield if block_given?
  end
end