components
1 year ago
block.json
1 year ago
edit.js
1 year ago
editor.scss
1 year ago
index.js
1 year ago
save.js
1 year ago
transforms.js
1 year ago
save.js
47 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { RichText, useBlockProps } from '@wordpress/block-editor'; |
| 5 | import { Icon } from './components/Icon.jsx'; |
| 6 | import { getBlockClasses } from '@utils/getBlockClasses.js'; |
| 7 | |
| 8 | export function Save( { attributes } ) { |
| 9 | const { |
| 10 | content, |
| 11 | tagName, |
| 12 | htmlAttributes = {}, |
| 13 | icon, |
| 14 | iconLocation, |
| 15 | iconOnly, |
| 16 | } = attributes; |
| 17 | |
| 18 | const TagName = tagName; |
| 19 | |
| 20 | const classNames = getBlockClasses( |
| 21 | 'gb-text', |
| 22 | attributes, |
| 23 | ! icon |
| 24 | ); |
| 25 | |
| 26 | const blockProps = useBlockProps.save( |
| 27 | { |
| 28 | className: classNames.join( ' ' ).trim(), |
| 29 | ...htmlAttributes, |
| 30 | } |
| 31 | ); |
| 32 | |
| 33 | return ( |
| 34 | <TagName { ...blockProps }> |
| 35 | { !! icon ? ( |
| 36 | <> |
| 37 | { 'before' === iconLocation && ( <Icon icon={ icon } /> ) } |
| 38 | { !! content && ! iconOnly && ( <span className="gb-text"><RichText.Content value={ content } /></span> ) } |
| 39 | { 'after' === iconLocation && ( <Icon icon={ icon } /> ) } |
| 40 | </> |
| 41 | ) : ( |
| 42 | <RichText.Content value={ content } /> |
| 43 | ) } |
| 44 | </TagName> |
| 45 | ); |
| 46 | } |
| 47 |