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
57 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 | export default ( { attributes } ) => { |
| 13 | const { |
| 14 | uniqueId, |
| 15 | elementId, |
| 16 | cssClasses, |
| 17 | element, |
| 18 | content, |
| 19 | icon, |
| 20 | removeText, |
| 21 | ariaLabel, |
| 22 | } = attributes; |
| 23 | |
| 24 | const ConditionalWrap = ( { condition, wrap, children } ) => condition ? wrap( children ) : children; |
| 25 | |
| 26 | return ( |
| 27 | <ConditionalWrap |
| 28 | condition={ icon } |
| 29 | wrap={ children => <div className={ classnames( { |
| 30 | 'gb-headline-wrapper': true, |
| 31 | [ `gb-headline-wrapper-${ uniqueId }` ]: true, |
| 32 | } ) }>{ children }</div> } |
| 33 | > |
| 34 | { icon && |
| 35 | <span |
| 36 | className="gb-icon" |
| 37 | aria-label={ !! removeText && !! ariaLabel ? ariaLabel : undefined } |
| 38 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 39 | /> |
| 40 | } |
| 41 | |
| 42 | { ! removeText && |
| 43 | <RichText.Content |
| 44 | tagName={ element } |
| 45 | id={ !! elementId ? elementId : undefined } |
| 46 | className={ classnames( { |
| 47 | 'gb-headline': true, |
| 48 | [ `gb-headline-${ uniqueId }` ]: true, |
| 49 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 50 | } ) } |
| 51 | value={ content } |
| 52 | /> |
| 53 | } |
| 54 | </ConditionalWrap> |
| 55 | ); |
| 56 | }; |
| 57 |