Class: UI::TooltipComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- UI::TooltipComponent
- Includes:
- TooltipBehavior
- Defined in:
- app/view_components/ui/tooltip_component.rb
Overview
TooltipComponent - ViewComponent implementation
Root container for tooltip. Manages tooltip state via Stimulus controller.
Supports asChild pattern for composition without wrapper elements.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(as_child: false, **attributes) ⇒ TooltipComponent
constructor
A new instance of TooltipComponent.
-
#tooltip_attrs ⇒ Object
Returns tooltip attributes for as_child mode.
Methods included from TooltipBehavior
#tooltip_data_attributes, #tooltip_html_attributes
Constructor Details
#initialize(as_child: false, **attributes) ⇒ TooltipComponent
Returns a new instance of TooltipComponent.
29 30 31 32 |
# File 'app/view_components/ui/tooltip_component.rb', line 29 def initialize(as_child: false, **attributes) @as_child = as_child @attributes = attributes end |
Instance Method Details
#call ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/view_components/ui/tooltip_component.rb', line 39 def call if @as_child # asChild mode: yield self to block, child accesses tooltip_attrs content else # Default: render wrapper div with controller content_tag :div, **tooltip_html_attributes.merge(@attributes.except(:data)) do content end end end |
#tooltip_attrs ⇒ Object
Returns tooltip attributes for as_child mode
35 36 37 |
# File 'app/view_components/ui/tooltip_component.rb', line 35 def tooltip_attrs tooltip_html_attributes.deep_merge(@attributes) end |