)
}
// By default, the TLShape type's meta property is { [key: string]: any }, but we can type it
// by unioning the type with a new type that has a meta property of our choosing.
type ShapeWithMyMeta = TLShape & { meta: { label: string } }
export const ShapeLabelUiWithHelper = track(function ShapeLabelUiWithHelper() {
const editor = useEditor()
const onlySelectedShape = editor.onlySelectedShape as ShapeWithMyMeta | null
if (!onlySelectedShape) {
return null
}
function onChange(e: React.ChangeEvent) {
if (onlySelectedShape) {
const { id, type, meta } = onlySelectedShape
editor.updateShapes([
{ id, type, meta: { ...meta, label: e.currentTarget.value } },
])
}
}
return (