tooltip

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tooltip provides tooltip/hint components.

Available variants:

  • New() creates a tooltip (template: "lvt:tooltip:default:v1")

Required lvt-* attributes: lvt-on:mouseenter, lvt-on:mouseleave, lvt-on:focus, lvt-on:blur

Example usage:

// In your controller/state
HelpTip: tooltip.New("help-tip",
    tooltip.WithContent("Click to learn more"),
    tooltip.WithPosition(tooltip.PositionTop),
)

// In your template
{{template "lvt:tooltip:default:v1" .HelpTip}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates() *base.TemplateSet

Templates returns the tooltip component's template set for registration with the LiveTemplate framework.

Example usage in main.go:

import "github.com/livetemplate/lvt/components/tooltip"

tmpl, err := livetemplate.New("app",
    livetemplate.WithComponentTemplates(tooltip.Templates()),
)

Available templates:

  • "lvt:tooltip:default:v1" - Basic tooltip

Types

type Option

type Option func(*Tooltip)

Option is a functional option for configuring tooltips.

func WithArrow

func WithArrow(show bool) Option

WithArrow enables or disables the arrow.

func WithContent

func WithContent(content string) Option

WithContent sets the tooltip content.

func WithDelay

func WithDelay(delay int) Option

WithDelay sets the show delay in milliseconds.

func WithHideDelay

func WithHideDelay(delay int) Option

WithHideDelay sets the hide delay in milliseconds.

func WithMaxWidth

func WithMaxWidth(width string) Option

WithMaxWidth sets the maximum width.

func WithPosition

func WithPosition(position Position) Option

WithPosition sets the tooltip position.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling.

func WithTrigger

func WithTrigger(trigger Trigger) Option

WithTrigger sets the tooltip trigger.

func WithVisible

func WithVisible(visible bool) Option

WithVisible sets the initial visibility state.

type Position

type Position string

Position defines where the tooltip appears relative to trigger.

const (
	PositionTop         Position = "top"
	PositionTopStart    Position = "top-start"
	PositionTopEnd      Position = "top-end"
	PositionBottom      Position = "bottom"
	PositionBottomStart Position = "bottom-start"
	PositionBottomEnd   Position = "bottom-end"
	PositionLeft        Position = "left"
	PositionLeftStart   Position = "left-start"
	PositionLeftEnd     Position = "left-end"
	PositionRight       Position = "right"
	PositionRightStart  Position = "right-start"
	PositionRightEnd    Position = "right-end"
)

type Tooltip

type Tooltip struct {
	base.Base

	// Content is the tooltip text
	Content string

	// Position is where the tooltip appears
	Position Position

	// Trigger is what action shows the tooltip
	Trigger Trigger

	// Visible indicates whether the tooltip is shown
	Visible bool

	// Delay in milliseconds before showing (for hover)
	Delay int

	// HideDelay in milliseconds before hiding (for hover)
	HideDelay int

	// Arrow shows a pointing arrow
	Arrow bool

	// MaxWidth limits tooltip width
	MaxWidth string
}

Tooltip is a contextual hint component. Use template "lvt:tooltip:default:v1" to render.

func New

func New(id string, opts ...Option) *Tooltip

New creates a tooltip.

Example:

t := tooltip.New("help",
    tooltip.WithContent("Help text"),
    tooltip.WithPosition(tooltip.PositionTop),
)

func (*Tooltip) ArrowClasses

func (t *Tooltip) ArrowClasses() string

ArrowClasses returns CSS classes for the arrow.

func (*Tooltip) HasContent

func (t *Tooltip) HasContent() bool

HasContent returns true if tooltip has content.

func (*Tooltip) Hide

func (t *Tooltip) Hide()

Hide makes the tooltip invisible.

func (*Tooltip) IsBottom

func (t *Tooltip) IsBottom() bool

IsBottom returns true if position starts with "bottom".

func (*Tooltip) IsClickTrigger

func (t *Tooltip) IsClickTrigger() bool

IsClickTrigger returns true if trigger is click.

func (*Tooltip) IsFocusTrigger

func (t *Tooltip) IsFocusTrigger() bool

IsFocusTrigger returns true if trigger is focus.

func (*Tooltip) IsHoverTrigger

func (t *Tooltip) IsHoverTrigger() bool

IsHoverTrigger returns true if trigger is hover.

func (*Tooltip) IsLeft

func (t *Tooltip) IsLeft() bool

IsLeft returns true if position starts with "left".

func (*Tooltip) IsRight

func (t *Tooltip) IsRight() bool

IsRight returns true if position starts with "right".

func (*Tooltip) IsTop

func (t *Tooltip) IsTop() bool

IsTop returns true if position starts with "top".

func (*Tooltip) PositionClasses

func (t *Tooltip) PositionClasses() string

PositionClasses returns CSS classes for position.

func (*Tooltip) Show

func (t *Tooltip) Show()

Show makes the tooltip visible.

func (*Tooltip) Styles

func (t *Tooltip) Styles() styles.TooltipStyles

Styles returns the resolved TooltipStyles for this component.

func (*Tooltip) Toggle

func (t *Tooltip) Toggle()

Toggle toggles tooltip visibility.

type Trigger

type Trigger string

Trigger defines what action shows the tooltip.

const (
	TriggerHover Trigger = "hover"
	TriggerFocus Trigger = "focus"
	TriggerClick Trigger = "click"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL