add-library.js
2 years ago
category-list.js
1 year ago
insert-pattern.js
2 years ago
library-cache.js
2 years ago
library-layout.js
1 year ago
library-provider.js
2 years ago
library-selector.js
1 year ago
manage-libraries.js
2 years ago
pattern-details-header.js
1 year ago
pattern-details.js
1 year ago
pattern-list.js
1 year ago
pattern-search.js
2 years ago
pattern.js
1 year ago
selected-patterns.js
1 year ago
pattern-search.js
29 lines
| 1 | import { SearchControl } from '@wordpress/components'; |
| 2 | import { useState, useEffect } from '@wordpress/element'; |
| 3 | import { useDebounce } from '@wordpress/compose'; |
| 4 | import { useLibrary } from './library-provider'; |
| 5 | |
| 6 | export default function PatternSearch( { onChange } ) { |
| 7 | const { setSearch, activeLibrary } = useLibrary(); |
| 8 | const [ searchInput, setSearchInput ] = useState( '' ); |
| 9 | const setDebouncedInput = useDebounce( setSearch, 500 ); |
| 10 | |
| 11 | useEffect( () => { |
| 12 | setDebouncedInput( searchInput ); |
| 13 | }, [ searchInput ] ); |
| 14 | |
| 15 | useEffect( () => { |
| 16 | setSearchInput( '' ); |
| 17 | }, [ activeLibrary?.id ] ); |
| 18 | |
| 19 | return ( |
| 20 | <SearchControl |
| 21 | value={ searchInput } |
| 22 | onChange={ ( value ) => { |
| 23 | onChange( value ); |
| 24 | setSearchInput( value ); |
| 25 | } } |
| 26 | /> |
| 27 | ); |
| 28 | } |
| 29 |