Custom canvas components
Replace tldraw's on-canvas components, such as the background, with your own.
import { Tldraw, TLEditorComponents } from 'tldraw'
import 'tldraw/tldraw.css'
// There's a guide at the bottom of this file!
// [1]
const components: TLEditorComponents = {
Background: () => {
return <div style={{ position: 'absolute', inset: 0, backgroundColor: '#f0f8ff' }} />
},
}
export default function CustomComponentsExample() {
return (
<div className="tldraw__editor">
<Tldraw persistenceKey="custom-components-example" components={components} />
</div>
)
}
/*
The `components` prop replaces the background, grid, cursors, shape indicators, and more. See
`TLEditorComponents` for the full list.
[1]
Define the components object outside the React component so it's a stable reference. Here we
replace the `Background` component with a plain div in a light blue color. Passing `null` for a
component hides it entirely.
*/
tldraw's on-canvas UI is built from replaceable React components: the background, grid, cursors, shape indicators, and more. Pass your own via the components prop, or pass null to hide one. This example replaces the Background component with a light blue div. See TLEditorComponents for the full list of slots.
Is this page helpful?
Prev
Contextual toolbarNext
Custom grid