Class: UI::PopoverComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- UI::PopoverComponent
- Includes:
- PopoverBehavior
- Defined in:
- app/view_components/ui/popover_component.rb
Overview
PopoverComponent - ViewComponent implementation
Container for popover trigger and content. Uses PopoverBehavior concern for shared styling logic.
Supports asChild pattern for composition without wrapper elements.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(as_child: false, placement: "bottom", offset: 4, trigger: "click", hover_delay: 200, classes: "", align: nil, side_offset: nil, **attributes) ⇒ PopoverComponent
constructor
A new instance of PopoverComponent.
-
#popover_attrs ⇒ Object
Returns popover attributes for as_child mode.
Methods included from PopoverBehavior
#popover_classes, #popover_data_attributes, #popover_html_attributes
Constructor Details
#initialize(as_child: false, placement: "bottom", offset: 4, trigger: "click", hover_delay: 200, classes: "", align: nil, side_offset: nil, **attributes) ⇒ PopoverComponent
Returns a new instance of PopoverComponent.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/view_components/ui/popover_component.rb', line 39 def initialize( as_child: false, placement: "bottom", offset: 4, trigger: "click", hover_delay: 200, classes: "", align: nil, side_offset: nil, **attributes ) @as_child = as_child @placement = placement @offset = side_offset || offset @trigger = trigger @hover_delay = hover_delay @classes = classes @align = align @attributes = attributes end |
Instance Method Details
#call ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/view_components/ui/popover_component.rb', line 65 def call if @as_child # asChild mode: yield self to block, child accesses popover_attrs content else # Default: render wrapper div with controller content_tag :div, **popover_html_attributes do content end end end |
#popover_attrs ⇒ Object
Returns popover attributes for as_child mode
61 62 63 |
# File 'app/view_components/ui/popover_component.rb', line 61 def popover_attrs popover_html_attributes.deep_merge(@attributes) end |