All components
Hover Card
Rich preview panels revealed from a trigger, in four padding sizes.
1234567891011121314151617import { HoverCard } from "#components/ui/ui-sdk/hover-card.tsx";
// UI SDK's hover card: the trigger is a link, and Content opens in the// browser's top layer, so there is no Portal or Positioner.export function Example() { return ( <HoverCard.Root size="md" delay={200} closeDelay={300}> <HoverCard.Trigger href="https://x.com/stylexblocks"> @stylexblocks </HoverCard.Trigger> <HoverCard.Content sideOffset={8}> <strong>StyleX Blocks</strong> <p>Production-ready blocks and themes, compiled with StyleX.</p> </HoverCard.Content> </HoverCard.Root> );}Sizes
Install
1npx stylexblocks add hover-cardSource
components/ui/ui-sdk/hover-card.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175import * as stylex from "@stylexjs/stylex";import { HoverCard as UiSdkHoverCard, HoverCardArrow, HoverCardContent, HoverCardTrigger,} from "@ui-sdk/react/hover-card";import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.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 { 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 hoverCardContent = stylex.create({ base: { position: 'relative', display: 'flex', flexDirection: 'column', fontSize: fontSizes.sm, lineHeight: lineHeights.sm, '--hovercard-bg': semanticColors.bgPanel, backgroundColor: 'var(--hovercard-bg)', maxWidth: sizes._80, '--hover-card-z-index': zIndices.layer2, zIndex: 'calc(var(--hover-card-z-index) + var(--layer-index, 0))', transformOrigin: 'var(--transform-origin)', outline: 'none', '--hover-card-radius': semanticRadii.panel, '--hover-card-concentric-radius': 'max(0px, calc(var(--hover-card-radius) - var(--hover-card-padding)))', 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.faster, }, },})
const hoverCardContentSizes = stylex.create({ xs: { '--hover-card-padding': spacing._3, padding: 'var(--hover-card-padding)', }, sm: { '--hover-card-padding': spacing._4, padding: 'var(--hover-card-padding)', }, md: { '--hover-card-padding': spacing._5, padding: 'var(--hover-card-padding)', }, lg: { '--hover-card-padding': spacing._6, padding: 'var(--hover-card-padding)', },})
const hoverCardArrow = stylex.create({ base: { '--arrow-size': sizes._3, '--arrow-background': 'var(--hovercard-bg)', },})
const hoverCardArrowTip = stylex.create({ base: { borderTopWidth: '0.5px', borderInlineStartWidth: '0.5px', },})
export type HoverCardSize = keyof typeof hoverCardContentSizes
// defineSlotRecipe validates the shape at compile time: default values must// exist in the axis maps, and slot keys must be `styles` or a declared axisconst hoverCardRecipe = defineSlotRecipe({ slots: { content: { styles: hoverCardContent, sizes: hoverCardContentSizes }, arrow: { styles: hoverCardArrow }, arrowTip: { styles: hoverCardArrowTip }, }, defaultVariants: { size: "md" },});
// Local chrome the recipe leaves to the composition layer: the panel surface// and a z-index that clears sticky page chrome — the generated `layer2` (10)// would sit beneath a `z-index: 50` site header. UI SDK's content is a// native popover in the top layer, so the surface also clears the browser's// popover margin, border and overflow, and only takes the recipe's// `display: flex` while open (the recipe sizes set the padding).const chrome = stylex.create({ content: { "--hover-card-z-index": zIndices.popover, display: { default: null, ":popover-open": "flex", }, margin: 0, borderWidth: 0, overflow: "visible", color: "inherit", borderRadius: "var(--hover-card-radius)", boxShadow: semanticShadows.overlay, }, // 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(hoverCardRecipe);
const StyledContent = withContext( HoverCardContent, (v) => [...resolveSlotStyles(hoverCardRecipe.slots.content, v), chrome.content], "HoverCardContent",);
/** Content defaults to an 8px gap from the trigger, like Ark's positioner. */function Content(allProps: React.ComponentProps<typeof StyledContent>) { const { sideOffset = 8, ...rest } = allProps; return <StyledContent sideOffset={sideOffset} {...rest} />;}Content.displayName = "HoverCardContent";
/** * Hover Card — UI SDK's hover card wearing the hover-card slot recipe. The * trigger is a link (give it an `href`); the content is a native popover in * the browser's top layer, so there is no Portal or Positioner: placement * props go on `Content`. Hover intent with `delay` / `closeDelay` (on Root) * comes from the engine. `<HoverCard.Root size>` resolves the recipe once; * parts inherit it through context and compose via `render`. */export const HoverCard = { Root: withRootProvider(UiSdkHoverCard, "HoverCardRoot"), Trigger: HoverCardTrigger, Content, Arrow: withContext( HoverCardArrow, (v) => [...resolveSlotStyles(hoverCardRecipe.slots.arrow, v), chrome.arrow], "HoverCardArrow", ),};
Examples
Installable blocks built with Hover Card — real use cases, delivered as source you own.
Project Status Dashboard
Launch-readiness program tracker powered by TanStack Charts: release KPI sparklines, phase-filtered milestone Gantt with a Today marker, burndown vs. planned trajectory, sprint velocity, weighted scope allocation, blockers & risks callouts, and a health-filterable workstream progress table.