Documentation navigation

Published API · 0.1.0-rc.1

themes · components/tooltip

Published themes API declarations for components/tooltip.

./components/tooltip

@wsagency/wseffect-themes · MIT · source · MIT license · WS-AGENCY-NOTICE

This entry point is published in @wsagency/wseffect-themes@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-themes/components/tooltip'

Exported declarations

embed

embed: <ParentMessage>(h: HtmlBuilder<ParentMessage>, config: EmbedConfig<ParentMessage>) => Html

EmbedConfig

export type EmbedConfig<Message> = Readonly<{
    slotId: string;
    model: UiTooltip.Model;
    toParentMessage: (message: UiTooltip.Message) => Message;
    viewInputs: ViewInputs<Message>;
}>;

fold

fold: <ParentModel, ParentMessage, ParentOutMessage>(config: Omit<Update.ChildFoldWithDerivedParentOutMessage<ParentModel, ParentMessage, UiTooltip.Model, UiTooltip.Message, UiTooltip.Message, UiTooltip.OutMessage, ParentOutMessage>, 'update'> & Readonly<{
    readGroup?: (parentModel: ParentModel) => TooltipGroup.Model;
}>) => Update.FoldWithOutMessage<ParentModel, ParentMessage, UiTooltip.Message, ParentOutMessage>

init

init: (config: UiTooltip.InitConfig) => UiTooltip.Model

Message

export type Message = typeof Message.Type;

Message

Union of all messages the tooltip component can produce.

Message: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly EnteredTrigger: {};
    readonly LeftTrigger: {};
    readonly FocusedTrigger: {};
    readonly BlurredTrigger: {};
    readonly PressedEscape: {};
    readonly PressedPointerOnTrigger: {
        pointerType: Schema.String;
    };
    readonly CompletedWaitBeforeShowing: {
        version: Schema.Number;
    };
    readonly CompletedAnchorTooltip: {};
}>

Model

export type Model = typeof Model.Type;

Model

Schema for the tooltip component's state. `isOpen` is visibility; `isHovered` tracks pointer on trigger; `isFocused` tracks tooltip-affirming focus on the trigger (focus arriving without a preceding mouse press, like keyboard, touch, or pen; mouse-click-induced focus is excluded since it doesn't affirm the user wants the tooltip visible); `isDismissed` suppresses re-opening after the user dismissed the tooltip (via Escape) until they disengage (leave or blur). `showDelay` is the hover-to-show duration. `maybeLastPointerType` records the most recent pointer type that pressed the trigger, so a mouse-click-induced focus can be distinguished from other focus.

Model: Schema.Struct<{
    readonly id: Schema.String;
    readonly isOpen: Schema.Boolean;
    readonly isHovered: Schema.Boolean;
    readonly isFocused: Schema.Boolean;
    readonly isDismissed: Schema.Boolean;
    readonly showDelay: Schema.DurationFromMillis;
    readonly pendingShowVersion: Schema.Number;
    readonly maybeLastPointerType: Schema.Option<Schema.String>;
}>

OutMessage

export type OutMessage = typeof OutMessage.Type;

OutMessage

Union of out-messages the tooltip component can produce.

OutMessage: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly Shown: {};
    readonly Hidden: {};
}>

reflectShowDelay

reflectShowDelay: (model: UiTooltip.Model, group: TooltipGroup.Model) => UiTooltip.Model

triggerId

Returns the bare DOM id of the tooltip trigger button, derived from the tooltip's base id. Use this to associate an external label with the trigger via a native `<label for={Tooltip.triggerId(id)}>` or an `aria-labelledby` reference.

triggerId: (id: string) => string

update

Processes a Tooltip Message and returns the next Model, optional Commands, and an optional OutMessage. `Shown`/`Hidden` fire only on `isOpen` transitions, so consumers don't get spurious events for messages that only update hover/focus/delay state without changing visibility.

update: (model: Model, message: Message) => Update.ReturnWithOutMessage<Model, Message, OutMessage>

ViewInputs

export type ViewInputs<Message> = Readonly<{
    trigger: ReadonlyArray<Html | string>;
    content: ReadonlyArray<Html | string>;
    anchor?: AnchorConfig;
    isDisabled?: boolean;
    ariaLabel?: string;
    ariaLabelledBy?: string;
}>;

Rendered component example

Tooltip
Example usage
import * as Themes from '@wsagency/wseffect-themes'
import * as SliderRange from '@wsagency/wseffect-themes/components/slider/range'
import * as Option from 'effect/Option'
import { defineView } from '@wsagency/wseffect-foldkit/submodel'
import { inertHtml, type HtmlBuilder } from '@wsagency/wseffect-foldkit/html'

const example = (h: HtmlBuilder<unknown>) => Themes.Tooltip.embed(h, { slotId: 'save-tooltip-example', model: Themes.Tooltip.init({ id: 'save-tooltip-example' }), toParentMessage: (message) => message, viewInputs: { trigger: [h.span([], ['Save'])], content: ['Save your changes'] } })