Class: UI::InputGroupButtonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
InputGroupButtonBehavior
Defined in:
app/view_components/ui/input_group_button_component.rb

Overview

InputGroupButtonComponent - ViewComponent implementation

A button component specifically styled for use within input groups. Uses InputGroupButtonBehavior concern for shared styling logic.

Examples:

Basic button

<%= render UI::InputGroupButtonComponent.new do %>
  Search
<% end %>

Icon button

<%= render UI::InputGroupButtonComponent.new(size: "icon-xs") do %>
  <svg>...</svg>
<% end %>

Instance Method Summary collapse

Methods included from InputGroupButtonBehavior

#input_group_button_attributes, #input_group_button_classes, #input_group_button_html_attributes

Constructor Details

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

Returns a new instance of InputGroupButtonComponent.

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



25
26
27
28
29
30
31
# File 'app/view_components/ui/input_group_button_component.rb', line 25

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

Instance Method Details

#callObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/view_components/ui/input_group_button_component.rb', line 33

def call
  # Get base attributes from behavior (type, variant, classes)
  base_attrs = input_group_button_attributes

  # Extract button-specific params that ui/button accepts as direct arguments
  button_params = {
    type: base_attrs[:type],
    variant: base_attrs[:variant],
    classes: base_attrs[:classes],
    content: content
  }

  # Merge additional HTML attributes (data, role, aria, tabindex, etc.) into attributes hash
  html_attrs = base_attrs.except(:type, :variant, :classes, :"data-size")
  button_params[:attributes] = html_attrs unless html_attrs.empty?

  render partial: "ui/button", locals: button_params
end