import { ItemListController } from '@/Controllers/ItemList/ItemListController' import { KeyboardKey } from '@/Services/IOService' import { useState, useCallback, KeyboardEventHandler, useRef } from 'react' import SearchOptions from '@/Components/SearchOptions/SearchOptions' import { SearchOptionsController } from '@/Controllers/SearchOptionsController' import Icon from '../Icon/Icon' import DecoratedInput from '../Input/DecoratedInput' import { observer } from 'mobx-react-lite' type Props = { itemListController: ItemListController searchOptionsController: SearchOptionsController } const SearchBar = ({ itemListController, searchOptionsController }: Props) => { const searchInputRef = useRef(null) const { noteFilterText, setNoteFilterText, clearFilterText, onFilterEnter } = itemListController const [focusedSearch, setFocusedSearch] = useState(false) const onNoteFilterTextChange = useCallback( (text: string) => { setNoteFilterText(text) }, [setNoteFilterText], ) const onNoteFilterKeyUp: KeyboardEventHandler = useCallback( (e) => { if (e.key === KeyboardKey.Enter) { onFilterEnter() } }, [onFilterEnter], ) const onSearchFocus = useCallback(() => setFocusedSearch(true), []) const onSearchBlur = useCallback(() => setFocusedSearch(false), []) const onClearSearch = useCallback(() => { clearFilterText() searchInputRef.current?.focus() }, [clearFilterText]) return (
]} right={[ noteFilterText && ( ), ]} roundedFull /> {(focusedSearch || noteFilterText) && (
)}
) } export default observer(SearchBar)