| 21 | |
| 22 | @observer |
| 23 | export class EditBox extends React.Component<EditBoxProps, EditBoxState> { |
| 24 | editTextArea: React.RefObject<HTMLTextAreaElement> |
| 25 | inputBox: React.RefObject<HTMLInputElement> |
| 26 | |
| 27 | constructor(props: EditBoxProps) { |
| 28 | super(props) |
| 29 | const editBoxData = this.props.editBoxData |
| 30 | this.editTextArea = React.createRef() |
| 31 | this.inputBox = React.createRef() |
| 32 | |
| 33 | this.state = { |
| 34 | userInput: editBoxData.contents, // Get current edit value |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | render() { |
| 39 | const { userInput } = this.state |
| 40 | const { editorX, editorY, editBoxData, selection } = this.props |
| 41 | const { x, y } = editBoxData |
| 42 | |
| 43 | const hidden = selection.isHidden |
| 44 | const positionStyles: React.CSSProperties = { |
| 45 | position: 'absolute', |
| 46 | left: x + editorX - 1 + 'px', |
| 47 | top: y + editorY + 'px', |
| 48 | opacity: hidden ? 0 : 1, |
| 49 | } |
| 50 | |
| 51 | if (editBoxData.node.layout.boxType === NodeBoxType.STRING) { |
| 52 | return ( |
| 53 | <div style={positionStyles}> |
| 54 | <div className="edit-box edit-box-string"> |
| 55 | <textarea |
| 56 | ref={this.editTextArea} |
| 57 | autoFocus |
| 58 | defaultValue={userInput} |
| 59 | onChange={this.onChange} |
| 60 | onKeyDown={this.onKeyDown} |
| 61 | /> |
| 62 | </div> |
| 63 | </div> |
| 64 | ) |
| 65 | } |
| 66 | |
| 67 | return ( |
| 68 | <div style={positionStyles}> |
| 69 | <div className="edit-box"> |
| 70 | <input |
| 71 | ref={this.inputBox} |
| 72 | autoFocus |
| 73 | type="text" |
| 74 | value={userInput} |
| 75 | onChange={this.onChange} |
| 76 | onKeyDown={this.onKeyDown} |
| 77 | /> |
| 78 | </div> |
| 79 | </div> |
| 80 | ) |
nothing calls this directly
no test coverage detected