Custom elements
THIS PAGE IS ABOUT VERY EXPERIMENTATION FEATURES OF POLOTNO!
Please use it carefully. Watch changelog for any changes!
By design polotno
support three main types of elements: text
, image
and svg
.
In some cases you may want to create your own custom elements.
#
How to create custom shapes with Polotno?As the demonstration we will create a custom star
element.
Demo: https://codesandbox.io/s/github/lavrton/polotno-site/tree/source/examples/polotno-custom-element
Creating new elements consists of three main steps.
#
1. Create model for your elementFirst we need to define additional attributes for our new element. Very basic attributes such as id
, x
, y
, rotation
, all filters attributes, etc are already defined. So we just need to define additional data and default values.
Now polotno
store knows that we can define star
model.
#
2. Create react component for new elementThen we need to define how to display our model. In order to do that we need to create react component with react-konva
shapes.
#
3. Create custom top toolbar (optional)Also we can define a custom toolbar to change star properties.