Class: PhlexKit::SidebarRail
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::SidebarRail
- Defined in:
- app/components/phlex_kit/sidebar/sidebar_rail.rb
Overview
Invisible grab strip along the sidebar's trailing edge — clicking it
toggles the collapse, like shadcn/ui's SidebarRail. Place it as the last
child of a Sidebar inside a collapsible wrapper. expanded: renders the
initial aria-expanded (pass false when the wrapper starts
default_collapsed); the phlex-kit--sidebar controller keeps it in sync on
toggle. controls: renders aria-controls pointing at the Sidebar's id —
when omitted, the controller wires it on connect. See sidebar.rb.
Instance Method Summary collapse
-
#initialize(expanded: true, controls: nil, **attrs) ⇒ SidebarRail
constructor
A new instance of SidebarRail.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(expanded: true, controls: nil, **attrs) ⇒ SidebarRail
Returns a new instance of SidebarRail.
10 11 12 13 14 |
# File 'app/components/phlex_kit/sidebar/sidebar_rail.rb', line 10 def initialize(expanded: true, controls: nil, **attrs) @expanded = @controls = controls @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/phlex_kit/sidebar/sidebar_rail.rb', line 16 def view_template base = { type: :button, class: "pk-sidebar-rail", aria_label: "Toggle sidebar", "aria-expanded": @expanded ? "true" : "false", tabindex: "-1", title: "Toggle sidebar", data: { action: "click->phlex-kit--sidebar#toggle" } } base["aria-controls"] = @controls if @controls (**mix(base, @attrs)) end |