About
Responsive React navigation dock with paginated groups, accessible tooltips, and active section tracking.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Dock to your project and fits it to your theme.
Code
How Dock is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client";
import { useEffect, useRef, useState } from 'react';
import { Dock, type DockItem } from '@/components/ui/dock';
const paths = {
home: <><path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8" /><path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" /></>,
search: <><path d="m21 21-4.34-4.34" /><circle cx="11" cy="11" r="8" /></>,
projects: <path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" />,
messages: <path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719" />,
profile: <><circle cx="12" cy="8" r="5" /><path d="M20 21a8 8 0 0 0-16 0" /></>,
settings: <><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" /><circle cx="12" cy="12" r="3" /></>,
save: <><path d="M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" /><path d="M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" /><path d="M7 3v4a1 1 0 0 0 1 1h7" /></>,
copy: <><rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /></>,
download: <><path d="M12 15V3" /><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="m7 10 5 5 5-5" /></>,
printer: <><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" /><path d="M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6" /><rect x="6" y="14" width="12" height="8" rx="1" /></>,
help: <><circle cx="12" cy="12" r="10" /><path d="M9 9.5a3 2.5 0 016 0c0 2-2 2-3 3.5" /><path d="M12 17h.01" /></>,
moon: <path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" />,
sun: <><circle cx="12" cy="12" r="4" /><path d="M12 2v2" /><path d="M12 20v2" /><path d="m4.93 4.93 1.41 1.41" /><path d="m17.66 17.66 1.41 1.41" /><path d="M2 12h2" /><path d="M20 12h2" /><path d="m6.34 17.66-1.41 1.41" /><path d="m19.07 4.93-1.41 1.41" /></>,
'save-check': <><path d="M12.5 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h10.2a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4v4.35" /><path d="m16 19 2 2 4-4" /><path d="M17 15.13V14a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" /><path d="M7 3v4a1 1 0 0 0 1 1h7" /></>,
'copy-check': <><rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /><path d="m12 15 2 2 4-4" /></>,
error: <><path d="M18 6 6 18" /><path d="m6 6 12 12" /></>,
};
function DemoIcon({ name }: { name: keyof typeof paths }) {
return <svg data-icon={name} width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">{paths[name]}</svg>;
}
type ActionState = 'idle' | 'pending' | 'success' | 'error';
export default function DockDemo() {
const [dark, setDark] = useState(false);
const [active, setActive] = useState('home');
const [message, setMessage] = useState('Choose a tool. Use the arrows to see more.');
const [save, setSave] = useState<ActionState>('idle');
const [copy, setCopy] = useState<ActionState>('idle');
const saveTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
const mounted = useRef(false);
const copying = useRef(false);
useEffect(() => {
mounted.current = true;
return () => {
mounted.current = false;
clearTimeout(saveTimer.current);
clearTimeout(copyTimer.current);
};
}, []);
const items: DockItem[] = [
...(['home', 'search', 'projects', 'messages', 'profile', 'settings'] as const).map(id => ({
id,
label: id[0].toUpperCase() + id.slice(1),
icon: <DemoIcon name={id} />,
onClick: () => {
setActive(id);
setMessage(`${id[0].toUpperCase() + id.slice(1)} selected.`);
},
})),
{
id: 'save', label: { idle: 'Save draft', pending: 'Saving draft', success: 'Saved locally', error: 'Save failed' }[save],
icon: <DemoIcon name={save === 'success' ? 'save-check' : save === 'error' ? 'error' : 'save'} />,
loading: save === 'pending',
onClick: () => {
clearTimeout(saveTimer.current);
setSave('pending');
saveTimer.current = setTimeout(() => {
try {
localStorage.setItem('react-dock-demo-draft', JSON.stringify({ active, savedAt: new Date().toISOString() }));
setSave('success'); setMessage('Demo draft saved in this browser, not on a server.');
} catch {
setSave('error'); setMessage('This browser did not allow local storage.');
}
saveTimer.current = setTimeout(() => setSave('idle'), 1800);
}, 700);
},
},
{
id: 'copy', label: { idle: 'Copy link', pending: 'Copying link', success: 'Link copied', error: 'Copy failed' }[copy],
icon: <DemoIcon name={copy === 'success' ? 'copy-check' : copy === 'error' ? 'error' : 'copy'} />,
onClick: async () => {
if (copying.current) return;
if (copy === 'success') {
clearTimeout(copyTimer.current);
copyTimer.current = setTimeout(() => setCopy('idle'), 1800);
return;
}
copying.current = true;
clearTimeout(copyTimer.current); setCopy('pending');
try {
await navigator.clipboard.writeText(window.location.href);
if (!mounted.current) return;
setCopy('success'); setMessage('Link copied to your clipboard.');
} catch {
if (!mounted.current) return;
setCopy('error'); setMessage('Clipboard access was denied or is unavailable.');
} finally { copying.current = false; }
copyTimer.current = setTimeout(() => setCopy('idle'), 1800);
},
},
{
id: 'download', label: 'Download', icon: <DemoIcon name="download" />,
onClick: () => setMessage('Download is a demo action. No file was downloaded.'),
},
{ id: 'print', label: 'Print', icon: <DemoIcon name="printer" />, onClick: () => setMessage('Print is a demo action. No print dialog was opened.') },
{ id: 'help', label: 'Help', icon: <DemoIcon name="help" />, onClick: () => setMessage('Hover or focus for tooltips. Use the arrows for more tools. Save stores a demo draft locally; Copy uses your clipboard.') },
{ id: 'theme', label: dark ? 'Light mode' : 'Dark mode', icon: <DemoIcon name={dark ? 'sun' : 'moon'} />, onClick: () => setDark(value => !value) },
];
return (
<div style={{ minHeight: 200, width: '100%', maxWidth: 560, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24, boxSizing: 'border-box', background: dark ? '#171b18' : '#e7ede4', color: dark ? '#edf2eb' : '#202520', borderRadius: 24 }}>
<span role="status" style={{ position: 'absolute', width: 1, height: 1, padding: 0, margin: -1, overflow: 'hidden', clipPath: 'inset(50%)', whiteSpace: 'nowrap', border: 0 }}>{message}</span>
<Dock items={items} activeId={active} maxVisibleItems={6} sectionNavigation={false} ariaLabel="Demo tools"
style={{ position: 'relative', inset: 'auto', ...(dark ? { '--rd-surface': '#252b26', '--rd-foreground': '#edf2eb', '--rd-border': '#424b42', '--rd-hover': '#343d34', '--rd-active': '#404e3e' } : {}) }} />
</div>
);
}
