TLBaseShape
See source codeTable of contents
Base interface for all shapes in tldraw.
This interface defines the common properties that all shapes share, regardless of their specific type. Every default shape extends this base with additional type-specific properties.
Custom shapes should be defined by augmenting the TLGlobalShapePropsMap type and getting the shape type from the TLShape type.
interface TLBaseShape<Type extends string, Props extends object> {}Example
// Define a default shape type
interface TLArrowShape
extends TLBaseShape<
'arrow',
{
kind: TLArrowShapeKind
labelColor: TLDefaultColorStyle
color: TLDefaultColorStyle
fill: TLDefaultFillStyle
dash: TLDefaultDashStyle
size: TLDefaultSizeStyle
arrowheadStart: TLArrowShapeArrowheadStyle
arrowheadEnd: TLArrowShapeArrowheadStyle
font: TLDefaultFontStyle
start: VecModel
end: VecModel
bend: number
richText: TLRichText
labelPosition: number
scale: number
elbowMidPoint: number
}
> {}
// Create a shape instance
const arrowShape: TLArrowShape = {
id: 'shape:abc123',
typeName: 'shape',
type: 'arrow',
x: 100,
y: 200,
rotation: 0,
index: 'a1',
parentId: 'page:main',
isLocked: false,
opacity: 1,
props: {
kind: 'arc',
start: { x: 0, y: 0 },
end: { x: 100, y: 100 },
// ... other props
},
meta: {},
}Properties
id
readonly
readonly id: TLShapeIdindex
index: IndexKeyisLocked
isLocked: booleanmeta
meta: JsonObjectopacity
opacity: TLOpacityTypeparentId
parentId: TLParentIdprops
props: Propsrotation
rotation: numbertype
type: TypetypeName
readonly
readonly typeName: 'shape'x
x: numbery
y: numberPrev
TLBaseBindingNext
TLBookmarkShapeProps