components
1 year ago
block.json
1 year ago
edit.js
1 year ago
editor.scss
1 year ago
index.js
1 year ago
save.js
1 year ago
transforms.js
1 year ago
index.js
62 lines
| 1 | import { registerBlockType, registerBlockVariation } from '@wordpress/blocks'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { Edit } from './edit'; |
| 4 | import metadata from './block.json'; |
| 5 | import { Save } from './save'; |
| 6 | import { transforms } from './transforms'; |
| 7 | import { getElementType } from '../element/utils/getElementType'; |
| 8 | import { getIcon } from '@utils'; |
| 9 | |
| 10 | registerBlockType( metadata, { |
| 11 | edit: Edit, |
| 12 | save: Save, |
| 13 | icon: getIcon( 'text' ), |
| 14 | transforms, |
| 15 | __experimentalLabel: ( attrs, { context } ) => { |
| 16 | if ( 'list-view' === context ) { |
| 17 | if ( attrs?.metadata?.name ) { |
| 18 | return attrs.metadata.name; |
| 19 | } |
| 20 | |
| 21 | const text = attrs.content?.text ?? attrs.content; |
| 22 | |
| 23 | if ( text || attrs.iconOnly ) { |
| 24 | if ( attrs.iconOnly ) { |
| 25 | return __( 'Icon', 'generateblocks' ); |
| 26 | } |
| 27 | |
| 28 | return attrs.content; |
| 29 | } |
| 30 | } |
| 31 | }, |
| 32 | } ); |
| 33 | |
| 34 | registerBlockVariation( |
| 35 | 'generateblocks/text', |
| 36 | { |
| 37 | name: 'generateblocks/heading', |
| 38 | title: 'Headline', |
| 39 | description: __( 'A heading text element.', 'generateblocks' ), |
| 40 | icon: getIcon( 'headline' ), |
| 41 | attributes: { |
| 42 | tagName: 'h2', |
| 43 | }, |
| 44 | isActive: ( blockAttributes ) => 'heading' === getElementType( blockAttributes.tagName ), |
| 45 | }, |
| 46 | ); |
| 47 | |
| 48 | registerBlockVariation( |
| 49 | 'generateblocks/text', |
| 50 | { |
| 51 | name: 'generateblocks/button', |
| 52 | title: 'Button', |
| 53 | description: __( 'An interactive button element.', 'generateblocks' ), |
| 54 | icon: getIcon( 'button' ), |
| 55 | attributes: { |
| 56 | tagName: 'a', |
| 57 | ...generateblocksBlockText.defaultButtonAttributes, |
| 58 | }, |
| 59 | isActive: ( blockAttributes ) => 'button' === getElementType( blockAttributes.tagName ), |
| 60 | }, |
| 61 | ); |
| 62 |