Class: UI::SidebarGroup

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

Overview

Group - Phlex implementation

Container for grouping related sidebar items. Can be made collapsible using UI::Collapsible.

Examples:

Basic usage (non-collapsible)

render UI::Group.new do
  render UI::GroupLabel.new { "Section" }
  render UI::GroupContent.new do
    render UI::Menu.new { ... }
  end
end

Collapsible group (using UI::Collapsible)

render UI::Collapsible.new(open: true, as_child: true) do |collapsible_attrs|
  render UI::Group.new(**collapsible_attrs) do
    render UI::CollapsibleTrigger.new(as_child: true) do |trigger_attrs|
      render UI::GroupLabel.new(**trigger_attrs) { "Section" }
    end
    render UI::CollapsibleContent.new do
      render UI::GroupContent.new do
        render UI::Menu.new { ... }
      end
    end
  end
end

Instance Method Summary collapse

Methods included from SidebarGroupBehavior

#sidebar_group_classes, #sidebar_group_data_attributes, #sidebar_group_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ SidebarGroup

Returns a new instance of SidebarGroup.



32
33
34
35
# File 'app/components/ui/sidebar_group.rb', line 32

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

Instance Method Details

#view_template(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/components/ui/sidebar_group.rb', line 37

def view_template(&block)
  all_attributes = sidebar_group_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