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 / components / ButtonContentRenderer.js
generateblocks / src / blocks / button / components Last commit date
BlockControls.js 4 years ago ButtonContentRenderer.js 4 years ago ComponentCSS.js 4 years ago ConditionalColors.js 4 years ago InspectorAdvancedControls.js 4 years ago InspectorControls.js 4 years ago
ButtonContentRenderer.js
99 lines
1 import { RichText, useBlockProps } from '@wordpress/block-editor';
2 import IconWrapper from '../../../components/icon-wrapper';
3 import { __ } from '@wordpress/i18n';
4 import Element from '../../../components/element';
5 import classnames from 'classnames';
6 import { applyFilters } from '@wordpress/hooks';
7
8 export default function ButtonContentRenderer( props ) {
9 const {
10 attributes,
11 setAttributes,
12 isSelected,
13 InnerContent = RichText,
14 context,
15 name,
16 buttonRef,
17 } = props;
18
19 const {
20 uniqueId,
21 anchor,
22 text,
23 url,
24 target,
25 relNoFollow,
26 relSponsored,
27 icon,
28 iconLocation,
29 removeText,
30 ariaLabel,
31 } = attributes;
32
33 const relAttributes = [];
34
35 if ( relNoFollow ) {
36 relAttributes.push( 'nofollow' );
37 }
38
39 if ( target ) {
40 relAttributes.push( 'noopener', 'noreferrer' );
41 }
42
43 if ( relSponsored ) {
44 relAttributes.push( 'sponsored' );
45 }
46
47 let htmlAttributes = {
48 className: classnames( {
49 'gb-button': true,
50 [ `gb-button-${ uniqueId }` ]: true,
51 'gb-button-text': ! icon,
52 } ),
53 rel: relAttributes && relAttributes.length > 0 ? relAttributes.join( ' ' ) : null,
54 'aria-label': !! ariaLabel ? ariaLabel : null,
55 id: anchor ? anchor : null,
56 ref: buttonRef,
57 };
58
59 htmlAttributes = applyFilters(
60 'generateblocks.frontend.htmlAttributes',
61 htmlAttributes,
62 'generateblocks/button',
63 attributes
64 );
65
66 const blockProps = useBlockProps( htmlAttributes );
67
68 const richTextFormats = applyFilters(
69 'generateblocks.editor.buttonDisableFormatting',
70 false,
71 props
72 ) ? [] : [ 'core/bold', 'core/italic', 'core/strikethrough' ];
73
74 return (
75 <Element tagName={ url ? 'a' : 'span' } htmlAttrs={ blockProps }>
76 <IconWrapper
77 hasIcon={ !! icon }
78 icon={ icon }
79 direction={ iconLocation }
80 hideChildren={ removeText }
81 showWrapper={ ! removeText && !! icon }
82 wrapperClassname={ 'gb-button-text' }
83 >
84 <InnerContent
85 name={ name }
86 placeholder={ __( 'Add text…', 'generateblocks' ) }
87 value={ text }
88 onChange={ ( value ) => setAttributes( { text: value } ) }
89 allowedFormats={ richTextFormats }
90 isSelected={ isSelected }
91 attributes={ attributes }
92 setAttributes={ setAttributes }
93 context={ context }
94 />
95 </IconWrapper>
96 </Element>
97 );
98 }
99