PreviewCard
PreviewCard composes Base UI’s preview card primitives for rich link previews that appear on hover or focus from a consumer-owned trigger element.
import { Button, PreviewCard, Skeleton, View } from "density-base-ui";
export default function PreviewCardExample() {
return (
<PreviewCard
trigger={<Button>Preview Density</Button>}
title="Density"
subtitle="A quiet, durable interface system for focused product work."
>
<View padding={false} style={{ marginTop: "0.5rem", width: "16rem" }}>
<Skeleton style={{ width: "5rem" }} />
<Skeleton style={{ width: "100%" }} />
</View>
</PreviewCard>
);
}Dismiss control
Set dismissable to show a Close control. Handle onDismiss to remove the preview from its owner.
import { Button, PreviewCard, Skeleton } from "density-base-ui";
export default function PreviewCardDismissableExample() {
return (
<PreviewCard
dismissable
onDismiss={() => undefined}
trigger={<Button>Preview Density</Button>}
title="Density"
>
<Skeleton style={{ height: "3rem", width: "12rem" }} />
</PreviewCard>
);
}Padding
NonePadding enabled
import { PreviewCard, Skeleton, View, Label } from "density-base-ui";
export default function PreviewCardPaddingExample() {
return (
<View orientation="horizontal" padding={false} wrap>
<PreviewCard padding={false} trigger={<Label>None</Label>}>
<Skeleton style={{ width: "10rem" }} />
</PreviewCard>
<PreviewCard
trigger={<Label>Padding enabled</Label>}
title="Padding enabled"
subtitle="Preview card content with padding."
>
<Skeleton style={{ width: "10rem" }} />
</PreviewCard>
</View>
);
}| Prop | Values | Required | Default | Behavior | Description |
|---|---|---|---|---|---|
children | (React.ReactNode | import("@base-ui/react/utils/popups/popupStoreUtils").PayloadChildRenderFunction<unknown>) & React.ReactNode | Not required | — | — | 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. |
dismissable | false, true | Not required | false | — | — |
onDismiss | () => void | Not required | — | — | — |
padding | false, true | Not required | true | Attribute: data-dn-padding | — |
subtitle | React.ReactNode | Not required | — | — | — |
title | React.ReactNode | Not required | — | — | — |
trigger | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Required | — | — | — |
This component also accepts props from native APIs. They are passed through and intentionally kept out of this focused Density API table.