PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.0
GenerateBlocks v1.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / button / save.js
generateblocks / src / blocks / button Last commit date
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