Skip to content

Group

A Group item is a container that holds other items together on the canvas. Items inside a group move, rotate, and scale as one unit. Groups can be nested inside other groups.

Type Definition

ts
type GroupItemType = BaseItem & {
  type: "Group"
  itemProps: {
    isPermanent: boolean
    childPositions: [
      string,
      {
        x: number
        y: number
        rotation: number
        width: number
        height: number | undefined
        fontSize?: number
        type: string
      },
    ][]
  }
}

Properties

Base Properties

Inherited from all item types. See Common Properties.

PropertyTypeDescription
idstringUnique identifier.
type"Group"Always "Group" for this item type.
xnumberX position of the group on the canvas.
ynumberY position of the group on the canvas.
widthnumberWidth of the group bounding box.
heightnumberHeight of the group bounding box.
rotationnumberRotation in degrees. Optional.
opacitynumberOpacity from 0 to 1. Optional.
lockedbooleanPrevents selection and movement. Optional.
groupIdstringID of a parent group (for nested groups). Optional.

itemProps

PropertyTypeDescription
isPermanentbooleanWhen true, the group persists when the user clicks elsewhere. When false, clicking outside the group dissolves it back to individual items.
childPositions[string, ChildPosition][]Array of [childId, position] tuples storing each child's local transform relative to the group.

ChildPosition

PropertyTypeDescription
xnumberX offset relative to the group origin.
ynumberY offset relative to the group origin.
rotationnumberChild's rotation relative to the group.
widthnumberChild width.
heightnumber | undefinedChild height (undefined for items where height is derived, e.g. auto-height text).
fontSizenumberFont size — only present when the child is a Text item. Optional.
typestringThe child item's type string (e.g. "Text", "Image", "Shape").

Creating a Group

Groups are created automatically when you select multiple items and group them via the keyboard shortcut (Cmd+G) or programmatically using useGroup.

tsx
const { createGroup } = useGroup()

// Mark an existing group as permanent
createGroup(groupItem)

Ungrouping

tsx
const { unGroup } = useGroup()

// Remove the permanent flag so the group can be dissolved
unGroup(groupItem)

Use Cmd+Shift+G in the Studio to ungroup items interactively.

Notes

  • A group's bounding box (x, y, width, height) is calculated from the rotated bounds of all its children at the time of creation.
  • Child items store their groupId referencing the parent group's id.
  • childPositions preserves each child's absolute position at group-creation time and is used to restore positions when ungrouping.
  • Setting isPermanent: true keeps the group intact when the user clicks outside it. When isPermanent is false, clicking elsewhere on the canvas dissolves the group and reverts its children to individual items.

Released under a proprietary license.