Class: Shadcn::DropdownMenu::Sub::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/dropdown_menu/sub/component.rb

Overview

DropdownMenuSub — a nested menu.

It is another shadcn--dropdown-menu controller, anchored to the right of its trigger. Stimulus scopes targets to the nearest controller of the same identifier, so the parent menu's items and the submenu's stay apart.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

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

Constructor Details

#initialize(open: false, side: :right, align: :start, side_offset: 0, **attributes) ⇒ Component

Returns a new instance of Component.



19
20
21
22
23
24
25
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 19

def initialize(open: false, side: :right, align: :start, side_offset: 0, **attributes)
  @open = open
  @side = side&.to_sym || :right
  @align = align&.to_sym || :start
  @side_offset = side_offset
  super(**attributes)
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



17
18
19
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 17

def align
  @align
end

#openObject (readonly)

Returns the value of attribute open.



17
18
19
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 17

def open
  @open
end

#sideObject (readonly)

Returns the value of attribute side.



17
18
19
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 17

def side
  @side
end

#side_offsetObject (readonly)

Returns the value of attribute side_offset.



17
18
19
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 17

def side_offset
  @side_offset
end

Instance Method Details

#callObject



38
39
40
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 38

def call
  render_element(body: safe_join([ trigger, menu_content, content ].compact))
end

#element_attributes(**defaults) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/components/shadcn/dropdown_menu/sub/component.rb', line 27

def element_attributes(**defaults)
  super(**{
    style: merged_style(CONTENTS_STYLE),
    "data-controller" => "shadcn--dropdown-menu",
    "data-shadcn--dropdown-menu-open-value" => open,
    "data-shadcn--dropdown-menu-side-value" => side,
    "data-shadcn--dropdown-menu-align-value" => align,
    "data-shadcn--dropdown-menu-side-offset-value" => side_offset
  }.merge(defaults))
end