Emit static fallback tokens for forced-colors mode
Map semantic border and focus-ring variables to system color keywords when Windows High Contrast is active.
Short contextual labels with a default panel style and an inverted variant.
1234567891011121314151617import { Tooltip } from "#components/ui/ui-sdk/tooltip.tsx";import { Button } from "#components/ui/ui-sdk/button.tsx";
export function Example() { return ( // variant="inverted" flips the surface; Content opens in the browser's // top layer (no Portal or Positioner), and tooltips group their delays // without a Provider. <Tooltip.Root variant="inverted" delay={200} closeDelay={100}> <Tooltip.Trigger render={<Button variant="surface" />}>Copy</Tooltip.Trigger> <Tooltip.Content sideOffset={8}> <Tooltip.Arrow /> Copy to clipboard </Tooltip.Content> </Tooltip.Root> );}1npx stylexblocks add tooltip123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import * as stylex from "@stylexjs/stylex";import { Tooltip as UiSdkTooltip, TooltipArrow, TooltipContent, TooltipTrigger,} from "@ui-sdk/react/tooltip";import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";import { defineSlotRecipe, fromMap, resolveSlotStyles } from "#lib/recipe-props.ts";import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'
const tooltipContent = stylex.create({ base: { '--tooltip-bg': semanticColors.bg, display: 'flex', alignItems: 'center', backgroundColor: 'var(--tooltip-bg)', color: semanticColors.fg, paddingInline: spacing._2_5, paddingBlock: spacing._1, borderRadius: semanticRadii.panel, fontWeight: fontWeights.medium, fontSize: fontSizes.xs, lineHeight: lineHeights.xs, boxShadow: semanticShadows.overlay, maxWidth: sizes.xs, zIndex: zIndices.tooltip, transformOrigin: 'var(--transform-origin)', animationName: { default: null, ':is([data-open], [data-state="open"])': 'scale-in, fade-in', ':is([data-closed], [data-state="closed"])': 'scale-out, fade-out', }, animationDuration: { default: null, ':is([data-open], [data-state="open"])': durations.fast, ':is([data-closed], [data-state="closed"])': durations.fast, }, },})
const tooltipContentVariants = stylex.create({ inverted: { '--tooltip-bg': semanticColors.bgInverted, color: semanticColors.fgInverted, },})
const tooltipArrow = stylex.create({ base: { '--arrow-size': sizes._2, '--arrow-background': 'var(--tooltip-bg)', zIndex: -1, },})
const tooltipArrowTip = stylex.create({ base: { borderTopWidth: '1px', borderInlineStartWidth: '1px', borderColor: 'var(--tooltip-bg)', },})
export type TooltipVariant = keyof typeof tooltipContentVariants
// The generated variant map is sparse (`inverted` only). An empty `solid`// entry is the implicit default panel look so `defaultVariants` type-checks.const tooltipPlain = stylex.create({ solid: {} });
const tooltipRecipe = defineSlotRecipe({ slots: { content: { styles: tooltipContent, variants: { solid: tooltipPlain.solid, inverted: tooltipContentVariants.inverted, }, }, arrow: { styles: tooltipArrow }, arrowTip: { styles: tooltipArrowTip }, }, defaultVariants: { variant: "solid" },});
// UI SDK's tooltip content is a native popover that stays in the page,// hidden, from the start (so it can name its trigger). It only takes the// recipe's `display: flex` while open, and clears the browser's popover// margin, border and overflow.const chrome = stylex.create({ content: { display: { default: null, ":popover-open": "flex", }, margin: 0, borderWidth: 0, overflow: "visible", }, // UI SDK places the arrow along the edge (`left`/`top`); the cross axis, // the diamond, and its color are ours. arrow: { width: "var(--arrow-size)", height: "var(--arrow-size)", backgroundColor: "var(--arrow-background)", transform: "rotate(45deg)", top: { default: null, ':is([data-side="bottom"])': "calc(var(--arrow-size) / -2)", }, bottom: { default: null, ':is([data-side="top"])': "calc(var(--arrow-size) / -2)", }, left: { default: null, ':is([data-side="right"])': "calc(var(--arrow-size) / -2)", }, right: { default: null, ':is([data-side="left"])': "calc(var(--arrow-size) / -2)", }, },});
const { withRootProvider, withContext } = createSlotRecipeContext(tooltipRecipe);
/** * Tooltip — UI SDK's tooltip wearing the tooltip slot recipe. The content is * a native popover in the browser's top layer, so there is no Portal or * Positioner: placement props (`side`, `align`, `sideOffset`) go on * `Content`. Hover/focus intent, delays (`delay`, `closeDelay` on Root), and * grouping across tooltips come from the engine — no Provider needed. * `<Tooltip.Root variant>` resolves the recipe once; parts inherit it through * context and compose via `render`. */export const Tooltip = { Root: withRootProvider(UiSdkTooltip, "TooltipRoot"), Trigger: TooltipTrigger, Content: withContext( TooltipContent, (v) => [tooltipContent.base, fromMap(tooltipContentVariants, v.variant), chrome.content], "TooltipContent", ), Arrow: withContext( TooltipArrow, (v) => [...resolveSlotStyles(tooltipRecipe.slots.arrow, v), chrome.arrow], "TooltipArrow", ),};
Installable blocks built with Tooltip — real use cases, delivered as source you own.
Two-column storefront checkout with express wallets, shipping and billing address fields, selectable delivery cards, auto-formatted card entry with network detection, promo code discounts, gift notes, inline validation, and a sticky collapsible order summary.
Four-step two-column checkout flow with live cart quantities and promo codes, country-aware shipping validation, delivery method selection, payment review, sticky order summary, and local order confirmation.
Transposed side-by-side vector database evaluation matrix with a sticky criteria label column, collapsible grouped rows, interactive column swapping and adding/removing, baseline pinning with relative deltas, best-in-row highlights, differences-only filtering, score bars, 30-day uptime telemetry, and a live recommendation footer.
Interactive four-lane sprint board with pointer drag-and-drop, keyboard and menu column movement, search and priority/assignee filters, quick-add task dialog, task detail drawer, and toast feedback.
Interactive design-system and token workbench featuring scoped accent, density, and corner-radius live preview controls over a responsive 3-column bento of cohesive UI SDK cards.