Class: UI::SidebarInset

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

Overview

SidebarInset - Phlex implementation

Main content area that sits alongside the sidebar. Should be used as a sibling to Sidebar within SidebarProvider.

Examples:

Basic usage

render UI::SidebarProvider.new do
  render UI::Sidebar.new { "Sidebar" }
  render UI::SidebarInset.new do
    # Main content here
  end
end

Instance Method Summary collapse

Methods included from SidebarInsetBehavior

#sidebar_inset_classes, #sidebar_inset_data_attributes, #sidebar_inset_html_attributes

Constructor Details

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

Returns a new instance of SidebarInset.

Parameters:

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

    Additional CSS classes

  • attributes (Hash)

    Additional HTML attributes



20
21
22
23
# File 'app/components/ui/sidebar_inset.rb', line 20

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

Instance Method Details

#view_template(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/ui/sidebar_inset.rb', line 25

def view_template(&block)
  all_attributes = sidebar_inset_html_attributes

  # Merge classes with TailwindMerge
  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

  # Deep merge other attributes (excluding class)
  all_attributes = all_attributes.deep_merge(@attributes.except(:class))

  main(**all_attributes, &block)
end