TagNameToolbar.jsx
70 lines
| 1 | import { TagNameIcon } from './TagNameIcon'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { ToolbarGroup } from '@wordpress/components'; |
| 4 | import { BlockControls } from '@wordpress/block-editor'; |
| 5 | |
| 6 | export function TagNameToolbar( { label, onChange, tagName } ) { |
| 7 | const options = [ |
| 8 | { |
| 9 | label: __( 'Heading 1', 'generateblocks' ), |
| 10 | value: 'h1', |
| 11 | }, |
| 12 | { |
| 13 | label: __( 'Heading 2', 'generateblocks' ), |
| 14 | value: 'h2', |
| 15 | }, |
| 16 | { |
| 17 | label: __( 'Heading 3', 'generateblocks' ), |
| 18 | value: 'h3', |
| 19 | }, |
| 20 | { |
| 21 | label: __( 'Heading 4', 'generateblocks' ), |
| 22 | value: 'h4', |
| 23 | }, |
| 24 | { |
| 25 | label: __( 'Heading 5', 'generateblocks' ), |
| 26 | value: 'h5', |
| 27 | }, |
| 28 | { |
| 29 | label: __( 'Heading 6', 'generateblocks' ), |
| 30 | value: 'h6', |
| 31 | }, |
| 32 | { |
| 33 | label: __( 'Paragraph', 'generateblocks' ), |
| 34 | value: 'p', |
| 35 | }, |
| 36 | { |
| 37 | label: __( 'Div', 'generateblocks' ), |
| 38 | value: 'div', |
| 39 | }, |
| 40 | { |
| 41 | label: __( 'Span', 'generateblocks' ), |
| 42 | value: 'span', |
| 43 | }, |
| 44 | ]; |
| 45 | |
| 46 | if ( ! options.find( ( option ) => option.value === tagName ) ) { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | const controls = options.map( ( option ) => { |
| 51 | return { |
| 52 | isActive: option.value === tagName, |
| 53 | icon: <TagNameIcon level={ option.value } />, |
| 54 | title: option.label, |
| 55 | onClick: () => onChange( option.value ), |
| 56 | }; |
| 57 | } ); |
| 58 | |
| 59 | return ( |
| 60 | <BlockControls> |
| 61 | <ToolbarGroup |
| 62 | isCollapsed={ true } |
| 63 | icon={ <TagNameIcon level={ tagName } /> } |
| 64 | label={ label } |
| 65 | controls={ controls } |
| 66 | /> |
| 67 | </BlockControls> |
| 68 | ); |
| 69 | } |
| 70 |