Class: PhlexKit::SidebarTrigger

Inherits:
BaseComponent show all
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. See sidebar.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(**attrs) ⇒ SidebarTrigger

Returns a new instance of SidebarTrigger.



8
9
10
# File 'app/components/phlex_kit/sidebar/sidebar_trigger.rb', line 8

def initialize(**attrs)
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'app/components/phlex_kit/sidebar/sidebar_trigger.rb', line 12

def view_template(&block)
  button(**mix({
    type: :button,
    class: "pk-sidebar-trigger",
    aria_label: "Toggle sidebar",
    data: { action: "click->phlex-kit--sidebar#toggle" }
  }, @attrs)) do
    block ? yield : render(Icon.new(:menu, size: nil))
  end
end