Skip to main content

Style Konva Transformer

You can adjust styles of Konva.Transformer for your web app. You can change stroke, size and fill of all anchors. Also you can change stroke color and size of border.

Also take a look into Complex Transformer Styling for fine tuning.

import Konva from 'konva';

const width = window.innerWidth;
const height = window.innerHeight;

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

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

const rect = new Konva.Rect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'yellow',
stroke: 'black',
draggable: true,
});
layer.add(rect);

const tr = new Konva.Transformer({
nodes: [rect],
// add border

borderStroke: '#000',
borderStrokeWidth: 3,
// add anchors

anchorFill: '#fff',
anchorStroke: '#000',
anchorStrokeWidth: 2,
anchorSize: 20,
// make all anchors look like circles

anchorCornerRadius: 50,
});
layer.add(tr);


</rewritten_file>