@objectifthunes/whiteboard
STORE & HOOKS

Helpers

usePanelRect, belowPanel, snapToWhiteboardGrid, WHITEBOARD_GRID, and cn.


SOURCE
import {
  usePanelRect,
  belowPanel,
  snapToWhiteboardGrid,
  WHITEBOARD_GRID,
  cn,
} from '@objectifthunes/whiteboard'

// 1. Track a panel's live rect.
const settingsRect = usePanelRect({ x: 40, y: 40 })

<FloatingPanel title="Settings" defaultPosition={{ x: 40, y: 40 }} trackRect={settingsRect} />

// 2. Stack another panel underneath it.
<FloatingPanel title="Layers" defaultPosition={belowPanel(settingsRect.current)} />

// 3. Snap any number to the grid.
const x = snapToWhiteboardGrid(rawX)  // → multiple of WHITEBOARD_GRID (20)

// 4. Tiny classnames helper.
className={cn('base', isActive && 'is-active', extra)}
NOTES

usePanelRect returns a stable ref. Pass it as trackRecton a FloatingPanel and it stays in sync with the panel's rendered { x, y, width, height }.

belowPanel(rect, gap?) defaults to one grid-cell gap. WHITEBOARD_GRID is 20.

cn is a one-liner: (string | false | null | undefined)[] → string. Filters out falsies and joins with a space.