import { TLFrameShape, TLShapeId, useEditor, useIsEditing, useValue } from '@tldraw/editor' import { memo, useEffect, useRef } from 'react' import { getFrameHeadingSide, getFrameHeadingTranslation } from '../frameHelpers' import { FrameLabelInput } from './FrameLabelInput' export const FrameHeading = memo(function FrameHeading({ id, name, width, height, fill, stroke, color, offsetX, showColors, }: { id: TLShapeId name: string width: number height: number fill: string stroke: string color: string offsetX: number showColors: boolean }) { const editor = useEditor() const { side, translation } = useValue( 'shape rotation', () => { const shape = editor.getShape(id) if (!shape) { // meh return { side: 0, translation: 'translate(0, 0)', } } const labelSide = getFrameHeadingSide(editor, shape) return { side: labelSide, translation: getFrameHeadingTranslation(shape, labelSide, false), } }, [editor, offsetX, id] ) const rInput = useRef(null) const isEditing = useIsEditing(id) useEffect(() => { const el = rInput.current if (el && isEditing) { // On iOS, we must focus here el.focus() el.select() } }, [rInput, isEditing]) return (
) })