HoverCard
HoverCard shows a preview of additional details when the user hovers over a trigger element.
Code
<HoverCard> <HoverCardTrigger className="tw:cursor-pointer tw:underline" render={<Button variant="link">Green Valley Farm</Button>} />
<HoverCardContent> <div className="tw:flex tw:flex-col tw:gap-2"> <h4 className="tw:text-sm tw:font-semibold">Green Valley Farm</h4>
<p className="tw:text-sm tw:text-muted-foreground"> Primary contact: Maria Larsen. Current balance: $12,450. </p>
<p className="tw:text-xs tw:text-muted-foreground"> Last order placed 2 days ago </p> </div> </HoverCardContent></HoverCard>HoverCard
Section titled “HoverCard”| Name | Type/Description |
|---|---|
actionsRef | RefObject<PreviewCardRootActions | null> | undefinedA ref to imperative actions. - `unmount`: Unmounts the preview card popup. - `close`: Closes the preview card imperatively when called. |
children | ReactNode | PayloadChildRenderFunction<unknown>The content of the preview card. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
defaultOpen = false | boolean | undefinedWhether the preview card is initially open. To render a controlled preview card, use the `open` prop instead. |
defaultTriggerId | string | null | undefinedID of the trigger that the preview card is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open preview card. |
handle | PreviewCardHandle<unknown> | undefinedA handle to associate the preview card with a trigger. If specified, allows external triggers to control the card's open state. Can be created with the PreviewCard.createHandle() method. |
onOpenChange | ((open: boolean, eventDetails: PreviewCardRootChangeEventDetails) => void) | undefinedEvent handler called when the preview card is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | undefinedEvent handler called after any animations complete when the preview card is opened or closed. |
open | boolean | undefinedWhether the preview card is currently open. |
triggerId | string | null | undefinedID of the trigger that the preview card is associated with. This is useful in conjunction with the `open` prop to create a controlled preview card. There's no need to specify this prop when the preview card is uncontrolled (that is, when the `open` prop is not set). |
HoverCardContent
Section titled “HoverCardContent”| Name | Type/Description |
|---|---|
align = "center" | Align | undefinedHow to align the popup relative to the specified side. |
alignOffset = 4 | number | OffsetFunction | undefinedAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} /> ``` |
className | string | ((state: PreviewCardPopupState) => string | undefined) | undefinedCSS class applied to the element, or a function that returns a class based on the component's state. |
ref | ((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement> | null | undefined |
render | ReactElement<any, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PreviewCardPopupState> | undefinedAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
side = "bottom" | Side | undefinedWhich side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset = 4 | number | OffsetFunction | undefinedDistance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} /> ``` |
style | CSSProperties | ((state: PreviewCardPopupState) => CSSProperties | undefined) | undefinedStyle applied to the element, or a function that returns a style object based on the component's state. |
HoverCardTrigger
Section titled “HoverCardTrigger”| Name | Type/Description |
|---|---|
className | string | ((state: PreviewCardTriggerState) => string | undefined) | undefinedCSS class applied to the element, or a function that returns a class based on the component's state. |
closeDelay = 300 | number | undefinedHow long to wait before closing the preview card. Specified in milliseconds. |
delay = 600 | number | undefinedHow long to wait before the preview card opens. Specified in milliseconds. |
handle | PreviewCardHandle<unknown> | undefinedA handle to associate the trigger with a preview card. |
payload | unknownA payload to pass to the preview card when it is opened. |
ref | ((instance: HTMLAnchorElement | null) => void) | RefObject<HTMLAnchorElement> | null | undefined |
render | ReactElement<any, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PreviewCardTriggerState> | undefinedAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | CSSProperties | ((state: PreviewCardTriggerState) => CSSProperties | undefined) | undefinedStyle applied to the element, or a function that returns a style object based on the component's state. |