AuthorMetaControl.js
3 years ago
CommentsControl.js
4 years ago
ContentTypeControl.js
4 years ago
DynamicSourceControl.js
3 years ago
ExcerptControl.js
4 years ago
LinkTypeControl.js
3 years ago
PostDateControl.js
4 years ago
PostMetaControl.js
3 years ago
TermsControl.js
4 years ago
TermsControl.js
50 lines
| 1 | import SimpleSelect from '../../../components/simple-select'; |
| 2 | import { useTaxonomies } from '../../../hooks'; |
| 3 | import { useMemo } from '@wordpress/element'; |
| 4 | import { __ } from '@wordpress/i18n'; |
| 5 | import { TextControl } from '@wordpress/components'; |
| 6 | |
| 7 | export default function TermsControl( props ) { |
| 8 | const { |
| 9 | isActive, |
| 10 | postType, |
| 11 | termTaxonomy, |
| 12 | termSeparator, |
| 13 | setAttributes, |
| 14 | name, |
| 15 | } = props; |
| 16 | |
| 17 | const taxonomies = useTaxonomies(); |
| 18 | |
| 19 | const taxonomiesOptions = useMemo( () => ( |
| 20 | taxonomies |
| 21 | .filter( ( tax ) => ( tax.types.includes( postType ) ) ) |
| 22 | .map( ( tax ) => ( { value: tax.slug, label: tax.name } ) ) |
| 23 | ), [ taxonomies, postType ] ); |
| 24 | |
| 25 | return ( |
| 26 | <> |
| 27 | { isActive && |
| 28 | <> |
| 29 | <SimpleSelect |
| 30 | label={ __( 'Taxonomy', 'generateblocks' ) } |
| 31 | options={ taxonomiesOptions } |
| 32 | value={ termTaxonomy } |
| 33 | onChange={ ( option ) => { |
| 34 | setAttributes( { termTaxonomy: option.value } ); |
| 35 | } } |
| 36 | /> |
| 37 | |
| 38 | { 'generateblocks/button' !== name && |
| 39 | <TextControl |
| 40 | label={ __( 'Term separator', 'generateblocks' ) } |
| 41 | value={ termSeparator } |
| 42 | onChange={ ( value ) => setAttributes( { termSeparator: value } ) } |
| 43 | /> |
| 44 | } |
| 45 | </> |
| 46 | } |
| 47 | </> |
| 48 | ); |
| 49 | } |
| 50 |