Class: Shadcn::NavigationMenu::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::NavigationMenu::Component
- Defined in:
- app/components/shadcn/navigation_menu/component.rb
Overview
Port of registry/new-york-v4/ui/navigation-menu.tsx, whose behaviour is
Radix's NavigationMenu — 1,403 lines against shadcn's 168, vendored at
vendor/radix/ui/navigation-menu.tsx.
data-viewport is always false here, and that is the decision this
port turns on. Upstream's default renders every panel into one shared
box that animates between their sizes — measured on the live demo, the
content's parent is navigation-menu-viewport, which means React has
moved it there through a portal. Nothing is portalled in this gem, for the
reason in decisions/02-javascript.md, so that mode cannot be reproduced
without giving up the rule every other component here was built on.
viewport={false} is not a workaround: it is a configuration shadcn
supports and ships classes for, and in it each panel stays inside its own
item with its own border, background and shadow. See
features/navigation-menu.md.
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#delay_duration ⇒ Object
readonly
Returns the value of attribute delay_duration.
-
#skip_delay_duration ⇒ Object
readonly
Returns the value of attribute skip_delay_duration.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #element_attributes(**defaults) ⇒ Object
-
#initialize(delay_duration: 200, skip_delay_duration: 300, **attributes) ⇒ Component
constructor
Radix's own defaults (navigation-menu.tsx:136-137).
Methods inherited from ApplicationViewComponent
#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(delay_duration: 200, skip_delay_duration: 300, **attributes) ⇒ Component
Radix's own defaults (navigation-menu.tsx:136-137). skip_delay_duration
is the grace period after a panel closes in which the next one opens at
once — it is what stops a menu feeling sticky when you sweep across it.
35 36 37 38 39 |
# File 'app/components/shadcn/navigation_menu/component.rb', line 35 def initialize(delay_duration: 200, skip_delay_duration: 300, **attributes) @delay_duration = delay_duration @skip_delay_duration = skip_delay_duration super(**attributes) end |
Instance Attribute Details
#delay_duration ⇒ Object (readonly)
Returns the value of attribute delay_duration.
30 31 32 |
# File 'app/components/shadcn/navigation_menu/component.rb', line 30 def delay_duration @delay_duration end |
#skip_delay_duration ⇒ Object (readonly)
Returns the value of attribute skip_delay_duration.
30 31 32 |
# File 'app/components/shadcn/navigation_menu/component.rb', line 30 def skip_delay_duration @skip_delay_duration end |
Instance Method Details
#element_attributes(**defaults) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'app/components/shadcn/navigation_menu/component.rb', line 41 def element_attributes(**defaults) super(**{ "data-viewport" => "false", "data-controller" => "shadcn--navigation-menu", "data-shadcn--navigation-menu-delay-value" => delay_duration, "data-shadcn--navigation-menu-skip-delay-value" => skip_delay_duration }.merge(defaults)) end |