PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.3
GenerateBlocks v1.5.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / authors-select / index.js
generateblocks / src / components / authors-select Last commit date
index.js 4 years ago
index.js
44 lines
1 import AdvancedSelect from '../advanced-select';
2 import { useMemo } from '@wordpress/element';
3 import { __ } from '@wordpress/i18n';
4 import useAuthors from '../../hooks/useAuthors';
5 import { applyFilters } from '@wordpress/hooks';
6
7 export default function AuthorsSelect( props ) {
8 const {
9 label,
10 onChange,
11 value,
12 help,
13 filterName = 'generateblocks.editor.authors-select',
14 } = props;
15 const authors = useAuthors();
16
17 const authorOptions = useMemo( () => {
18 const options = authors
19 .reduce( ( result, author ) => {
20 result.push( { value: author.id, label: author.name } );
21 return result;
22 }, [] );
23
24 return applyFilters( filterName, options );
25 }, [ authors ] );
26
27 const selectedValues = authorOptions.filter( ( option ) => ( value.includes( option.value ) ) );
28
29 return (
30 <AdvancedSelect
31 id={ 'gblocks-select-author' }
32 label={ label || __( 'Select authors', 'generateblocks' ) }
33 help={ help }
34 placeholder={ label || __( 'Select authors', 'generateblocks' ) }
35 options={ authorOptions }
36 isMulti
37 isSearchable
38 value={ selectedValues }
39 onChange={ onChange }
40 isLoading={ authorOptions.length === 0 }
41 />
42 );
43 }
44