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