| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import classnames from 'classnames/dedupe'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies |
| 8 |
*/ |
| 9 |
import metadata from './block.json'; |
| 10 |
|
| 11 |
/** |
| 12 |
* WordPress dependencies |
| 13 |
*/ |
| 14 |
const { applyFilters } = wp.hooks; |
| 15 |
|
| 16 |
const { |
| 17 |
useBlockProps, |
| 18 |
useInnerBlocksProps: __stableUseInnerBlocksProps, |
| 19 |
__experimentalUseInnerBlocksProps, |
| 20 |
} = wp.blockEditor; |
| 21 |
|
| 22 |
const { name } = metadata; |
| 23 |
|
| 24 |
const useInnerBlocksProps = __stableUseInnerBlocksProps || __experimentalUseInnerBlocksProps; |
| 25 |
|
| 26 |
/** |
| 27 |
* Block Save Class. |
| 28 |
*/ |
| 29 |
export default function BlockSave(props) { |
| 30 |
const { verticalAlign, horizontalAlign, gap } = props.attributes; |
| 31 |
|
| 32 |
let className = classnames( |
| 33 |
'ghostkit-grid', |
| 34 |
`ghostkit-grid-gap-${gap}`, |
| 35 |
verticalAlign ? `ghostkit-grid-align-items-${verticalAlign}` : false, |
| 36 |
horizontalAlign ? `ghostkit-grid-justify-content-${horizontalAlign}` : false |
| 37 |
); |
| 38 |
|
| 39 |
// background |
| 40 |
const background = applyFilters('ghostkit.blocks.grid.background', '', { |
| 41 |
...{ |
| 42 |
name, |
| 43 |
}, |
| 44 |
...props, |
| 45 |
}); |
| 46 |
|
| 47 |
if (background) { |
| 48 |
className = classnames(className, 'ghostkit-grid-with-bg'); |
| 49 |
} |
| 50 |
|
| 51 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 52 |
...{ |
| 53 |
name, |
| 54 |
}, |
| 55 |
...props, |
| 56 |
}); |
| 57 |
|
| 58 |
const blockProps = useBlockProps.save({ |
| 59 |
className, |
| 60 |
}); |
| 61 |
const { children, ...innerBlocksProps } = useInnerBlocksProps.save(blockProps); |
| 62 |
|
| 63 |
return ( |
| 64 |
<div {...innerBlocksProps}> |
| 65 |
{background} |
| 66 |
<div className="ghostkit-grid-inner">{children}</div> |
| 67 |
</div> |
| 68 |
); |
| 69 |
} |
| 70 |
|