Class: UI::SidebarGroupLabel

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

Overview

GroupLabel - Phlex implementation

Label/header for a sidebar group. Can be used with UI::CollapsibleTrigger for collapsible groups.

Examples:

Basic usage

render UI::GroupLabel.new { "Section" }

With asChild for collapsible trigger

render UI::CollapsibleTrigger.new(as_child: true) do |trigger_attrs|
  render UI::GroupLabel.new(**trigger_attrs) do
    "Section"
    render UI::Icon.new(name: "chevron-right", class: "ml-auto transition-transform group-data-[state=open]:rotate-90")
  end
end

Instance Method Summary collapse

Methods included from SidebarGroupLabelBehavior

#sidebar_group_label_classes, #sidebar_group_label_data_attributes, #sidebar_group_label_html_attributes

Constructor Details

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

Returns a new instance of SidebarGroupLabel.



21
22
23
24
25
# File 'app/components/ui/sidebar_group_label.rb', line 21

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

Instance Method Details

#view_template(&block) ⇒ Object



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

def view_template(&block)
  if @as_child
    yield sidebar_group_label_html_attributes.deep_merge(@attributes)
  else
    all_attributes = sidebar_group_label_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))

    div(**all_attributes, &block)
  end
end