PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.1
GenerateBlocks v1.4.1
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 5 years ago attributes.js 4 years ago block.js 4 years ago deprecated.js 5 years ago edit.js 4 years ago editor.scss 5 years ago save.js 5 years ago
save.js
91 lines
1 /**
2 * Block: Buttons
3 */
4
5 import classnames from 'classnames';
6 import Element from '../../components/element';
7
8 import {
9 RichText,
10 } from '@wordpress/block-editor';
11
12 import {
13 applyFilters,
14 } from '@wordpress/hooks';
15
16 export default ( { attributes } ) => {
17 const {
18 uniqueId,
19 className,
20 text,
21 url,
22 target,
23 relNoFollow,
24 relSponsored,
25 icon,
26 iconLocation,
27 removeText,
28 ariaLabel,
29 anchor,
30 } = attributes;
31
32 const relAttributes = [];
33
34 if ( relNoFollow ) {
35 relAttributes.push( 'nofollow' );
36 }
37
38 if ( target ) {
39 relAttributes.push( 'noopener', 'noreferrer' );
40 }
41
42 if ( relSponsored ) {
43 relAttributes.push( 'sponsored' );
44 }
45
46 let htmlAttributes = {
47 className: classnames( {
48 'gb-button': true,
49 [ `gb-button-${ uniqueId }` ]: true,
50 'gb-button-text': ! icon,
51 [ `${ className }` ]: undefined !== className,
52 } ),
53 href: !! url ? url : null,
54 target: !! target ? '_blank' : null,
55 rel: relAttributes && relAttributes.length > 0 ? relAttributes.join( ' ' ) : null,
56 'aria-label': !! ariaLabel ? ariaLabel : null,
57 id: anchor ? anchor : null,
58 };
59
60 htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/button', attributes );
61
62 return (
63 <Element
64 tagName={ url ? 'a' : 'span' }
65 htmlAttrs={ htmlAttributes }
66 >
67 { !! icon && 'left' === iconLocation &&
68 <span
69 className="gb-icon"
70 dangerouslySetInnerHTML={ { __html: icon } }
71 />
72 }
73
74 { ! removeText &&
75 <RichText.Content
76 value={ text }
77 tagName={ !! icon ? 'span' : null }
78 className={ !! icon ? 'gb-button-text' : null }
79 />
80 }
81
82 { !! icon && 'right' === iconLocation &&
83 <span
84 className="gb-icon"
85 dangerouslySetInnerHTML={ { __html: icon } }
86 />
87 }
88 </Element>
89 );
90 };
91