Preview Card
A link that shows a destination preview without interrupting keyboard or screen reader navigation.
In Nyte
import { PreviewCard } from "@nyte-ai/ui/preview-card";@nyte-ai/ui/preview-card re-exports the Base UI namespace unchanged. There is no Nyte styling on
this subpath; the consumer owns every class, StyleX style, and layout decision. Base UI owns the
interaction model, keyboard handling, focus management, and ARIA below.
Consumed by:
desktop/src/renderer/src/chrome/sidebar-session-preview.tsxdesktop/src/renderer/src/conversation/composer-suggestions.tsx
The rest of this page is Base UI's documentation for @base-ui/react/preview-card, reproduced
verbatim under the MIT license, © Material-UI SAS. Component paths in examples refer to the Base UI
package; in Nyte, import from the subpath above.
Usage guidelines
- Protect screen reader users' current context: Exposing each preview to screen readers would force users through its contents before they could continue through the page, repeatedly disrupting their current context. Keep the link as the only accessible interface and include all previewed information at its destination.
- Keep popup content supplementary: Avoid placing unique or essential information in the popup unless it is also available on the linked page. For the reason above, preview card content is not touch, keyboard or screen reader navigable. It acts as a visual progressive enhancement for sighted mouse and keyboard users only.
Anatomy
Import the component and assemble its parts:
import { PreviewCard } from '@base-ui/react/preview-card';
<PreviewCard.Root>
<PreviewCard.Trigger />
<PreviewCard.Portal>
<PreviewCard.Backdrop />
<PreviewCard.Positioner>
<PreviewCard.Popup>
<PreviewCard.Arrow />
<PreviewCard.Viewport />
</PreviewCard.Popup>
</PreviewCard.Positioner>
</PreviewCard.Portal>
</PreviewCard.Root>;Examples
Detached triggers
A preview card can be controlled by a trigger located either inside or outside the <PreviewCard.Root> component.
For simple, one-off interactions, place the <PreviewCard.Trigger> inside <PreviewCard.Root>, as shown in the example at the top of this page.
However, if defining the preview card's content next to its trigger is not practical, you can use a detached trigger.
This involves placing the <PreviewCard.Trigger> outside of <PreviewCard.Root> and linking them with a handle created by the PreviewCard.createHandle() function.
The imperative methods on the handle, such as open() and close(), require a <PreviewCard.Root> using the same handle to be mounted.
Calls made while no root is attached to the handle — before one mounts, or after it unmounts — are ignored. Each time a root mounts, it starts from fresh state: a call made while no root was attached is not replayed, and no open state carries over from a previous mount.
const demoPreviewCard = PreviewCard.createHandle();
// @highlight
// @highlight-text "handle={demoPreviewCard}"
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Link
</PreviewCard.Trigger>
// @highlight
// @highlight-text "handle={demoPreviewCard}"
<PreviewCard.Root handle={demoPreviewCard}>
...
</PreviewCard.Root>;Multiple triggers
A single preview card can be opened by multiple trigger elements.
You can achieve this by using the same handle for several detached triggers, or by placing multiple <PreviewCard.Trigger> components inside a single <PreviewCard.Root>.
<PreviewCard.Root>
<PreviewCard.Trigger href="#">Trigger 1</PreviewCard.Trigger>
<PreviewCard.Trigger href="#">Trigger 2</PreviewCard.Trigger>
...
</PreviewCard.Root>const demoPreviewCard = PreviewCard.createHandle();
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Trigger 1
</PreviewCard.Trigger>
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Trigger 2
</PreviewCard.Trigger>
<PreviewCard.Root handle={demoPreviewCard}>
...
</PreviewCard.Root>The preview card can render different content depending on which trigger opened it.
This is achieved by passing a payload to the <PreviewCard.Trigger> and using the function-as-a-child pattern in <PreviewCard.Root>.
The payload can be strongly typed by providing a type argument to the createHandle() function:
// @highlight
const demoPreviewCard = PreviewCard.createHandle<{ title: string }>();
// @highlight
// @highlight-text "payload"
<PreviewCard.Trigger handle={demoPreviewCard} payload={{ title: 'Trigger 1' }} href="#">
Trigger 1
</PreviewCard.Trigger>
// @highlight
// @highlight-text "payload"
<PreviewCard.Trigger handle={demoPreviewCard} payload={{ title: 'Trigger 2' }} href="#">
Trigger 2
</PreviewCard.Trigger>
<PreviewCard.Root handle={demoPreviewCard}>
{({ payload }) => ( // @highlight-text "payload"
<PreviewCard.Portal>
<PreviewCard.Positioner sideOffset={8}>
<PreviewCard.Popup>
{payload !== undefined && ( // @highlight-text "payload"
<span>
Preview card opened by {payload.title} {/* @highlight-text "payload" */}
</span>
)}
</PreviewCard.Popup>
</PreviewCard.Positioner>
</PreviewCard.Portal>
)}
</PreviewCard.Root>Controlled mode with multiple triggers
You can control the preview card's open state externally using the open and onOpenChange props on <PreviewCard.Root>.
This allows you to manage the preview card's visibility based on your application's state.
When using multiple triggers, you have to manage which trigger is active with the triggerId prop on <PreviewCard.Root> and the id prop on each <PreviewCard.Trigger>.
Note that there is no separate onTriggerIdChange prop.
Instead, the onOpenChange callback receives an additional argument, eventDetails, which contains the trigger element that initiated the state change.
Animating the Preview Card
You can animate a preview card as it moves between different trigger elements. This includes animating its position, size, and content.
Position and Size
To animate the preview card's position, apply CSS transitions to the left, right, top, and bottom properties of the Positioner part.
To animate its size, transition the width and height of the Popup part.
Content
The preview card also supports content transitions. This is useful when different triggers display different content within the same preview card.
To enable content animations, wrap the content in the <PreviewCard.Viewport> part.
This part provides features to create direction-aware animations.
It renders a div with a data-activation-direction attribute that indicates the new trigger's position relative to the previous one. The value is a space-separated set of up to two tokens (one per axis) — left or right for the horizontal axis and up or down for the vertical axis (for example, right down). Match a single token with the ~= attribute selector, such as [data-activation-direction~='right'].
Inside the <PreviewCard.Viewport>, the content is further wrapped in divs with data attributes to help with styling:
data-current: The currently visible content when no transitions are present or the incoming content.data-previous: The outgoing content during a transition.
You can use these attributes to style the enter and exit animations.
API reference
Root
Groups all parts of the preview card. Doesn't render its own HTML element.
Root Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultOpen | boolean | false | Whether the preview card is initially open. To render a controlled preview card, use the open prop instead. |
| open | boolean | - | Whether the preview card is currently open. |
| onOpenChange | ((open: boolean, eventDetails: PreviewCard.Root.ChangeEventDetails) => void) | - | Event handler called when the preview card is opened or closed. |
| actionsRef | React.RefObject<PreviewCard.Root.Actions | null> | - | A ref to imperative actions. unmount: Unmounts the preview card popup.close: Closes the preview card imperatively when called. |
| defaultTriggerId | string | null | - | ID 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 | PreviewCard.Handle<Payload> | - | A 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. |
| onOpenChangeComplete | ((open: boolean) => void) | - | Event handler called after any animations complete when the preview card is opened or closed. |
| triggerId | string | null | - | ID 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). |
| children | React.ReactNode | PayloadChildRenderFunction<Payload> | - | 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. |
Root.Props
Re-export of Root props.
Root.State
type PreviewCardRootState = {};Root.Actions
type PreviewCardRootActions = { unmount: () => void; close: () => void };Root.ChangeEventReason
type PreviewCardRootChangeEventReason =
| 'trigger-hover'
| 'trigger-focus'
| 'trigger-press'
| 'outside-press'
| 'escape-key'
| 'imperative-action'
| 'none';Root.ChangeEventDetails
type PreviewCardRootChangeEventDetails = (
| { reason: 'trigger-hover'; event: MouseEvent }
| { reason: 'trigger-focus'; event: FocusEvent }
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
preventUnmountOnClose: preventUnmountOnClose;
};Trigger
A link that opens the preview card.
Renders an <a> element.
Trigger Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| handle | PreviewCard.Handle<Payload> | - | A handle to associate the trigger with a preview card. |
| payload | Payload | - | A payload to pass to the preview card when it is opened. |
| delay | number | 600 | How long to wait before the preview card opens. Specified in milliseconds. |
| closeDelay | number | 300 | How long to wait before closing the preview card. Specified in milliseconds. |
| className | string | ((state: PreviewCard.Trigger.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Trigger.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, state: PreviewCard.Trigger.State) => ReactElement) | - | Allows 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. |
Trigger Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-popup-open | - | Present when the corresponding preview card is open. |
Trigger.Props
Re-export of Trigger props.
Trigger.State
type PreviewCardTriggerState = {
/** Whether the preview card is currently open and was opened by this trigger. */
open: boolean;
};Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>.
Renders a <div> element.
Portal Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| container | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | - | A parent element to render the portal element into. |
| className | string | ((state: PreviewCard.Portal.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Portal.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| keepMounted | boolean | false | Whether to keep the portal mounted in the DOM while the popup is hidden. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Portal.State) => ReactElement) | - | Allows 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. |
Portal.Props
Re-export of Portal props.
Portal.State
type PreviewCardPortalState = {};Backdrop
A presentational overlay displayed beneath the popup.
Renders a <div> element.
Backdrop Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: PreviewCard.Backdrop.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Backdrop.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Backdrop.State) => ReactElement) | - | Allows 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. |
Backdrop Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the preview card is open. |
| data-closed | - | Present when the preview card is closed. |
| data-starting-style | - | Present when the preview card begins animating in. |
| data-ending-style | - | Present when the preview card is animating out. |
Backdrop.Props
Re-export of Backdrop props.
Backdrop.State
type PreviewCardBackdropState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};Positioner
Positions the popup against the trigger.
Renders a <div> element.
Positioner Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| disableAnchorTracking | boolean | false | Whether to disable the popup from tracking any layout shift of its positioning anchor. |
| align | Align | 'center' | How to align the popup relative to the specified side. |
| alignOffset | number | OffsetFunction | 0 | Additional 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. |
| side | Side | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
| sideOffset | number | OffsetFunction | 0 | Distance 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. |
| arrowPadding | number | 5 | Minimum distance to maintain between the arrow and the edges of the popup. Use it to prevent the arrow element from hanging out of the rounded corners of a popup. |
| anchor | Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null | - | An element to position the popup against. By default, the popup will be positioned against the trigger. |
| collisionAvoidance | CollisionAvoidance | - | Determines how to handle collisions when positioning the popup. side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side
(top and bottom, or left and right).'shift': never change side; keep the requested side and move the popup within
the clipping boundary so it stays visible.'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the
alignment axis to fit.'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first
(top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first
(bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'. |
| collisionBoundary | Boundary | 'clipping-ancestors' | An element or a rectangle that delimits the area that the popup is confined to. |
| collisionPadding | Padding | 5 | Additional space to maintain from the edge of the collision boundary. |
| sticky | boolean | false | Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. |
| positionMethod | 'absolute' | 'fixed' | 'absolute' | Determines which CSS position property to use. |
| className | string | ((state: PreviewCard.Positioner.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Positioner.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Positioner.State) => ReactElement) | - | Allows 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. |
alignOffset Prop Example:
<Positioner
alignOffset={({ side, align, anchor, positioner }) => {
return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
}}
/>sideOffset Prop Example:
<Positioner
sideOffset={({ side, align, anchor, positioner }) => {
return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
}}
/>collisionAvoidance Prop Example:
<Positioner
collisionAvoidance={{
side: 'shift',
align: 'shift',
fallbackAxisSide: 'none',
}}
/>Positioner Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the preview card is open. |
| data-closed | - | Present when the preview card is closed. |
| data-anchor-hidden | - | Present when the anchor is hidden. |
| data-align | 'start' | 'center' | 'end' | Indicates how the popup is aligned relative to specified side. |
| data-side | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | Indicates which side the popup is positioned relative to the trigger. |
Positioner CSS Variables:
| Variable | Type | Description |
|---|---|---|
--anchor-height | number | The anchor's height. |
--anchor-width | number | The anchor's width. |
--available-height | number | The available height between the trigger and the edge of the viewport. |
--available-width | number | The available width between the trigger and the edge of the viewport. |
--positioner-height | number | The height of the preview card's positioner.
It is important to set height to this value when using CSS to animate size changes. |
--positioner-width | number | The width of the preview card's positioner.
It is important to set width to this value when using CSS to animate size changes. |
--transform-origin | string | The coordinates that this element is anchored to. Used for animations and transitions. |
Positioner.Props
Re-export of Positioner props.
Positioner.State
type PreviewCardPositionerState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
/** Whether transitions should be skipped. */
instant: 'dismiss' | 'focus' | undefined;
};Popup
A container for the preview card contents.
Renders a <div> element.
Popup Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: PreviewCard.Popup.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Popup.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Popup.State) => ReactElement) | - | Allows 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. |
Popup Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the preview card is open. |
| data-closed | - | Present when the preview card is closed. |
| data-align | 'start' | 'center' | 'end' | Indicates how the popup is aligned relative to specified side. |
| data-side | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | Indicates which side the popup is positioned relative to the trigger. |
| data-starting-style | - | Present when the preview card begins animating in. |
| data-ending-style | - | Present when the preview card is animating out. |
Popup.Props
Re-export of Popup props.
Popup.State
type PreviewCardPopupState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether transitions should be skipped. */
instant: 'dismiss' | 'focus' | undefined;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};Arrow
Displays an element positioned against the preview card anchor.
Renders a <div> element.
Arrow Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: PreviewCard.Arrow.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Arrow.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Arrow.State) => ReactElement) | - | Allows 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. |
Arrow Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the preview card is open. |
| data-closed | - | Present when the preview card is closed. |
| data-uncentered | - | Present when the preview card arrow is uncentered. |
| data-align | 'start' | 'center' | 'end' | Indicates how the popup is aligned relative to specified side. |
| data-side | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | Indicates which side the popup is positioned relative to the trigger. |
Arrow.Props
Re-export of Arrow props.
Arrow.State
type PreviewCardArrowState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the arrow cannot be centered on the anchor. */
uncentered: boolean;
};Viewport
A viewport for displaying content transitions.
This component is only required if one popup can be opened by multiple triggers, its content
changes based on the trigger, and switching between them is animated.
Renders a <div> element.
Viewport Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | - | The content to render inside the transition container. |
| className | string | ((state: PreviewCard.Viewport.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: PreviewCard.Viewport.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: PreviewCard.Viewport.State) => ReactElement) | - | Allows 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. |
Viewport Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-activation-direction | `${'left' | 'right' | ''} ${'down' | 'up' | ''}` | Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes. |
| data-current | - | Applied to the direct child of the viewport when no transitions are present or the new content when it's entering. |
| data-instant | 'dismiss' | 'focus' | Present if animations should be instant. |
| data-previous | - | Applied to the direct child of the viewport that contains the exiting content when transitions are present. |
| data-transitioning | - | Indicates that the viewport is currently transitioning between old and new content. |
Viewport CSS Variables:
| Variable | Type | Description |
|---|---|---|
--popup-height | `` | The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content. |
--popup-width | `` | The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content. |
Viewport.Props
Re-export of Viewport props.
Viewport.State
type PreviewCardViewportState = {
/** The activation direction of the transitioned content. */
activationDirection: string | undefined;
/** Whether the viewport is currently transitioning between contents. */
transitioning: boolean;
/** Present if animations should be instant. */
instant: 'dismiss' | 'focus' | undefined;
};createHandle
Creates a new handle to connect a PreviewCard.Root with detached PreviewCard.Trigger components.
Return Value:
type ReturnValue = PreviewCard.Handle<Payload>;Handle
Controls a PreviewCard imperatively and associates detached PreviewCard.Trigger components with
a PreviewCard.Root. Create one with PreviewCard.createHandle() and pass it to the handle
prop of the root and of any triggers rendered outside of it.
The imperative methods take effect only while a root using this handle is mounted; calls made before a root attaches (or after it unmounts) are ignored.
Properties:
| Property | Type | Modifiers | Description |
|---|---|---|---|
| isOpen | boolean | readonly | Whether the preview card is currently open. Returns false while no root is attached to the handle. |
Methods:
function open(triggerId: string): void;Opens the preview card and associates it with the trigger with the given id.
This method should only be called in an event handler or an effect (not during rendering).
function close(): void;Closes the preview card.
This method should only be called in an event handler or an effect (not during rendering).
External Types
PayloadChildRenderFunction
type PayloadChildRenderFunction = (arg: { payload: unknown | undefined }) => ReactNode;preventUnmountOnClose
type preventUnmountOnClose = () => void;Side
type Side = 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';Align
type Align = 'start' | 'center' | 'end';OffsetFunction
type OffsetFunction = (data: {
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
align: 'start' | 'center' | 'end';
anchor: { width: number; height: number };
positioner: { width: number; height: number };
}) => number;Export Groups
PreviewCard.Root:PreviewCard.Root,PreviewCard.Root.State,PreviewCard.Root.Props,PreviewCard.Root.Actions,PreviewCard.Root.ChangeEventReason,PreviewCard.Root.ChangeEventDetailsPreviewCard.Portal:PreviewCard.Portal,PreviewCard.Portal.State,PreviewCard.Portal.PropsPreviewCard.Trigger:PreviewCard.Trigger,PreviewCard.Trigger.State,PreviewCard.Trigger.PropsPreviewCard.Positioner:PreviewCard.Positioner,PreviewCard.Positioner.State,PreviewCard.Positioner.PropsPreviewCard.Popup:PreviewCard.Popup,PreviewCard.Popup.State,PreviewCard.Popup.PropsPreviewCard.Arrow:PreviewCard.Arrow,PreviewCard.Arrow.State,PreviewCard.Arrow.PropsPreviewCard.Backdrop:PreviewCard.Backdrop,PreviewCard.Backdrop.State,PreviewCard.Backdrop.PropsPreviewCard.Viewport:PreviewCard.Viewport,PreviewCard.Viewport.Props,PreviewCard.Viewport.StatePreviewCard.createHandlePreviewCard.HandleDefault:PreviewCardRootState,PreviewCardRootProps,PreviewCardRootActions,PreviewCardRootChangeEventReason,PreviewCardRootChangeEventDetails,PreviewCardTriggerState,PreviewCardTriggerProps,PreviewCardPortalState,PreviewCardPortalProps,PreviewCardPositionerState,PreviewCardPositionerProps,PreviewCardPopupState,PreviewCardPopupProps,PreviewCardArrowState,PreviewCardArrowProps,PreviewCardViewportState,PreviewCardViewportProps,PreviewCardBackdropState,PreviewCardBackdropProps
Canonical Types
Maps Canonical: Alias — Use Canonical when its namespace is already imported; otherwise use Alias.
PreviewCard.Root.State:PreviewCardRootStatePreviewCard.Root.Props:PreviewCardRootPropsPreviewCard.Root.Actions:PreviewCardRootActionsPreviewCard.Root.ChangeEventReason:PreviewCardRootChangeEventReasonPreviewCard.Root.ChangeEventDetails:PreviewCardRootChangeEventDetailsPreviewCard.Portal.State:PreviewCardPortalStatePreviewCard.Portal.Props:PreviewCardPortalPropsPreviewCard.Trigger.State:PreviewCardTriggerStatePreviewCard.Trigger.Props:PreviewCardTriggerPropsPreviewCard.Positioner.State:PreviewCardPositionerStatePreviewCard.Positioner.Props:PreviewCardPositionerPropsPreviewCard.Popup.State:PreviewCardPopupStatePreviewCard.Popup.Props:PreviewCardPopupPropsPreviewCard.Arrow.State:PreviewCardArrowStatePreviewCard.Arrow.Props:PreviewCardArrowPropsPreviewCard.Backdrop.State:PreviewCardBackdropStatePreviewCard.Backdrop.Props:PreviewCardBackdropPropsPreviewCard.Viewport.Props:PreviewCardViewportPropsPreviewCard.Viewport.State:PreviewCardViewportState