Class: UI::HoverCardTrigger
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UI::HoverCardTrigger
- Includes:
- HoverCardTriggerBehavior
- Defined in:
- app/components/ui/hover_card_trigger.rb
Overview
Trigger - Phlex implementation
Element that triggers the hover card on hover. Uses HoverCardTriggerBehavior for shared styling logic. Supports asChild pattern for composition.
Instance Method Summary collapse
-
#initialize(as_child: false, tag: :span, classes: "", **attributes) ⇒ HoverCardTrigger
constructor
A new instance of HoverCardTrigger.
- #view_template(&block) ⇒ Object
Methods included from HoverCardTriggerBehavior
#trigger_classes, #trigger_data_attributes, #trigger_html_attributes
Constructor Details
#initialize(as_child: false, tag: :span, classes: "", **attributes) ⇒ HoverCardTrigger
Returns a new instance of HoverCardTrigger.
26 27 28 29 30 31 |
# File 'app/components/ui/hover_card_trigger.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
#view_template(&block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/ui/hover_card_trigger.rb', line 33 def view_template(&block) trigger_attrs = trigger_html_attributes if @as_child # Yield attributes to block - child must accept and apply them yield(trigger_attrs) if block_given? else # Add tabindex for keyboard focus on non-focusable elements trigger_attrs[:tabindex] ||= "0" if [:span, :div].include?(@tag) # Default: render as specified tag (span by default) public_send(@tag, **trigger_attrs, &block) end end |