2021-06-23 05:37:08 -04:00
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
2021-05-13 06:24:12 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-05-20 05:19:36 -04:00
|
|
|
import { FormControl } from 'react-bootstrap'
|
2021-05-14 04:25:40 -04:00
|
|
|
import useDebounce from '../../../shared/hooks/use-debounce'
|
2021-05-13 06:24:12 -04:00
|
|
|
|
|
|
|
export default function SymbolPaletteSearch({ setInput, inputRef }) {
|
|
|
|
const [localInput, setLocalInput] = useState('')
|
|
|
|
|
|
|
|
// debounce the search input until a typing delay
|
|
|
|
const debouncedLocalInput = useDebounce(localInput, 250)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setInput(debouncedLocalInput)
|
|
|
|
}, [debouncedLocalInput, setInput])
|
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-05-20 05:19:36 -04:00
|
|
|
const inputRefCallback = useCallback(
|
|
|
|
element => {
|
|
|
|
inputRef.current = element
|
|
|
|
},
|
|
|
|
[inputRef]
|
|
|
|
)
|
|
|
|
|
2021-05-13 06:24:12 -04:00
|
|
|
return (
|
2021-05-20 05:19:36 -04:00
|
|
|
<FormControl
|
2021-05-13 06:24:12 -04:00
|
|
|
className="symbol-palette-search"
|
|
|
|
type="search"
|
2021-05-20 05:19:36 -04:00
|
|
|
inputRef={inputRefCallback}
|
2021-05-13 06:24:12 -04:00
|
|
|
id="symbol-palette-input"
|
|
|
|
aria-label="Search"
|
|
|
|
value={localInput}
|
|
|
|
placeholder={t('search') + '…'}
|
|
|
|
onChange={event => {
|
|
|
|
setLocalInput(event.target.value)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
SymbolPaletteSearch.propTypes = {
|
|
|
|
setInput: PropTypes.func.isRequired,
|
|
|
|
inputRef: PropTypes.object.isRequired,
|
|
|
|
}
|