Components
Live cursors
NativeNamed collaborator pointers over a shared area, with normalized positions and theme colors.
Ideas for the studio
3 people here · demoSpace
More room
for messy ideas.
Rituals
Friday
show & tell.
Move your pointer over the board.
- Maya is here
- Alex is here
- Sam is here
Installation
npx nook-ui@latest add live-cursorsPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Live cursors" component to this project, exactly as Nook ships it.
Named collaborator pointers over a shared area, with normalized positions and theme colors.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add live-cursors`. It writes `components/ui/live-cursors.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/live-cursors.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { LiveCursors, useLocalCursor, type LiveCursor, type LocalCursorPosition } from "@/components/ui/live-cursors";
import { useReducedMotion } from "@/components/ui/loading";
const collaborators: LiveCursor[] = [
{ id: "maya", name: "Maya", x: 0.22, y: 0.3, color: 1 },
{ id: "alex", name: "Alex", x: 0.66, y: 0.54, color: 3 },
{ id: "sam", name: "Sam", x: 0.42, y: 0.77, color: 5 },
];
export default function LiveCursorsDefault() {
const [cursors, setCursors] = React.useState(collaborators);
const [local, setLocal] = React.useState<LocalCursorPosition | null>(null);
const area = useLocalCursor({ onChange: setLocal });
const reduced = useReducedMotion();
React.useEffect(() => {
if (reduced) return;
let step = 0;
const motion = getComputedStyle(area.current!).getPropertyValue("--motion-pop").trim();
const interval = Number.parseFloat(motion) * (motion.endsWith("ms") ? 1 : 1000) * 6;
if (!Number.isFinite(interval) || interval <= 0) return;
const timer = window.setInterval(() => {
step++;
setCursors(collaborators.map((cursor, index) => ({ ...cursor, x: cursor.x + Math.sin(step * 0.4 + index) * 0.08, y: cursor.y + Math.cos(step * 0.35 + index) * 0.06 })));
}, interval);
return () => window.clearInterval(timer);
}, [reduced, area]);
return <div className="grid w-full gap-4"><div className="flex flex-wrap items-center justify-between gap-2"><h3 className="text-sm font-medium">Ideas for the studio</h3><span className="flex items-center gap-2 text-xs text-muted-foreground"><span className="size-1.5 bg-brand" />3 people here · demo</span></div>
<div ref={area} className="relative min-h-80 overflow-hidden rounded-lg border-(length:--edge) border-(--field-edge) bg-muted/30 p-5">
<div className="grid grid-cols-2 gap-4"><div className="-rotate-3 border-(length:--edge) border-(--surface-edge) bg-chart-2/15 p-4"><p className="text-xs text-muted-foreground">Space</p><p className="mt-3 text-lg font-medium">More room<br />for messy ideas.</p></div><div className="mt-10 rotate-3 border-(length:--edge) border-(--surface-edge) bg-chart-3/15 p-4"><p className="text-xs text-muted-foreground">Rituals</p><p className="mt-3 text-lg font-medium">Friday<br />show & tell.</p></div></div>
<p className="absolute right-5 bottom-4 left-5 font-mono text-xs text-muted-foreground">{local ? `Your pointer: ${local.x.toFixed(2)}, ${local.y.toFixed(2)}` : "Move your pointer over the board."}</p>
<LiveCursors cursors={cursors} />
</div>
</div>;
}
```
API
- `LiveCursors`: An absolute overlay inside a positioned parent. Coordinates are clamped from zero through one.
- `cursors` (`{ id; name; x; y; color?: 1 | 2 | 3 | 4 | 5 }[]`): Collaborators, normalized positions, and chart color numbers.
- `labelPlacement` (`"above" | "below"`, default below): Preferred label position. Labels flip near the edges to stay visible.
- `...props` (`React.HTMLAttributes<HTMLDivElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
- `useLocalCursor`: Returns a ref for the shared area. Broadcasts leading and trailing pointer positions and null on leave.
- `onChange` (`(position: { x; y } | null) => void`): Send normalized coordinates to your own collaboration service.
- `throttleMs` (`number`, default 50): Minimum interval between pointer broadcast windows, in milliseconds.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: A visually hidden list names everyone present. Remote pointer artwork is decorative and cannot block interaction. CSS movement transitions stop with reduced motion. The local cursor hook cancels trailing broadcasts on leave and unmount.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { LiveCursors, useLocalCursor, type LiveCursor, type LocalCursorPosition } from "@/components/ui/live-cursors";
import { useReducedMotion } from "@/components/ui/loading";
const collaborators: LiveCursor[] = [
{ id: "maya", name: "Maya", x: 0.22, y: 0.3, color: 1 },
{ id: "alex", name: "Alex", x: 0.66, y: 0.54, color: 3 },
{ id: "sam", name: "Sam", x: 0.42, y: 0.77, color: 5 },
];
export default function LiveCursorsDefault() {
const [cursors, setCursors] = React.useState(collaborators);
const [local, setLocal] = React.useState<LocalCursorPosition | null>(null);
const area = useLocalCursor({ onChange: setLocal });
const reduced = useReducedMotion();
React.useEffect(() => {
if (reduced) return;
let step = 0;
const motion = getComputedStyle(area.current!).getPropertyValue("--motion-pop").trim();
const interval = Number.parseFloat(motion) * (motion.endsWith("ms") ? 1 : 1000) * 6;
if (!Number.isFinite(interval) || interval <= 0) return;
const timer = window.setInterval(() => {
step++;
setCursors(collaborators.map((cursor, index) => ({ ...cursor, x: cursor.x + Math.sin(step * 0.4 + index) * 0.08, y: cursor.y + Math.cos(step * 0.35 + index) * 0.06 })));
}, interval);
return () => window.clearInterval(timer);
}, [reduced, area]);
return <div className="grid w-full gap-4"><div className="flex flex-wrap items-center justify-between gap-2"><h3 className="text-sm font-medium">Ideas for the studio</h3><span className="flex items-center gap-2 text-xs text-muted-foreground"><span className="size-1.5 bg-brand" />3 people here · demo</span></div>
<div ref={area} className="relative min-h-80 overflow-hidden rounded-lg border-(length:--edge) border-(--field-edge) bg-muted/30 p-5">
<div className="grid grid-cols-2 gap-4"><div className="-rotate-3 border-(length:--edge) border-(--surface-edge) bg-chart-2/15 p-4"><p className="text-xs text-muted-foreground">Space</p><p className="mt-3 text-lg font-medium">More room<br />for messy ideas.</p></div><div className="mt-10 rotate-3 border-(length:--edge) border-(--surface-edge) bg-chart-3/15 p-4"><p className="text-xs text-muted-foreground">Rituals</p><p className="mt-3 text-lg font-medium">Friday<br />show & tell.</p></div></div>
<p className="absolute right-5 bottom-4 left-5 font-mono text-xs text-muted-foreground">{local ? `Your pointer: ${local.x.toFixed(2)}, ${local.y.toFixed(2)}` : "Move your pointer over the board."}</p>
<LiveCursors cursors={cursors} />
</div>
</div>;
}Props
LiveCursors
An absolute overlay inside a positioned parent. Coordinates are clamped from zero through one.
| Prop | Type | Default | Description |
|---|---|---|---|
| cursors | { id; name; x; y; color?: 1 | 2 | 3 | 4 | 5 }[] | – | Collaborators, normalized positions, and chart color numbers. |
| labelPlacement | "above" | "below" | below | Preferred label position. Labels flip near the edges to stay visible. |
| ...props | React.HTMLAttributes<HTMLDivElement> | – | Everything the native element accepts, such as `id`, `aria-*` and event handlers. |
useLocalCursor
Returns a ref for the shared area. Broadcasts leading and trailing pointer positions and null on leave.
| Prop | Type | Default | Description |
|---|---|---|---|
| onChange | (position: { x; y } | null) => void | – | Send normalized coordinates to your own collaboration service. |
| throttleMs | number | 50 | Minimum interval between pointer broadcast windows, in milliseconds. |
Accessibility
A visually hidden list names everyone present. Remote pointer artwork is decorative and cannot block interaction. CSS movement transitions stop with reduced motion. The local cursor hook cancels trailing broadcasts on leave and unmount.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.