css
6 years ago
attributes.js
6 years ago
block.js
6 years ago
edit.js
6 years ago
editor.scss
6 years ago
save.js
6 years ago
style.scss
6 years ago
save.js
73 lines
| 1 | /** |
| 2 | * Block: Buttons |
| 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 | text, |
| 18 | url, |
| 19 | target, |
| 20 | relNoFollow, |
| 21 | relSponsored, |
| 22 | icon, |
| 23 | iconLocation, |
| 24 | removeText, |
| 25 | ariaLabel, |
| 26 | } = attributes; |
| 27 | |
| 28 | const relAttributes = []; |
| 29 | |
| 30 | if ( relNoFollow ) { |
| 31 | relAttributes.push( 'nofollow' ); |
| 32 | } |
| 33 | |
| 34 | if ( target ) { |
| 35 | relAttributes.push( 'noopener', 'noreferrer' ); |
| 36 | } |
| 37 | |
| 38 | if ( relSponsored ) { |
| 39 | relAttributes.push( 'sponsored' ); |
| 40 | } |
| 41 | |
| 42 | return ( |
| 43 | <a |
| 44 | id={ !! elementId ? elementId : undefined } |
| 45 | className={ classnames( { |
| 46 | 'gb-button': true, |
| 47 | [ `gb-button-${ uniqueId }` ]: true, |
| 48 | [ `${ cssClasses }` ]: '' !== cssClasses, |
| 49 | } ) } |
| 50 | href={ !! url ? url : undefined } |
| 51 | target={ !! target ? '_blank' : undefined } |
| 52 | rel={ relAttributes && relAttributes.length > 0 ? relAttributes.join( ' ' ) : undefined } |
| 53 | aria-label={ !! removeText && !! ariaLabel ? ariaLabel : undefined } |
| 54 | > |
| 55 | { icon && 'left' === iconLocation && |
| 56 | <span |
| 57 | className="gb-icon" |
| 58 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 59 | /> |
| 60 | } |
| 61 | { ! removeText && |
| 62 | <RichText.Content tagName="span" className="button-text" value={ text } key="button-text" /> |
| 63 | } |
| 64 | { icon && 'right' === iconLocation && |
| 65 | <span |
| 66 | className="gb-icon" |
| 67 | dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } } |
| 68 | /> |
| 69 | } |
| 70 | </a> |
| 71 | ); |
| 72 | }; |
| 73 |