MCPcopy Create free account
hub / github.com/emwalker/digraph / TextInput

Function TextInput

client/src/components/ui/SearchBox/TextInput/index.tsx:41–79  ·  view source on GitHub ↗
({ handleReturn, queryInfo }: Props)

Source from the content-addressed store, hash-verified

39}
40
41const TextInput = ({ handleReturn, queryInfo }: Props) => {
42 const [editorState, setEditorState] = useState(stateFor(queryInfo))
43 const [mentionListOpen, setMentionListOpen] = useState(false)
44 const [hasFocus, setHasFocus] = useState(false)
45 const editor = useRef(null)
46
47 const wrappedHandleReturn = useCallback((event: KeyboardEvent, nextEditorState: EditorState) => {
48 if (!mentionListOpen) {
49 handleReturn(event, nextEditorState)
50 return 'handled'
51 }
52 return 'not-handled'
53 }, [mentionListOpen])
54
55 const onFocus = useCallback(() => setHasFocus(true), [setHasFocus])
56 const onBlur = useCallback(() => setHasFocus(false), [setHasFocus])
57 const focus = hasFocus ? 'focus' : ''
58
59 return (
60 <div className={`textInputTextInput form-control ${focus}`}>
61 <Editor
62 ref={editor}
63 editorState={editorState}
64 handleReturn={wrappedHandleReturn}
65 onBlur={onBlur}
66 onChange={setEditorState}
67 onFocus={onFocus}
68 placeholder="Search"
69 plugins={plugins}
70 stripPastedStyles
71 />
72 <TopicSuggestions
73 Suggestions={MentionSuggestions}
74 setMentionListOpen={setMentionListOpen}
75 isOpen={mentionListOpen}
76 />
77 </div>
78 )
79}
80
81export default TextInput

Callers

nothing calls this directly

Calls 1

stateForFunction · 0.85

Tested by

no test coverage detected