Class: UI::SidebarProvider

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

Overview

SidebarProvider - Phlex implementation

Root container for sidebar that manages state via Stimulus controller. Wraps the entire layout (sidebar + main content).

Examples:

Basic usage

render UI::SidebarProvider.new do
  render UI::Sidebar.new do
    # Sidebar content
  end
  render UI::SidebarInset.new do
    # Main content
  end
end

With custom width

render UI::SidebarProvider.new(sidebar_width: "18rem") do
  # ...
end

Instance Method Summary collapse

Methods included from SidebarProviderBehavior

#sidebar_provider_classes, #sidebar_provider_data_attributes, #sidebar_provider_html_attributes, #sidebar_provider_style

Constructor Details

#initialize(open: true, collapsible: "icon", side: "left", cookie_name: "sidebar_state", sidebar_width: "16rem", sidebar_width_mobile: "18rem", sidebar_width_icon: "3rem", classes: "", **attributes) ⇒ SidebarProvider

Returns a new instance of SidebarProvider.

Parameters:

  • open (Boolean) (defaults to: true)

    Initial open state (default: true)

  • collapsible (String) (defaults to: "icon")

    Collapsible mode: “offcanvas”, “icon”, or “none” (default: “icon”)

  • side (String) (defaults to: "left")

    Side position: “left” or “right” (default: “left”)

  • cookie_name (String) (defaults to: "sidebar_state")

    Cookie name for persisting state (default: “sidebar_state”)

  • sidebar_width (String) (defaults to: "16rem")

    Custom sidebar width (default: “16rem”)

  • sidebar_width_mobile (String) (defaults to: "18rem")

    Custom mobile sidebar width (default: “18rem”)

  • sidebar_width_icon (String) (defaults to: "3rem")

    Custom icon-mode width (default: “3rem”)

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

    Additional CSS classes

  • attributes (Hash)

    Additional HTML attributes



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/ui/sidebar_provider.rb', line 34

def initialize(
  open: true,
  collapsible: "icon",
  side: "left",
  cookie_name: "sidebar_state",
  sidebar_width: "16rem",
  sidebar_width_mobile: "18rem",
  sidebar_width_icon: "3rem",
  classes: "",
  **attributes
)
  @open = open
  @collapsible = collapsible
  @side = side
  @cookie_name = cookie_name
  @sidebar_width = sidebar_width
  @sidebar_width_mobile = sidebar_width_mobile
  @sidebar_width_icon = sidebar_width_icon
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/components/ui/sidebar_provider.rb', line 56

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

  div(**all_attributes, &block)
end