Class: Shadcn::Sidebar::Provider::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/sidebar/provider/component.rb

Overview

SidebarProvider — the wrapper that holds the state for everything below it. In React that state is a context (vendor/shadcn/ui/sidebar.tsx:56); here it is the Stimulus controller, which is why this element and not the panel carries data-controller.

Upstream also wraps its children in a TooltipProvider with delayDuration={0}, so a collapsed sidebar's icons can explain themselves. This port has no provider component — each Tooltip carries its own delay — so there is nothing to reproduce here.

Constant Summary collapse

WIDTH =
"16rem"
WIDTH_ICON =
"3rem"
WIDTH_MOBILE =

Upstream's SIDEBAR_WIDTH_MOBILE (sidebar.tsx:31), which it applies by overriding --sidebar-width on the Sheet it renders instead of the panel. There is no second element here to override it on, so it is published as its own variable and the panel reaches for it directly.

"18rem"

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(open: true, **attributes) ⇒ Component

open: is what a Rails layout passes after reading the sidebar_state cookie, the way a Next.js layout passes defaultOpen. It defaults to open, as upstream's does.



35
36
37
38
# File 'app/components/shadcn/sidebar/provider/component.rb', line 35

def initialize(open: true, **attributes)
  @open = open
  super(**attributes)
end

Instance Attribute Details

#openObject (readonly)

Returns the value of attribute open.



30
31
32
# File 'app/components/shadcn/sidebar/provider/component.rb', line 30

def open
  @open
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'app/components/shadcn/sidebar/provider/component.rb', line 40

def element_attributes(**defaults)
  super(**{
    style: merged_style(
      "--sidebar-width: #{WIDTH}; --sidebar-width-icon: #{WIDTH_ICON}; " \
      "--sidebar-width-mobile: #{WIDTH_MOBILE};"
    ),
    "data-controller" => "shadcn--sidebar",
    "data-shadcn--sidebar-open-value" => open
  }.merge(defaults))
end