Class: IronAdmin::Ui::TooltipComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/iron_admin/ui/tooltip_component.rb

Overview

Renders a tooltip that appears on hover.

Examples:

Basic tooltip

render IronAdmin::Ui::TooltipComponent.new(text: "More info") do
  heroicon("information-circle")
end

Constant Summary collapse

POSITIONS =

Position class mappings.

Returns:

  • (Hash{Symbol => String})
{
  top: "bottom-full left-1/2 -translate-x-1/2 mb-2",
  bottom: "top-full left-1/2 -translate-x-1/2 mt-2",
  left: "right-full top-1/2 -translate-y-1/2 mr-2",
  right: "left-full top-1/2 -translate-y-1/2 ml-2",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, position: :top) ⇒ TooltipComponent

Returns a new instance of TooltipComponent.

Parameters:

  • text (String)

    Tooltip text

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

    Position (default: :top)



29
30
31
32
# File 'app/components/iron_admin/ui/tooltip_component.rb', line 29

def initialize(text:, position: :top)
  @text = text
  @position = position.to_sym
end

Instance Attribute Details

#positionSymbol (readonly)

Returns Position (:top, :bottom, :left, :right).

Returns:

  • (Symbol)

    Position (:top, :bottom, :left, :right)



16
17
18
# File 'app/components/iron_admin/ui/tooltip_component.rb', line 16

def position
  @position
end

#textString (readonly)

Returns Tooltip text.

Returns:

  • (String)

    Tooltip text



13
14
15
# File 'app/components/iron_admin/ui/tooltip_component.rb', line 13

def text
  @text
end

Instance Method Details

#position_classesString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CSS classes for tooltip position.

Returns:

  • (String)

    CSS classes for tooltip position



36
37
38
# File 'app/components/iron_admin/ui/tooltip_component.rb', line 36

def position_classes
  POSITIONS[@position] || POSITIONS[:top]
end

#tooltip_classesString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CSS classes for tooltip container.

Returns:

  • (String)

    CSS classes for tooltip container



42
43
44
45
46
# File 'app/components/iron_admin/ui/tooltip_component.rb', line 42

def tooltip_classes
  "absolute #{position_classes} px-2 py-1 text-xs font-medium text-white bg-gray-900 " \
    "rounded whitespace-nowrap opacity-0 invisible group-hover:opacity-100 group-hover:visible " \
    "transition-all duration-150 z-50"
end