Skip to content

ShapeDraw Item

Represents a custom Bezier shape drawn by the user with the shape drawing tool. Unlike Shape items (which use a preset SVG path), ShapeDraw items are created from freehand Bezier strokes drawn directly on the canvas.

Creating a ShapeDraw Item

ShapeDraw items are not created with addItem. Instead, the user draws a shape on the canvas using the shape drawing tool, then calls saveDrawShape() from useDraw to commit it as an item.

tsx
function DrawControls() {
  const { changeDrawMode, setDrawType, saveDrawShape, isDrawMode } = useDraw();

  function startDrawing() {
    setDrawType("shape");
    changeDrawMode("draw");
  }

  return (
    <div>
      <button onClick={startDrawing}>Draw Shape</button>
      {isDrawMode && <button onClick={saveDrawShape}>Save Shape</button>}
    </div>
  );
}

When saveDrawShape() is called, the drawn shape is added to the canvas as a ShapeDraw item. Pressing Enter while in draw mode also saves the shape.

Receiving the Saved Shape

You can receive the saved ShapeDrawItemType via the onSaveDrawShape prop on StudioProvider. This is useful for persisting drawn shapes on your backend.

tsx
<SessionProvider onCreateSession={createSession}>
  <StudioProvider
    onSaveDrawShape={(shape) => {
      console.log("Saved shape:", shape);
      // persist to your backend
    }}
  >
    <Studio />
  </StudioProvider>
</SessionProvider>

Properties

All properties below are passed inside itemProps.

PropertyTypeDescription
verticesnumber[]Flattened array of normalized vertex coordinates [x0, y0, x1, y1, ...]. Required.
controlsnumber[]Flattened array of normalized Bezier control point coordinates.
strokestringStroke color (hex). Required.
strokeWidthnumberStroke thickness in pixels. Required.
fillstringFill color (hex).
cornerRadiusnumberCorner radius applied to the shape.
shadowEnabledbooleanEnable or disable the shadow.
shadowColorstringShadow color.
shadowBlurnumberShadow blur radius.
shadowOffsetXnumberShadow horizontal offset.
shadowOffsetYnumberShadow vertical offset.

Notes

  • vertices and controls are normalized to the item's bounding box (0–1 range), so the shape scales correctly when the item is resized.
  • The drawing tool settings (drawColor, drawStrokeWidth, drawFillColor) from useDraw are applied automatically when the shape is saved.

Released under a proprietary license.