PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.2
GenerateBlocks v1.5.2
2.4.1 2.4.0 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
34 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
6 export default function AuthorsSelect( { label, onChange, value, help } ) {
7 const authors = useAuthors();
8
9 const authorOptions = useMemo( () => {
10 return authors
11 .reduce( ( result, author ) => {
12 result.push( { value: author.id, label: author.name } );
13 return result;
14 }, [] );
15 }, [ authors ] );
16
17 const selectedValues = authorOptions.filter( ( option ) => ( value.includes( option.value ) ) );
18
19 return (
20 <AdvancedSelect
21 id={ 'gblocks-select-author' }
22 label={ label || __( 'Select authors', 'generateblocks' ) }
23 help={ help }
24 placeholder={ label || __( 'Select authors', 'generateblocks' ) }
25 options={ authorOptions }
26 isMulti
27 isSearchable
28 value={ selectedValues }
29 onChange={ onChange }
30 isLoading={ authorOptions.length === 0 }
31 />
32 );
33 }
34