components
4 years ago
css
4 years ago
attributes.js
4 years ago
block.js
4 years ago
deprecated.js
5 years ago
edit.js
4 years ago
editor.scss
4 years ago
element-icons.js
4 years ago
markformat.js
4 years ago
save.js
4 years ago
transforms.js
5 years ago
save.js
57 lines
| 1 | /** |
| 2 | * Block: Headline |
| 3 | */ |
| 4 | |
| 5 | import classnames from 'classnames'; |
| 6 | import Element from '../../components/element'; |
| 7 | import { RichText, useBlockProps } from '@wordpress/block-editor'; |
| 8 | import { applyFilters } from '@wordpress/hooks'; |
| 9 | import IconWrapper from '../../components/icon-wrapper'; |
| 10 | |
| 11 | export default ( { attributes } ) => { |
| 12 | const { |
| 13 | uniqueId, |
| 14 | anchor, |
| 15 | element, |
| 16 | content, |
| 17 | icon, |
| 18 | hasIcon, |
| 19 | removeText, |
| 20 | } = attributes; |
| 21 | |
| 22 | let htmlAttributes = { |
| 23 | className: classnames( { |
| 24 | 'gb-headline': true, |
| 25 | [ `gb-headline-${ uniqueId }` ]: true, |
| 26 | 'gb-headline-text': ! hasIcon, |
| 27 | } ), |
| 28 | id: anchor ? anchor : null, |
| 29 | }; |
| 30 | |
| 31 | htmlAttributes = applyFilters( |
| 32 | 'generateblocks.frontend.htmlAttributes', |
| 33 | htmlAttributes, |
| 34 | 'generateblocks/headline', |
| 35 | attributes |
| 36 | ); |
| 37 | |
| 38 | const blockProps = useBlockProps.save( htmlAttributes ); |
| 39 | |
| 40 | return ( |
| 41 | <Element tagName={ element } htmlAttrs={ blockProps }> |
| 42 | <IconWrapper |
| 43 | hasIcon={ hasIcon } |
| 44 | icon={ icon } |
| 45 | hideChildren={ removeText } |
| 46 | showWrapper={ false } |
| 47 | > |
| 48 | <RichText.Content |
| 49 | value={ content } |
| 50 | tagName={ hasIcon && icon ? 'span' : undefined } |
| 51 | className={ hasIcon && icon ? 'gb-headline-text' : undefined } |
| 52 | /> |
| 53 | </IconWrapper> |
| 54 | </Element> |
| 55 | ); |
| 56 | }; |
| 57 |