Class: Shadcn::SidebarComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/sidebar_component.rb

Overview

Sidebar component for application layouts Matches shadcn/ui Sidebar component A composable, themeable sidebar with collapsible state

Examples:

Basic sidebar

<%= render Shadcn::SidebarComponent.new do |sidebar| %>
  <% sidebar.with_header do %>
    
App Name
<% end %> <% sidebar.with_sidebar_content do |sc| %> <% sc.with_group do |group| %> <% group.with_label { "Platform" } %> <% group.with_group_content do |gc| %> <% gc.with_menu do |menu| %> <% menu.with_item do |item| %> <% item.with_button(href: "/dashboard") do %> Dashboard <% end %> <% end %> <% end %> <% end %> <% end %> <% end %> <% sidebar.with_footer do %> User info here <% end %> <% end %>

Constant Summary collapse

"16rem"
"18rem"
"3rem"
SIDES =
{
  left: "left",
  right: "right"
}.freeze
VARIANTS =
{
  sidebar: "sidebar",
  floating: "floating",
  inset: "inset"
}.freeze
COLLAPSIBLE_MODES =
{
  offcanvas: "offcanvas",
  icon: "icon",
  none: "none"
}.freeze

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(side: :left, variant: :sidebar, collapsible: :offcanvas, default_open: true, **options) ⇒ SidebarComponent

Returns a new instance of SidebarComponent.

Parameters:

  • side (Symbol) (defaults to: :left)

    Side to show sidebar (:left, :right)

  • variant (Symbol) (defaults to: :sidebar)

    Visual style (:sidebar, :floating, :inset)

  • collapsible (Symbol) (defaults to: :offcanvas)

    Collapse mode (:offcanvas, :icon, :none)

  • default_open (Boolean) (defaults to: true)

    Whether sidebar starts open



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/components/shadcn/sidebar_component.rb', line 74

def initialize(
  side: :left,
  variant: :sidebar,
  collapsible: :offcanvas,
  default_open: true,
  **options
)
  super(**options)
  @side = side.to_sym
  @variant = variant.to_sym
  @collapsible = collapsible.to_sym
  @default_open = default_open
end

Instance Method Details

#callObject



88
89
90
# File 'app/components/shadcn/sidebar_component.rb', line 88

def call
  (:aside, sidebar_wrapper, sidebar_attributes)
end