Skip to main content

HTML5 canvas Group Tutorial

To create a group of shapes with Konva, we can instantiate a Konva.Group() object.

For full list of properties and methods, see the Group API Reference.

import Konva from 'konva';

const stage = new Konva.Stage({
  container: 'container',
  width: window.innerWidth,
  height: window.innerHeight
});

const layer = new Konva.Layer();
stage.add(layer);

const group = new Konva.Group({
  x: 50,
  y: 50,
  draggable: true
});

const circle = new Konva.Circle({
  x: 0,
  y: 0,
  radius: 30,
  fill: 'red'
});

const rect = new Konva.Rect({
  x: 20,
  y: 20,
  width: 100,
  height: 50,
  fill: 'green'
});

group.add(circle);
group.add(rect);
layer.add(group);