Class: PhlexKit::SidebarWrapper
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::SidebarWrapper
- Defined in:
- app/components/phlex_kit/sidebar/sidebar_wrapper.rb
Overview
The page-level flex row that holds a PhlexKit::Sidebar + a PhlexKit::SidebarInset.
collapsible: (shadcn/ui's Sidebar collapsible prop, held here because the
wrapper is the Stimulus scope shared by rail, trigger and scrim):
:none — static rail (default).
:offcanvas — the rail hides/reveals via a PhlexKit::SidebarTrigger. On
desktop it slides out of the layout; below 768px it overlays
as a fixed drawer behind a click-to-close scrim, closed by
Escape and before Turbo caches the page. State is DOM-only:
`data-collapsed` (desktop) / `data-open` (mobile drawer).
See sidebar.rb.
Constant Summary collapse
- COLLAPSIBLE =
{ none: nil, offcanvas: "collapsible-offcanvas" }.freeze
Instance Method Summary collapse
-
#initialize(collapsible: :none, **attrs) ⇒ SidebarWrapper
constructor
A new instance of SidebarWrapper.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(collapsible: :none, **attrs) ⇒ SidebarWrapper
Returns a new instance of SidebarWrapper.
16 17 18 19 |
# File 'app/components/phlex_kit/sidebar/sidebar_wrapper.rb', line 16 def initialize(collapsible: :none, **attrs) @collapsible = collapsible.to_sym @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/components/phlex_kit/sidebar/sidebar_wrapper.rb', line 21 def view_template(&block) unless offcanvas? return div(**mix({ class: classes }, @attrs), &block) end div(**mix({ class: classes, data: { controller: "phlex-kit--sidebar", action: "keydown.esc@window->phlex-kit--sidebar#closeMobile " \ "turbo:before-cache@window->phlex-kit--sidebar#closeMobile" } }, @attrs)) do yield if block (type: :button, class: "pk-sidebar-scrim", aria_label: "Close sidebar", tabindex: "-1", data: { action: "click->phlex-kit--sidebar#closeMobile" }) end end |