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