Class: Shadcn::TooltipComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/tooltip_component.rb

Overview

Tooltip component for contextual information Matches shadcn/ui Tooltip component Uses Stimulus for interactivity

Examples:

Basic tooltip

<%= render Shadcn::TooltipComponent.new(text: "Add to library") do %>
  <%= render Shadcn::ButtonComponent.new(variant: :outline, size: :icon) do %>
    +
  <% end %>
<% end %>

With custom positioning

<%= render Shadcn::TooltipComponent.new(text: "Help", side: :right) do %>
  Hover me
<% end %>

Constant Summary collapse

CONTENT_CLASSES =
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground whitespace-nowrap animate-tooltip-in data-[state=closed]:animate-tooltip-out"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(text: nil, side: :top, align: :center, delay_duration: 200, skip_delay_duration: 300, **options) ⇒ TooltipComponent

Returns a new instance of TooltipComponent.

Parameters:

  • text (String) (defaults to: nil)

    Tooltip text content

  • side (Symbol) (defaults to: :top)

    Side to show tooltip (:top, :right, :bottom, :left)

  • align (Symbol) (defaults to: :center)

    Alignment (:start, :center, :end)

  • delay_duration (Integer) (defaults to: 200)

    Delay before showing (ms)

  • skip_delay_duration (Integer) (defaults to: 300)

    Delay when moving between triggers (ms)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/shadcn/tooltip_component.rb', line 28

def initialize(
  text: nil,
  side: :top,
  align: :center,
  delay_duration: 200,
  skip_delay_duration: 300,
  **options
)
  @tooltip_content = text
  @side = side
  @align = align
  @delay_duration = delay_duration
  @skip_delay_duration = skip_delay_duration
  super(**options)
end