Class: UI::HoverCardTriggerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- UI::HoverCardTriggerComponent
- Includes:
- HoverCardTriggerBehavior
- Defined in:
- app/view_components/ui/hover_card_trigger_component.rb
Overview
TriggerComponent - ViewComponent implementation
Element that triggers the hover card on hover. Uses HoverCardTriggerBehavior for shared styling logic. Supports asChild pattern for composition.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(as_child: false, tag: :span, classes: "", **attributes) ⇒ HoverCardTriggerComponent
constructor
A new instance of HoverCardTriggerComponent.
-
#render_in(view_context, &block) ⇒ Object
Override render_in to pass trigger_attrs to block when as_child is true.
Methods included from HoverCardTriggerBehavior
#trigger_classes, #trigger_data_attributes, #trigger_html_attributes
Constructor Details
#initialize(as_child: false, tag: :span, classes: "", **attributes) ⇒ HoverCardTriggerComponent
Returns a new instance of HoverCardTriggerComponent.
26 27 28 29 30 31 |
# File 'app/view_components/ui/hover_card_trigger_component.rb', line 26 def initialize(as_child: false, tag: :span, classes: "", **attributes) @as_child = as_child @tag = tag @classes = classes @attributes = attributes end |
Instance Method Details
#call ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/view_components/ui/hover_card_trigger_component.rb', line 46 def call # Default: render with full styling and tabindex for keyboard focus attrs = trigger_html_attributes.merge(@attributes) attrs[:tabindex] ||= "0" if @tag == :span || @tag == :div content_tag @tag, **attrs do content end end |
#render_in(view_context, &block) ⇒ Object
Override render_in to pass trigger_attrs to block when as_child is true
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/view_components/ui/hover_card_trigger_component.rb', line 34 def render_in(view_context, &block) @view_context = view_context if @as_child && block # asChild pattern: call the block with trigger attributes # Block should use these attrs on the actual trigger element view_context.capture(trigger_html_attributes, &block) else super end end |