Class: UI::TooltipTriggerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
TooltipTriggerBehavior
Defined in:
app/view_components/ui/tooltip_trigger_component.rb

Overview

TriggerComponent - ViewComponent implementation

The interactive element that shows/hides the tooltip on hover/focus. Supports asChild pattern for composition with other components.

Examples:

Basic usage

<%= render UI::TooltipTriggerComponent.new do %>
  Hover me
<% end %>

As child (yields attributes to block)

<%= render UI::TooltipTriggerComponent.new(as_child: true) do |trigger| %>
  <%= render UI::InputGroupButtonComponent.new(**trigger.trigger_attrs) do %>
    Info
  <% end %>
<% end %>

Instance Method Summary collapse

Methods included from TooltipTriggerBehavior

#tooltip_trigger_classes, #tooltip_trigger_data_attributes, #tooltip_trigger_html_attributes

Constructor Details

#initialize(as_child: false, **attributes) ⇒ TooltipTriggerComponent

Returns a new instance of TooltipTriggerComponent.

Parameters:

  • as_child (Boolean) (defaults to: false)

    If true, yields attributes to block instead of rendering button

  • attributes (Hash)

    Additional HTML attributes



24
25
26
27
# File 'app/view_components/ui/tooltip_trigger_component.rb', line 24

def initialize(as_child: false, **attributes)
  @as_child = as_child
  @attributes = attributes
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/view_components/ui/tooltip_trigger_component.rb', line 34

def call
  if @as_child
    # asChild mode: yield self so caller can access trigger_attrs
    content
  else
    # Default mode: render as button with proper styling
     :button, **trigger_attrs do
      content
    end
  end
end

#trigger_attrsObject

Returns trigger attributes for as_child mode



30
31
32
# File 'app/view_components/ui/tooltip_trigger_component.rb', line 30

def trigger_attrs
  tooltip_trigger_html_attributes.deep_merge(@attributes)
end