Class: Daisy::Feedback::TooltipComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/feedback/tooltip_component.rb

Overview

The TooltipComponent displays informative text when users hover over an element. It can be used in two ways:

  1. As a wrapper component around any HTML content.

  2. Through the TippableComponent concern, which many components include.

This component is also aliased as ‘daisy_tip` for convenience.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws, &block) ⇒ TooltipComponent

Creates a new Tooltip component.

Parameters:

  • args (Array)

    If provided, the first argument is used as the ‘tip` text.

  • kws (Hash)

    Keyword arguments for customizing the tooltip.

Options Hash (**kws):

  • tip (String)

    The text to display in the tooltip. Can be passed as the first positional argument or as a keyword argument.

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Position modifiers: ‘tooltip-top`, `tooltip-bottom`, `tooltip-left`, `tooltip-right`

    • Colors: ‘tooltip-primary`, `tooltip-secondary`, `tooltip-accent`, `tooltip-info`, `tooltip-success`, `tooltip-warning`, `tooltip-error`

    • Open state: ‘tooltip-open`



55
56
57
58
59
60
# File 'app/components/daisy/feedback/tooltip_component.rb', line 55

def initialize(*args, **kws, &block)
  super

  # Accept a `tip` keyword argument, or the first positional argument
  @tip = config_option(:tip, args[0])
end

Instance Method Details

#before_renderObject

Sets up the component’s CSS and HTML attributes.



65
66
67
68
# File 'app/components/daisy/feedback/tooltip_component.rb', line 65

def before_render
  add_css(:component, "tooltip")
  add_html(:component, { data: { tip: @tip } }) if @tip
end

#callObject

Renders the component and its content (inline).



73
74
75
# File 'app/components/daisy/feedback/tooltip_component.rb', line 73

def call
  part(:component) { content }
end