PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
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 / text / components / BlockSettings.jsx
generateblocks / src / blocks / text / components Last commit date
BlockSettings.jsx 1 year ago Icon.jsx 1 year ago
BlockSettings.jsx
202 lines
1 import { __ } from '@wordpress/i18n';
2 import { SelectControl, TextControl, BaseControl, ToggleControl } from '@wordpress/components';
3 import { applyFilters } from '@wordpress/hooks';
4
5 import { OpenPanel, IconControl, ColorPicker } from '@edge22/components';
6
7 import {
8 ApplyFilters,
9 URLControls,
10 TagNameControl,
11 DynamicTagsOnboarder,
12 } from '@components/index.js';
13 import { useBlockStyles } from '@hooks/useBlockStyles';
14 import generalSvgs from '@components/icon-picker/svgs-general';
15 import socialSvgs from '@components/icon-picker/svgs-social';
16
17 export function BlockSettings( {
18 getStyleValue,
19 onStyleChange,
20 name,
21 attributes,
22 setAttributes,
23 htmlAttributes,
24 context,
25 } ) {
26 const {
27 tagName,
28 icon,
29 iconLocation,
30 iconOnly,
31 } = attributes;
32
33 const {
34 currentAtRule,
35 } = useBlockStyles();
36
37 const panelProps = {
38 name,
39 attributes,
40 setAttributes,
41 };
42
43 const icons = applyFilters(
44 'generateblocks.editor.iconSVGSets',
45 {
46 general: {
47 group: __( 'General', 'generateblocks' ),
48 svgs: generalSvgs,
49 },
50 social: {
51 group: __( 'Social', 'generateblocks' ),
52 svgs: socialSvgs,
53 },
54 },
55 { attributes }
56 );
57
58 return (
59 <ApplyFilters
60 name="generateblocks.editor.blockControls"
61 blockName={ name }
62 getStyleValue={ getStyleValue }
63 onStyleChange={ onStyleChange }
64 currentAtRule={ currentAtRule }
65 attributes={ attributes }
66 setAttributes={ setAttributes }
67 >
68 <OpenPanel
69 { ...panelProps }
70 shouldRender={ 'a' === tagName && '' === currentAtRule }
71 panelId="link-destination"
72 >
73 <URLControls
74 label={ __( 'Link Destination', 'generateblocks' ) }
75 setAttributes={ setAttributes }
76 htmlAttributes={ htmlAttributes }
77 context={ context }
78 tagName={ tagName }
79 />
80 </OpenPanel>
81
82 <OpenPanel
83 { ...panelProps }
84 shouldRender={ '' === currentAtRule }
85 panelId="settings"
86 >
87 <TagNameControl
88 blockName="generateblocks/text"
89 value={ tagName }
90 onChange={ ( value ) => {
91 setAttributes( { tagName: value } );
92
93 if ( 'a' === value && ! getStyleValue( 'display', currentAtRule ) ) {
94 onStyleChange( 'display', 'block' );
95 }
96 } }
97 />
98 </OpenPanel>
99
100 <OpenPanel
101 { ...panelProps }
102 shouldRender={ '' === currentAtRule }
103 panelId="icon"
104 >
105 <IconControl
106 label={ __( 'Icon', 'generateblocks' ) }
107 value={ icon }
108 onChange={ ( value ) => {
109 // If the user hasn't done this before, align the icon and text.
110 if ( ! icon ) {
111 if ( ! getStyleValue( 'display' ) ) {
112 onStyleChange( 'display', 'inline-flex' );
113 }
114
115 if ( ! getStyleValue( 'alignItems' ) ) {
116 onStyleChange( 'alignItems', 'center' );
117 }
118
119 if ( ! getStyleValue( 'columnGap' ) ) {
120 onStyleChange( 'columnGap', '0.5em' );
121 }
122
123 if ( ! getStyleValue( 'width', '', '.gb-shape svg' ) ) {
124 onStyleChange( 'width', '1em', '', '.gb-shape svg' );
125 }
126
127 if ( ! getStyleValue( 'height', '', '.gb-shape svg' ) ) {
128 onStyleChange( 'height', '1em', '', '.gb-shape svg' );
129 }
130
131 if ( ! getStyleValue( 'fill', '', '.gb-shape svg' ) ) {
132 onStyleChange( 'fill', 'currentColor', '', '.gb-shape svg' );
133 }
134 }
135
136 setAttributes( { icon: value } );
137 } }
138 onClear={ () => setAttributes( { icon: '' } ) }
139 icons={ icons }
140 clearLabel={ __( 'Clear', 'generateblocks' ) }
141 openLabel={ __( 'Open Library', 'generateblocks' ) }
142 modalTitle={ __( 'Icon Library', 'generateblocks' ) }
143 />
144
145 { !! icon && (
146 <>
147 <ColorPicker
148 label={ __( 'Icon Color', 'generateblocks' ) }
149 value={ getStyleValue( 'color', currentAtRule, '.gb-shape svg' ) }
150 onChange={ ( value ) => onStyleChange( 'color', value, currentAtRule, '.gb-shape svg' ) }
151 />
152
153 { ! iconOnly && (
154 <SelectControl
155 label={ __( 'Icon Location', 'generateblocks' ) }
156 value={ iconLocation }
157 options={ [
158 { label: __( 'Before', 'generateblocks' ), value: 'before' },
159 { label: __( 'After', 'generateblocks' ), value: 'after' },
160 ] }
161 onChange={ ( value ) => setAttributes( { iconLocation: value } ) }
162 />
163 ) }
164
165 <BaseControl
166 label={ __( 'Icon Display', 'generateblocks' ) }
167 id="gb-icon-only"
168 >
169 <ToggleControl
170 id="gb-icon-only"
171 label={ __( 'Show the icon by itself', 'generateblocks' ) }
172 checked={ !! iconOnly }
173 onChange={ () => setAttributes( { iconOnly: ! iconOnly } ) }
174 />
175 </BaseControl>
176
177 <TextControl
178 label={ __( 'ARIA Label', 'generateblocks' ) }
179 value={ htmlAttributes[ 'aria-label' ] ?? '' }
180 onChange={ ( value ) => {
181 const newHtmlAttributes = { ...htmlAttributes };
182
183 if ( ! value && htmlAttributes[ 'aria-label' ] ) {
184 delete newHtmlAttributes[ 'aria-label' ];
185 } else if ( value ) {
186 newHtmlAttributes[ 'aria-label' ] = value;
187 }
188
189 setAttributes( {
190 htmlAttributes: newHtmlAttributes,
191 } );
192 } }
193 />
194 </>
195 ) }
196 </OpenPanel>
197
198 <DynamicTagsOnboarder />
199 </ApplyFilters>
200 );
201 }
202