Class: PhlexKit::SidebarTrigger
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::SidebarTrigger
- Defined in:
- app/components/phlex_kit/sidebar/sidebar_trigger.rb
Overview
The hamburger that toggles an offcanvas sidebar, ported from shadcn/ui's
SidebarTrigger. Place it anywhere inside a
SidebarWrapper(collapsible: :offcanvas) — typically at the top of the
SidebarInset. Renders the :menu icon unless a block supplies its own
content. Hidden by CSS unless the wrapper is offcanvas. 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 (generating an id on the
sidebar if needed). See sidebar.rb.
Instance Method Summary collapse
-
#initialize(expanded: true, controls: nil, **attrs) ⇒ SidebarTrigger
constructor
A new instance of SidebarTrigger.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(expanded: true, controls: nil, **attrs) ⇒ SidebarTrigger
Returns a new instance of SidebarTrigger.
13 14 15 16 17 |
# File 'app/components/phlex_kit/sidebar/sidebar_trigger.rb', line 13 def initialize(expanded: true, controls: nil, **attrs) @expanded = @controls = controls @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/phlex_kit/sidebar/sidebar_trigger.rb', line 19 def view_template(&block) base = { type: :button, class: "pk-sidebar-trigger", aria_label: "Toggle sidebar", "aria-expanded": @expanded ? "true" : "false", data: { action: "click->phlex-kit--sidebar#toggle" } } base["aria-controls"] = @controls if @controls (**mix(base, @attrs)) do block ? yield : render(Icon.new(:menu, size: nil)) end end |