A short hint on hover or focus: a shortcut or a cut-off name. The first waits; its neighbours show at once.
Bold ⌘B
Italic ⌘I
Strikethrough ⌘⇧X
Inline code ⌘E
Link ⌘K
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { buttonStyle } from "./ui/uicontext/components/Button.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { Tip, TipGroup } from "./ui/uicontext/components/Tip.ts"import { color, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ toolbar: { display: "inline-flex", gap: space.xxs, padding: space.xs, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, }, divider: { inlineSize: 1, marginInline: space.xs, backgroundColor: color.line },})const tools = [ { id: "bold", label: "Bold", tip: "Bold ⌘B", d: "M7 5h6a3.5 3.5 0 0 1 0 7H7zM7 12h7a3.5 3.5 0 0 1 0 7H7z" }, { id: "italic", label: "Italic", tip: "Italic ⌘I", d: "M14 5h-4M14 19h-4M13 5l-2 14" }, { id: "strike", label: "Strikethrough", tip: "Strikethrough ⌘⇧X", d: "M5 12h14M16 7c-.8-1.3-2.3-2-4-2-2.2 0-4 1.2-4 3 0 1.4 1 2.3 3 3M8 17c.8 1.3 2.3 2 4 2 2.2 0 4-1.2 4-3" }, { id: "code", label: "Inline code", tip: "Inline code ⌘E", d: "M9 8l-4 4 4 4M15 8l4 4-4 4" }, { id: "link", label: "Link", tip: "Link ⌘K", d: "M10 14a4 4 0 0 0 5.7 0l2.8-2.8a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-2.8 2.8a4 4 0 0 0 5.7 5.7l1-1" },] as constconst Message = UiSchema.TaggedEnum({ RequestedOpenTip: { id: Schema.String }, RequestedCloseTip: { id: Schema.String } })export const FormattingToolbar = Html.component({ name: "FormattingToolbar", model: Schema.Struct({ tip: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ tip: null }), update: { RequestedOpenTip: ($, { id }) => $.evolve({ tip: id }), // a late close from the tip just left mustn't close the one just opened RequestedCloseTip: ($, { id }) => ($.model.tip === id ? $.evolve({ tip: null }) : $.model), }, view: (h, { tip }) => // in a group the first tip waits for the hover delay; the next one shows at once TipGroup(h, () => h.div.attrs({ role: "group", "aria-label": "Formatting", ...sx(styles.toolbar) }).children( tools.flatMap((tool, i) => [ ...(i === 3 ? [h.span.key("divider").attrs({ "aria-hidden": "true", ...sx(styles.divider) })] : []), Tip(h, { key: tool.id, open: tip === tool.id, text: tool.tip, onRequestedOpen: Message.RequestedOpenTip({ id: tool.id }), onRequestedClose: Message.RequestedCloseTip({ id: tool.id }), trigger: (tooltip) => tooltip.trigger(h.button).attrs({ type: "button", "aria-label": tool.label, ...sx(...buttonStyle({ emphasis: "ghost", iconOnly: true, size: "sm" })) }).children( h.svg.attrs({ width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }) .children(h.path.attrs({ d: tool.d })), ), }), ]), ), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/tooltipUsage
import { Tip } from "./ui/uicontext/components/Tip.ts"const Message = UiSchema.TaggedEnum({ RequestedOpenTip: {}, RequestedCloseTip: {} })export const ArchiveTip = (h: Html.H<typeof Message.Type>, open: boolean) => Tip(h, { open, text: "Archive E", onRequestedOpen: Message.RequestedOpenTip(), onRequestedClose: Message.RequestedCloseTip(), trigger: (tooltip) => tooltip.trigger(h.button).attrs({ type: "button" }).children("Archive"), })Examples
Full name of a cut-off file
Only the names cut short get a tip. It sits below, and the link's label is the whole name.
- Q3 Board Deck — FINAL…legal].pdfQ3 Board Deck — FINAL (revised) v12 [approved by legal].pdf
- IMG_20250914_183022_HD…edited.HEICIMG_20250914_183022_HDR_portrait_edited_edited.HEIC
- pricing.md
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { middleTruncate } from "./ui/uicontext/components/domain/Format.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { Tip, TipGroup } from "./ui/uicontext/components/Tip.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ list: { margin: 0, padding: space.xs, listStyle: "none", inlineSize: "min(100%, 20rem)", borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, }, file: { display: "flex", alignItems: "center", inlineSize: "100%", minBlockSize: { default: 32, "@media (pointer: coarse)": 40 }, paddingInline: space.md, borderRadius: radius.sm, color: color.fg, fontSize: font.sm, textDecoration: "none", whiteSpace: "nowrap", backgroundColor: { default: "transparent", ":hover": color.hover }, outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` }, },})const files = [ "Q3 Board Deck — FINAL (revised) v12 [approved by legal].pdf", "IMG_20250914_183022_HDR_portrait_edited_edited.HEIC", "pricing.md",]const Message = UiSchema.TaggedEnum({ RequestedOpenTip: { file: Schema.String }, RequestedCloseTip: { file: Schema.String } })// a long name is cut from the middle so the extension stays; the tip shows the whole name, belowexport const Attachments = Html.component({ name: "Attachments", model: Schema.Struct({ tip: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ tip: null }), update: { RequestedOpenTip: ($, { file }) => $.evolve({ tip: file }), RequestedCloseTip: ($, { file }) => ($.model.tip === file ? $.evolve({ tip: null }) : $.model), }, view: (h, { tip }) => TipGroup(h, () => h.ul.attrs({ "aria-label": "Attachments", ...sx(styles.list) }).children( files.map((file) => { const shown = middleTruncate(file, 34) const link = h.a.attrs({ href: `#${encodeURIComponent(file)}`, ...sx(styles.file) }) return h.li.key(file).children( shown === file ? link.children(file) : Tip(h, { key: file, open: tip === file, text: file, side: "bottom", // the link's own text is cut short, so the full name is its label, not a description describesTrigger: false, onRequestedOpen: Message.RequestedOpenTip({ file }), onRequestedClose: Message.RequestedCloseTip({ file }), trigger: (tooltip) => tooltip.trigger(link).attrs({ "aria-label": file }).children(shown), }), ) }), ), ),})API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the tooltip among others in the same view; needed for more than one |
openrequired | boolean | — | — |
textrequired | string | — | — |
onRequestedOpenrequired | Message | — | — |
onRequestedCloserequired | Message | — | — |
describesTrigger | boolean | True | The tip adds to the trigger's label (a shortcut, a detail), so it's also the trigger's accessible description; leave it off when it repeats the label. True by default. |
side | "top" | "bottom" | — | — |
triggerrequired | (tooltip: TipParts<Message>) => View.Input | — | The trigger: apply tooltip.trigger to a button or link builder |