PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.0
GenerateBlocks v1.4.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 / deprecated.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
deprecated.js
123 lines
1 /**
2 * External dependencies
3 */
4 import classnames from 'classnames';
5 import blockAttributes from './attributes';
6 import sanitizeSVG from '../../utils/sanitize-svg';
7
8 import {
9 applyFilters,
10 } from '@wordpress/hooks';
11
12 import {
13 RichText,
14 } from '@wordpress/block-editor';
15
16 const deprecated = [
17 // v1 of button block.
18 {
19 attributes: {
20 ...blockAttributes,
21 text: {
22 type: 'array',
23 source: 'children',
24 selector: '.gb-button .button-text',
25 default: 'Button',
26 },
27 },
28 supports: {
29 anchor: false,
30 className: false,
31 customClassName: false,
32 inserter: false,
33 reusable: false,
34 },
35 migrate( attributes ) {
36 const oldClasses = attributes.cssClasses ? attributes.cssClasses : attributes.className;
37 const oldAnchor = attributes.elementId ? attributes.elementId : attributes.anchor;
38
39 return {
40 ...attributes,
41 className: oldClasses,
42 anchor: oldAnchor,
43 cssClasses: '',
44 elementId: '',
45 };
46 },
47 save( { attributes } ) {
48 const {
49 uniqueId,
50 elementId,
51 cssClasses,
52 text,
53 url,
54 target,
55 relNoFollow,
56 relSponsored,
57 icon,
58 iconLocation,
59 removeText,
60 ariaLabel,
61 } = attributes;
62
63 const relAttributes = [];
64
65 if ( relNoFollow ) {
66 relAttributes.push( 'nofollow' );
67 }
68
69 if ( target ) {
70 relAttributes.push( 'noopener', 'noreferrer' );
71 }
72
73 if ( relSponsored ) {
74 relAttributes.push( 'sponsored' );
75 }
76
77 let htmlAttributes = {
78 id: !! elementId ? elementId : undefined,
79 className: classnames( {
80 'gb-button': true,
81 [ `gb-button-${ uniqueId }` ]: true,
82 [ `${ cssClasses }` ]: '' !== cssClasses,
83 } ),
84 href: !! url ? url : undefined,
85 target: !! target ? '_blank' : undefined,
86 rel: relAttributes && relAttributes.length > 0 ? relAttributes.join( ' ' ) : undefined,
87 'aria-label': !! ariaLabel ? ariaLabel : undefined,
88 };
89
90 htmlAttributes = applyFilters( 'generateblocks.frontend.htmlAttributes', htmlAttributes, 'generateblocks/button', attributes );
91
92 return (
93 <a
94 { ...htmlAttributes }
95 >
96 { icon && 'left' === iconLocation &&
97 <span
98 className="gb-icon"
99 dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } }
100 />
101 }
102 { ! removeText &&
103 <RichText.Content
104 tagName="span"
105 className="button-text"
106 value={ text }
107 key="button-text"
108 />
109 }
110 { icon && 'right' === iconLocation &&
111 <span
112 className="gb-icon"
113 dangerouslySetInnerHTML={ { __html: sanitizeSVG( icon ) } }
114 />
115 }
116 </a>
117 );
118 },
119 },
120 ];
121
122 export default deprecated;
123