Class: Shadcn::Sidebar::Trigger::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/sidebar/trigger/component.rb

Overview

SidebarTrigger — upstream renders a ghost icon Button (vendor/shadcn/ui/sidebar.tsx:256-280), so this borrows the button's own compiled variants rather than restating them, as PaginationLink does.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

default_tag, #initialize, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

This class inherits a constructor from Shadcn::ApplicationViewComponent

Instance Method Details

#callObject

The label is sr-only rather than an aria-label: upstream puts it in the button's content, and a visible-to-screen-readers span survives translation tooling that an attribute does not.



29
30
31
32
33
34
35
# File 'app/components/shadcn/sidebar/trigger/component.rb', line 29

def call
  render_element(body: safe_join([
    render(Icon::Component.new("panel-left")),
    tag.span(shadcn_t("sidebar.toggle"), class: "sr-only"),
    content
  ].compact))
end

#css_classes(extra = nil) ⇒ Object



22
23
24
# File 'app/components/shadcn/sidebar/trigger/component.rb', line 22

def css_classes(extra = nil)
  Button::Component.variant_classes(variant: :ghost, size: :icon, class: [ "size-7", extra ].compact.join(" "))
end

#element_attributes(**defaults) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/components/shadcn/sidebar/trigger/component.rb', line 13

def element_attributes(**defaults)
  super(**{
    type: "button",
    "data-sidebar" => "trigger",
    "data-shadcn--sidebar-target" => "trigger",
    "data-action" => "click->shadcn--sidebar#toggle"
  }.merge(defaults))
end