PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.1.1
GenerateBlocks v2.1.1
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
187 lines
1 import { __ } from '@wordpress/i18n';
2 import { SelectControl, 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 atRule,
35 } = useBlockStyles();
36
37 const panelProps = {
38 name,
39 attributes,
40 setAttributes,
41 onStyleChange,
42 getStyleValue,
43 };
44
45 const icons = applyFilters(
46 'generateblocks.editor.iconSVGSets',
47 {
48 general: {
49 group: __( 'General', 'generateblocks' ),
50 svgs: generalSvgs,
51 },
52 social: {
53 group: __( 'Social', 'generateblocks' ),
54 svgs: socialSvgs,
55 },
56 },
57 { attributes }
58 );
59
60 return (
61 <ApplyFilters
62 name="generateblocks.editor.blockControls"
63 blockName={ name }
64 getStyleValue={ getStyleValue }
65 onStyleChange={ onStyleChange }
66 currentAtRule={ atRule }
67 attributes={ attributes }
68 setAttributes={ setAttributes }
69 >
70 <OpenPanel
71 { ...panelProps }
72 shouldRender={ 'a' === tagName && '' === atRule }
73 panelId="link-destination"
74 >
75 <URLControls
76 label={ __( 'Link Destination', 'generateblocks' ) }
77 setAttributes={ setAttributes }
78 htmlAttributes={ htmlAttributes }
79 context={ context }
80 tagName={ tagName }
81 />
82 </OpenPanel>
83
84 <OpenPanel
85 { ...panelProps }
86 shouldRender={ '' === atRule }
87 panelId="icon"
88 >
89 <IconControl
90 label={ __( 'Icon', 'generateblocks' ) }
91 value={ icon }
92 onChange={ ( value ) => {
93 // If the user hasn't done this before, align the icon and text.
94 if ( ! icon ) {
95 if ( ! getStyleValue( 'display' ) ) {
96 onStyleChange( 'display', 'inline-flex' );
97 }
98
99 if ( ! getStyleValue( 'alignItems' ) ) {
100 onStyleChange( 'alignItems', 'center' );
101 }
102
103 if ( ! getStyleValue( 'columnGap' ) ) {
104 onStyleChange( 'columnGap', '0.5em' );
105 }
106
107 if ( ! getStyleValue( 'width', '', '.gb-shape svg' ) ) {
108 onStyleChange( 'width', '1em', '', '.gb-shape svg' );
109 }
110
111 if ( ! getStyleValue( 'height', '', '.gb-shape svg' ) ) {
112 onStyleChange( 'height', '1em', '', '.gb-shape svg' );
113 }
114
115 if ( ! getStyleValue( 'fill', '', '.gb-shape svg' ) ) {
116 onStyleChange( 'fill', 'currentColor', '', '.gb-shape svg' );
117 }
118 }
119
120 setAttributes( { icon: value } );
121 } }
122 onClear={ () => setAttributes( { icon: '' } ) }
123 icons={ icons }
124 clearLabel={ __( 'Clear', 'generateblocks' ) }
125 openLabel={ __( 'Open Library', 'generateblocks' ) }
126 modalTitle={ __( 'Icon Library', 'generateblocks' ) }
127 />
128
129 { !! icon && (
130 <>
131 <ColorPicker
132 label={ __( 'Icon Color', 'generateblocks' ) }
133 value={ getStyleValue( 'color', atRule, '.gb-shape svg' ) }
134 onChange={ ( value ) => onStyleChange( 'color', value, atRule, '.gb-shape svg' ) }
135 />
136
137 { ! iconOnly && (
138 <SelectControl
139 label={ __( 'Icon Location', 'generateblocks' ) }
140 value={ iconLocation }
141 options={ [
142 { label: __( 'Before', 'generateblocks' ), value: 'before' },
143 { label: __( 'After', 'generateblocks' ), value: 'after' },
144 ] }
145 onChange={ ( value ) => setAttributes( { iconLocation: value } ) }
146 />
147 ) }
148
149 <BaseControl
150 label={ __( 'Icon Display', 'generateblocks' ) }
151 id="gb-icon-only"
152 >
153 <ToggleControl
154 id="gb-icon-only"
155 label={ __( 'Show the icon by itself', 'generateblocks' ) }
156 checked={ !! iconOnly }
157 onChange={ () => setAttributes( { iconOnly: ! iconOnly } ) }
158 />
159 </BaseControl>
160 </>
161 ) }
162 </OpenPanel>
163
164 <OpenPanel
165 { ...panelProps }
166 panelId="settings"
167 >
168 { '' === atRule && (
169 <TagNameControl
170 blockName="generateblocks/text"
171 value={ tagName }
172 onChange={ ( value ) => {
173 setAttributes( { tagName: value } );
174
175 if ( 'a' === value && ! getStyleValue( 'display', atRule ) ) {
176 onStyleChange( 'display', 'block' );
177 }
178 } }
179 />
180 ) }
181 </OpenPanel>
182
183 <DynamicTagsOnboarder />
184 </ApplyFilters>
185 );
186 }
187