One preview shared by linked records
Detached triggers pass typed project data to a shared popup. Moving between links updates the content and viewport without mounting separate cards.
Keyboard
- Each project is an ordinary link in document order.
- Enter follows the focused project destination; Escape dismisses the visual preview.
- No project action is available only in the preview.
States covered
- Typed trigger payloads
- Detached multiple triggers
- Shared content transition
- Different content heights
- Complete destination content
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-preview-linked-records.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import { useState } from 'react';
import { Layers } from 'lucide-react';
import { PreviewCard, PreviewCardTrigger, PreviewCardPopup, createPreviewCardHandle } from '@bld8/ui/preview-card';
type Project = { id: string; name: string; owner: string; summary: string; status: string };
const projects: Project[] = [
{ id: 'atlas', name: 'Atlas', owner: 'Maya Chen', summary: 'Shared components, interaction guidance and editable source examples.', status: 'In review' },
{ id: 'harbour', name: 'Harbour', owner: 'Eli Morgan', summary: 'An internal record directory with saved filters, ownership review and clear recovery for failed saves. The next review focuses on narrow screens.', status: 'In progress' },
];
export function LinkedRecordPreviewExample() {
const [handle] = useState(() => createPreviewCardHandle<Project>());
return <div style={{ width: '100%', display: 'grid', gap: 24 }}>
<p style={{ margin: 0 }}>Related projects: {projects.map((project, index) => <span key={project.id}>{index > 0 && ' and '}<PreviewCardTrigger handle={handle} payload={project} href={'#preview-project-' + project.id} delay={250}>{project.name}</PreviewCardTrigger></span>)}.</p>
<PreviewCard handle={handle}>{({ payload }) => <PreviewCardPopup className="record-preview">{payload && <>
<div className="bui-preview-heading"><span className="bui-preview-avatar"><Layers size={18} aria-hidden="true" /></span><div><p className="bui-preview-title">{payload.name}</p><p className="bui-preview-meta">{payload.status}</p></div></div>
<p className="bui-preview-description">{payload.summary}</p><div className="bui-preview-facts"><span>Owner: {payload.owner}</span></div>
</>}</PreviewCardPopup>}</PreviewCard>
{projects.map(project => <section key={project.id} id={'preview-project-' + project.id}><strong>{project.name}</strong><p className="bui-hint">{project.status} · Owner: {project.owner}. {project.summary}</p></section>)}
</div>;
}