css
6 years ago
attributes.js
6 years ago
block.js
6 years ago
deprecated.js
6 years ago
edit.js
6 years ago
editor.scss
6 years ago
markformat.js
6 years ago
save.js
6 years ago
transforms.js
6 years ago
save.js
67 lines
| 1 | /** |
| 2 | * Block: Headline |
| 3 | */ |
| 4 | |
| 5 | import classnames from 'classnames'; |
| 6 | import sanitizeSVG from '../../utils/sanitize-svg'; |
| 7 | |
| 8 | const { |
| 9 | RichText, |
| 10 | } = wp.blockEditor; |
| 11 | |
| 12 | const { |
| 13 | applyFilters, |
| 14 | } = wp.hooks; |
| 15 | |
| 16 | export default ( { attributes } ) => { |
| 17 | const { |
| 18 | uniqueId, |
| 19 | elementId, |
| 20 | cssClasses, |
| 21 | element, |
| 22 | content, |
| 23 | icon, |
| 24 | removeText, |
| 25 | ariaLabel, |
| 26 | } = attributes; |
| 27 | |
| 28 | const ConditionalWrap = ( { condition, wrap, children } ) => condition ? wrap( children ) : children; |
| 29 | |
| 30 | let htmlAttributes = { |
| 31 | id: !! elementId ? elementId : undefined, |
| 32 | className: classnames( { |
| 33 | 'gb-headline': true, |
| 34 | [ `gb-headline-${ uniqueId }` ]: true, |
| 35 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 36 | } ), |
| 37 | }; |
| 38 | |
| 39 | htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/headline', attributes ); |
| 40 | |
| 41 | return ( |
| 42 | <ConditionalWrap |
| 43 | condition={ icon } |
| 44 | wrap={ children => <div className={ classnames( { |
| 45 | 'gb-headline-wrapper': true, |
| 46 | [ `gb-headline-wrapper-${ uniqueId }` ]: true, |
| 47 | } ) }>{ children }</div> } |
| 48 | > |
| 49 | { icon && |
| 50 | <span |
| 51 | className="gb-icon" |
| 52 | aria-label={ !! removeText && !! ariaLabel ? ariaLabel : undefined } |
| 53 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 54 | /> |
| 55 | } |
| 56 | |
| 57 | { ! removeText && |
| 58 | <RichText.Content |
| 59 | tagName={ element } |
| 60 | value={ content } |
| 61 | { ...htmlAttributes } |
| 62 | /> |
| 63 | } |
| 64 | </ConditionalWrap> |
| 65 | ); |
| 66 | }; |
| 67 |