Preview Card

Previews a link's target on hover or focus.

Source
$npx @dinachi/cli@latest add preview-card

Dinachi UI is heavily inspired by Base UI and provides accessible, composable components styled with Tailwind CSS.

delay
closeDelay

Usage

import {
  PreviewCard,
  PreviewCardContent,
  PreviewCardTrigger,
} from "@/components/ui/preview-card"

export function ProfileLink() {
  return (
    <PreviewCard>
      <PreviewCardTrigger href="/people/ada">Ada Lovelace</PreviewCardTrigger>
      <PreviewCardContent>
        <p className="text-sm">Mathematician. Wrote the first published program.</p>
      </PreviewCardContent>
    </PreviewCard>
  )
}

Examples

Dinachi UI is heavily inspired by Base UI and provides accessible, composable components styled with Tailwind CSS.

Links in a paragraph that preview on hover.
import { PreviewCard, PreviewCardTrigger, PreviewCardContent } from '@/components/ui/preview-card';

export function Example() {
  return (
    <p className="text-sm leading-relaxed text-foreground max-w-md">
      Dinachi UI is heavily inspired by{' '}
      <PreviewCard>
        <PreviewCardTrigger href="#">
          Base UI
        </PreviewCardTrigger>
        <PreviewCardContent>
          <div className="space-y-2">
            <h4 className="text-sm font-semibold">Base UI</h4>
            <p className="text-sm text-muted-foreground">
              Unstyled React components and hooks from the creators of Material UI. Ship accessible interfaces without compromising creative freedom.
            </p>
          </div>
        </PreviewCardContent>
      </PreviewCard>
      {' '}and provides accessible, composable components styled with{' '}
      <PreviewCard>
        <PreviewCardTrigger href="#">
          Tailwind CSS
        </PreviewCardTrigger>
        <PreviewCardContent>
          <div className="space-y-2">
            <h4 className="text-sm font-semibold">Tailwind CSS</h4>
            <p className="text-sm text-muted-foreground">
              A utility-first CSS framework for rapidly building custom designs without ever leaving your HTML.
            </p>
          </div>
        </PreviewCardContent>
      </PreviewCard>
      .
    </p>
  );
}

Notes

Content only

For reading only. Touch screens have no hover, so keep essential content on the linked page and put controls in a Popover.

One card, many triggers

Pass a createPreviewCardHandle() handle to the PreviewCard and each PreviewCardTrigger, and give each trigger a payload; the children function receives it. Triggers outside the PreviewCard are not tied to its agent entry, so the agent sees them as plain links.

API

openboolean
Controlled open state.
defaultOpenboolean = false
Starting state when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs for people and agents. details.cancel() refuses the change.
onOpenChangeComplete(open) => void
Runs once the open or close animation ends.
handlePreviewCardHandle
Links the card to triggers elsewhere. Make one with createPreviewCardHandle().
childrenReactNode | ({ payload }) => ReactNode
A function receives the opening trigger's payload.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as popover.

Reads

label

The trigger's text.

open

Whether the card is showing.

Actions

open()

Opens the card. Only while closed.

close()

Closes the card. Only while open.

Once open, the trigger stays the control and the card is read as content. An agent's change runs through onOpenChange. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused.

await agent.act({
  steps: [{ ref: "Base UI", action: "open" }],
})

Accessibility

  • The trigger is a plain link; it works if the card never opens.
  • Opens on hover and on keyboard focus of the trigger.