This is an example showing a basic editor with a frame inside a canvas. It has one frame layer.
Try it out: Use your mouse to navigate, pan and zoom the canvas. Click on the blue frame to interact with it: move, resize, and rotate to see the editor in action.
Components
We compose our custom editor using the following components:
Designerto render the editor.DesignerContentas the container for the canvas and frame.DesignerCanvasfor the infinite scrollable canvas.DesignerFrameto render the frame. By default, it's a 1024x1024px square.
import {
Designer,
DesignerCanvas,
DesignerContent,
DesignerFrame,
} from "@shadcn/designer"
function CustomDesigner() {
return (
<Designer className="h-svh">
<DesignerContent>
<DesignerCanvas>
<DesignerFrame />
</DesignerCanvas>
</DesignerContent>
</Designer>
)
}You can create anything from simple editors with just a frame to complex editors with headers, panels, toolbars, and more advanced features.
Layer Types
The Designer includes three built-in layer types: text, image, and frame.
You can add custom layer types and remove the default ones using the layerTypes prop.
import { DEFAULT_LAYER_TYPES, type LayerType } from "@shadcn/designer"
// Extends the default layer types with a custom video layer type.
const CUSTOM_LAYER_TYPES = [
...DEFAULT_LAYER_TYPES,
{
id: "video",
name: "Video",
// ... other props
},
] satisfies LayerType[]
function CustomDesigner() {
return (
<Designer layerTypes={CUSTOM_LAYER_TYPES}>
<DesignerContent />
</Designer>
)
}Working with Layers
The Designer component accepts a defaultLayers prop. It's an array of layers.
Use the defaultLayers prop to add default layers to the editor for example, layers loaded from a database.
function CustomDesigner() {
return (
<Designer
defaultLayers={[
{
id: "1",
type: "text",
name: "Layer 1",
value: "",
cssVars: {
"--background-color": "#54a0ff",
"--width": "400px",
"--height": "400px",
"--translate-x": "50px",
"--translate-y": "50px",
},
},
]}
>
<DesignerContent>
<DesignerCanvas>
<DesignerFrame />
</DesignerCanvas>
</DesignerContent>
</Designer>
)
}Controlled Mode
The Designer component can be used in controlled mode by passing a layers and onLayersChange props.
function CustomDesigner() {
const [layers, setLayers] = useState<Layer[]>([])
return (
<Designer layers={layers} onLayersChange={setLayers}>
<DesignerContent>
<DesignerCanvas>
<DesignerFrame />
</DesignerCanvas>
</DesignerContent>
</Designer>
)
}