Class: UI::SidebarGroupAction

Inherits:
Phlex::HTML
  • Object
show all
Includes:
SidebarGroupActionBehavior
Defined in:
app/components/ui/sidebar_group_action.rb

Overview

GroupAction - Phlex implementation

Action button within a sidebar group header. Typically used for actions like “Add” or contextual menus.

Examples:

Basic usage

render UI::GroupAction.new do
  render UI::Icon.new(name: "plus")
end

With asChild for custom trigger

render UI::GroupAction.new(as_child: true) do |action_attrs|
  render UI::DropdownMenuTrigger.new(**action_attrs) do
    render UI::Icon.new(name: "ellipsis")
  end
end

Instance Method Summary collapse

Methods included from SidebarGroupActionBehavior

#sidebar_group_action_classes, #sidebar_group_action_data_attributes, #sidebar_group_action_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ SidebarGroupAction

Returns a new instance of SidebarGroupAction.



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

def initialize(as_child: false, classes: "", **attributes)
  @as_child = as_child
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



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

def view_template(&block)
  if @as_child
    yield sidebar_group_action_html_attributes.deep_merge(@attributes)
  else
    all_attributes = sidebar_group_action_html_attributes

    if @attributes.key?(:class)
      merged_class = TailwindMerge::Merger.new.merge([
        all_attributes[:class],
        @attributes[:class]
      ].compact.join(" "))
      all_attributes = all_attributes.merge(class: merged_class)
    end

    all_attributes = all_attributes.deep_merge(@attributes.except(:class))

    button(**all_attributes, &block)
  end
end