components
1 year ago
css
2 years ago
attributes.js
3 years ago
block.js
1 year ago
deprecated.js
3 years ago
edit.js
2 years ago
editor.scss
2 years ago
save.js
3 years ago
transforms.js
1 year ago
block.js
82 lines
| 1 | /** |
| 2 | * Block: Buttons |
| 3 | */ |
| 4 | |
| 5 | import './editor.scss'; |
| 6 | |
| 7 | import editButton from './edit'; |
| 8 | import saveButton from './save'; |
| 9 | import deprecated from './deprecated'; |
| 10 | import blockAttributes from './attributes'; |
| 11 | import getIcon from '../../utils/get-icon'; |
| 12 | import dynamicContentAttributes from '../../extend/dynamic-content/attributes'; |
| 13 | import { transforms } from './transforms'; |
| 14 | |
| 15 | import { |
| 16 | __, |
| 17 | } from '@wordpress/i18n'; |
| 18 | |
| 19 | import { |
| 20 | registerBlockType, |
| 21 | } from '@wordpress/blocks'; |
| 22 | import getContentTypeLabel from '../../extend/dynamic-content/utils/getContentTypeLabel'; |
| 23 | import { getBlockAttributes } from '../../block-context'; |
| 24 | import buttonContext from '../../block-context/button'; |
| 25 | |
| 26 | const attributes = Object.assign( |
| 27 | {}, |
| 28 | getBlockAttributes( blockAttributes, buttonContext, generateBlocksDefaults.button ), |
| 29 | dynamicContentAttributes |
| 30 | ); |
| 31 | |
| 32 | /** |
| 33 | * Register our Button block. |
| 34 | * |
| 35 | * @param {string} name Block name. |
| 36 | * @param {Object} settings Block settings. |
| 37 | * @return {?WPBlock} The block, if it has been successfully |
| 38 | * registered; otherwise `undefined`. |
| 39 | */ |
| 40 | registerBlockType( 'generateblocks/button', { |
| 41 | apiVersion: 3, |
| 42 | title: __( 'Button', 'generateblocks' ), |
| 43 | description: __( 'Drive conversions with beautiful buttons.', 'generateblocks' ), |
| 44 | icon: getIcon( 'button' ), |
| 45 | category: 'generateblocks', |
| 46 | keywords: [ |
| 47 | __( 'button' ), |
| 48 | __( 'buttons' ), |
| 49 | __( 'generate' ), |
| 50 | ], |
| 51 | attributes, |
| 52 | supports: { |
| 53 | className: false, |
| 54 | }, |
| 55 | edit: editButton, |
| 56 | save: saveButton, |
| 57 | deprecated, |
| 58 | transforms, |
| 59 | usesContext: [ 'postId', 'postType', 'generateblocks/query', 'generateblocks/inheritQuery' ], |
| 60 | __experimentalLabel: ( attrs, { context } ) => { |
| 61 | const customName = attrs?.metadata?.name; |
| 62 | |
| 63 | if ( 'list-view' === context && customName ) { |
| 64 | return customName; |
| 65 | } |
| 66 | |
| 67 | if ( |
| 68 | context === 'list-view' && |
| 69 | ( attrs.text || attrs.removeText ) && |
| 70 | ! attrs.useDynamicData |
| 71 | ) { |
| 72 | if ( attrs.removeText ) { |
| 73 | return __( 'Icon', 'generateblocks' ); |
| 74 | } |
| 75 | |
| 76 | return attrs.text; |
| 77 | } |
| 78 | |
| 79 | return getContentTypeLabel( attrs, __( 'Button', 'generateblocks' ) ); |
| 80 | }, |
| 81 | } ); |
| 82 |