LevelChatDocs
Docs
Whiteboard

Components

Whiteboard

A collaborative sketch surface that renders identically at any size.

Whiteboard is the collaborative canvas — pointer-events draw a stroke locally; on pointer-up the stroke is committed via the SDK and replicated to every other participant. Coordinates are stored normalised (0..1 in both axes) so a drawing made on a 1200×800 surface looks identical on a 600×400 surface.

Install

pnpm add @levelchat/react-components @levelchat/web

Basic usage

import { Whiteboard } from '@levelchat/react-components';

<Whiteboard showClear className="h-[480px] w-full" />

Coordinate model

Every stroke is a sequence of { x: 0..1, y: 0..1 } points + a colour + a width. The canvas renders at whatever CSS size the container provides, and a ResizeObserver keeps the backing-store DPR-correct so strokes stay crisp.

Server caps

The server (not this component) enforces:

  • ≤ 200 strokes / second / author.
  • ≤ 500 points / stroke.
  • ≤ 5000 strokes / board; older strokes age out FIFO.

We trust the server's caps — no double validation in the React layer. The component does filter near-duplicate points client-side (sub-0.002 unit distance) to avoid blowing past the 500-point cap during a slow drag.

Custom toolbar

<Whiteboard
  renderToolbar={(state) => (
    <MyToolbar
      colors={state.color}
      onPick={state.setColor}
      onUndo={state.undo}
      onClear={state.clear}
    />
  )}
/>

Props

PropTypeDefaultNotes
colorsstring[]brand paletteOverride the pen-colour swatches.
widthsnumber[][2, 4, 8, 14]Override the pen-width options.
showClearbooleanfalseShow the host-only Clear button.
renderToolbar(state) => ReactNodeReplace the toolbar entirely.
Whiteboard — LevelChat Docs