Class: UI::DropdownMenuComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- UI::DropdownMenuComponent
- Includes:
- DropdownMenuBehavior, SharedAsChildBehavior
- Defined in:
- app/view_components/ui/dropdown_menu_component.rb
Overview
DropdownMenuComponent - ViewComponent implementation
Container for dropdown menus with Stimulus controller for interactivity. Uses DropdownMenuBehavior concern for shared styling logic.
Supports asChild pattern for composition without wrapper elements.
Instance Method Summary collapse
- #call ⇒ Object
-
#dropdown_attrs ⇒ Object
Provide dropdown attributes to the block.
-
#initialize(as_child: false, placement: "bottom-start", offset: 4, flip: true, classes: "", **attributes) ⇒ DropdownMenuComponent
constructor
A new instance of DropdownMenuComponent.
Methods included from SharedAsChildBehavior
Methods included from DropdownMenuBehavior
#dropdown_menu_classes, #dropdown_menu_data_attributes, #dropdown_menu_html_attributes
Constructor Details
#initialize(as_child: false, placement: "bottom-start", offset: 4, flip: true, classes: "", **attributes) ⇒ DropdownMenuComponent
Returns a new instance of DropdownMenuComponent.
24 25 26 27 28 29 30 31 |
# File 'app/view_components/ui/dropdown_menu_component.rb', line 24 def initialize(as_child: false, placement: "bottom-start", offset: 4, flip: true, classes: "", **attributes) @as_child = as_child @placement = placement @offset = offset @flip = flip @classes = classes @attributes = attributes end |
Instance Method Details
#call ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/view_components/ui/dropdown_menu_component.rb', line 33 def call dropdown_attrs = .deep_merge(@attributes) if @as_child # Yield attributes to block - child receives controller setup content_for(:dropdown_attrs, dropdown_attrs) content else # Default: render wrapper div with controller content_tag :div, **dropdown_attrs do content end end end |
#dropdown_attrs ⇒ Object
Provide dropdown attributes to the block
49 50 51 |
# File 'app/view_components/ui/dropdown_menu_component.rb', line 49 def dropdown_attrs .deep_merge(@attributes) end |