Cursor presence
The other people in an editor: their cursors and selections, always with their name, moving in steps.
import { CursorPresence, editorPresenceTone, EDITOR_PRESENCE_TONES } from "@forgeron/ui";- Léa
- Karim, drawing
- Jo
import { CursorPresence } from "@forgeron/ui";
export default function Default() {
return (
<div
style={{
position: "relative",
width: "100%",
maxWidth: 520,
height: 240,
border: "1px solid var(--line-strong)",
background: "var(--bg-sunk)",
}}
>
<div
style={{
position: "absolute",
left: 200,
top: 90,
width: 140,
height: 70,
border: "1px solid var(--ink-dim)",
background: "var(--bg-raised)",
}}
/>
<CursorPresence
label="People here"
cursors={[
{ id: "lea", name: "Léa", x: 90, y: 60 },
{ id: "karim", name: "Karim", x: 380, y: 170, status: "drawing" },
{
id: "jo",
name: "Jo",
color: "#3ddc84",
x: 330,
y: 110,
selection: { x: 200, y: 90, w: 140, h: 70 },
},
]}
/>
</div>
);
}- Léa
- Karim
import { CursorPresence, type EditorCursor } from "@forgeron/ui";
import { useEffect, useState } from "react";
const paths: Record<string, Array<[number, number]>> = {
lea: [
[60, 50],
[220, 70],
[300, 160],
[120, 190],
],
karim: [
[420, 60],
[360, 200],
[200, 120],
[440, 150],
],
};
export default function Moving() {
const [tick, setTick] = useState(0);
useEffect(() => {
const id = window.setInterval(() => setTick((t) => t + 1), 1200);
return () => window.clearInterval(id);
}, []);
const cursors: EditorCursor[] = Object.entries(paths).map(([id, path]) => {
const [x, y] = path[tick % path.length]!;
return { id, name: id === "lea" ? "Léa" : "Karim", x, y };
});
return (
<div
style={{
position: "relative",
width: "100%",
maxWidth: 520,
height: 240,
border: "1px solid var(--line-strong)",
background: "var(--bg-sunk)",
}}
>
<CursorPresence label="People here" cursors={cursors} />
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the layer for assistive technology: “People here”. |
cursors | { id, name, color?, x?, y?, selection?, status? }[] | — | x, y: the pointer. selection: { x, y, w, h } drawn dashed with the name above. color: #RRGGBB, else a token picked from the id. |
view | { x, y, zoom } | — | Projects world positions; without it they are pixels. |
announce | boolean | true | A list of who is here, read by assistive technology only. |
className | string | — | Extra classes. |