TagNameControl.jsx
23 lines
| 1 | import { SelectControl } from '@wordpress/components'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { getBlockType } from '@wordpress/blocks'; |
| 4 | |
| 5 | export function TagNameControl( { value, options = [], onChange, blockName } ) { |
| 6 | const tagNames = getBlockType( blockName )?.attributes?.tagName?.enum; |
| 7 | const tagNameOptions = options.length |
| 8 | ? options |
| 9 | : tagNames.map( ( tag ) => ( { |
| 10 | label: tag, |
| 11 | value: tag, |
| 12 | } ) ); |
| 13 | |
| 14 | return ( |
| 15 | <SelectControl |
| 16 | label={ __( 'Tag Name' ) } |
| 17 | value={ value } |
| 18 | options={ tagNameOptions } |
| 19 | onChange={ onChange } |
| 20 | /> |
| 21 | ); |
| 22 | } |
| 23 |