Class: PhlexKit::SidebarMenuSubButton

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/phlex_kit/sidebar/sidebar_menu_sub_button.rb

Overview

The interactive element of a SidebarMenuSubItem, ported from shadcn/ui's SidebarMenuSubButton. as: is :a (their default — pass href:) or :button; active: true highlights with the accent role (shadcn subs use accent, not primary). Kwarg rather than attr for the same mix-merge reason as SidebarMenuButton. See sidebar.rb.

Constant Summary collapse

AS_TAGS =

as: is dispatched dynamically (send) — whitelist, matching SidebarMenuButton.

%i[a button].freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(as: :a, active: false, **attrs) ⇒ SidebarMenuSubButton

Returns a new instance of SidebarMenuSubButton.



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

def initialize(as: :a, active: false, **attrs)
  @as = as.to_sym
  unless AS_TAGS.include?(@as)
    raise ArgumentError, "unknown SidebarMenuSubButton as: #{@as.inspect} (use one of #{AS_TAGS.join(", ")})"
  end
  @active = active
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



21
22
23
# File 'app/components/phlex_kit/sidebar/sidebar_menu_sub_button.rb', line 21

def view_template(&block)
  send(@as, **mix({ class: "pk-sidebar-menu-sub-button", "data-active": (@active ? "true" : "false") }, @attrs), &block)
end