Class: Shadcn::NavigationMenu::Trigger::Component

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

Overview

The button that opens a panel. Its classes are exported upstream as navigationMenuTriggerStyle so a plain link can borrow them; the same is available here as Component.new.css_classes, which is how the sidebar preview borrows the menu button's.

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

#css_classes, 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 chevron is upstream's, and so is the space before it: shadcn writes {children}{" "} rather than a gap utility (navigation-menu.tsx:76).



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/shadcn/navigation_menu/trigger/component.rb', line 42

def call
  render_element(
    body: safe_join([
      content,
      " ",
      render(Shadcn::Icon::Component.new(
        "chevron-down",
        class: "relative top-[1px] ml-1 size-3 transition duration-300 " \
               "group-data-[state=open]:rotate-180",
        "aria-hidden": true
      ))
    ])
  )
end

#element_attributes(**defaults) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/components/shadcn/navigation_menu/trigger/component.rb', line 27

def element_attributes(**defaults)
  super(**{
    type: "button",
    "data-state" => "closed",
    "aria-expanded" => "false",
    "data-shadcn--navigation-menu-target" => "trigger",
    "data-action" => "pointerenter->shadcn--navigation-menu#pointerEnter " \
                     "pointerleave->shadcn--navigation-menu#pointerLeave " \
                     "click->shadcn--navigation-menu#toggle " \
                     "keydown->shadcn--navigation-menu#keydown"
  }.merge(defaults))
end