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
3 years ago
editor.scss
4 years ago
deprecated.js
78 lines
| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | import classnames from 'classnames'; |
| 5 | import blockAttributes from './attributes'; |
| 6 | |
| 7 | import { |
| 8 | InnerBlocks, |
| 9 | } from '@wordpress/block-editor'; |
| 10 | |
| 11 | import { |
| 12 | applyFilters, |
| 13 | } from '@wordpress/hooks'; |
| 14 | |
| 15 | import { getBlockAttributes } from '../../block-context'; |
| 16 | import buttonContainerContext from '../../block-context/button-container'; |
| 17 | |
| 18 | const allAttributes = Object.assign( |
| 19 | {}, |
| 20 | getBlockAttributes( |
| 21 | blockAttributes, |
| 22 | buttonContainerContext, |
| 23 | generateBlocksDefaults.buttonContainer |
| 24 | ), |
| 25 | ); |
| 26 | |
| 27 | const deprecated = [ |
| 28 | // v1 of container block. Deprecated the gb-grid-column wrapper in save component. |
| 29 | { |
| 30 | attributes: allAttributes, |
| 31 | supports: { |
| 32 | anchor: false, |
| 33 | className: false, |
| 34 | customClassName: false, |
| 35 | }, |
| 36 | migrate( attributes ) { |
| 37 | const oldClasses = attributes.cssClasses ? attributes.cssClasses : attributes.className; |
| 38 | const oldAnchor = attributes.elementId ? attributes.elementId : attributes.anchor; |
| 39 | |
| 40 | return { |
| 41 | ...attributes, |
| 42 | className: oldClasses, |
| 43 | anchor: oldAnchor, |
| 44 | cssClasses: '', |
| 45 | elementId: '', |
| 46 | }; |
| 47 | }, |
| 48 | save( { attributes } ) { |
| 49 | const { |
| 50 | uniqueId, |
| 51 | elementId, |
| 52 | cssClasses, |
| 53 | } = attributes; |
| 54 | |
| 55 | let htmlAttributes = { |
| 56 | id: !! elementId ? elementId : undefined, |
| 57 | className: classnames( { |
| 58 | 'gb-button-wrapper': true, |
| 59 | [ `gb-button-wrapper-${ uniqueId }` ]: true, |
| 60 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 61 | } ), |
| 62 | }; |
| 63 | |
| 64 | htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/button-container', attributes ); |
| 65 | |
| 66 | return ( |
| 67 | <div |
| 68 | { ...htmlAttributes } |
| 69 | > |
| 70 | <InnerBlocks.Content /> |
| 71 | </div> |
| 72 | ); |
| 73 | }, |
| 74 | }, |
| 75 | ]; |
| 76 | |
| 77 | export default deprecated; |
| 78 |