PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.3
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.3
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / progress / edit.js

edit.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.3, at gutenberg/blocks/progress/edit.js

299 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import {
4 InspectorControls,
5 RichText,
6 useBlockProps,
7 } from '@wordpress/block-editor';
8 import {
9 PanelBody,
10 ResizableBox,
11 TabPanel,
12 TextControl,
13 ToggleControl,
14 } from '@wordpress/components';
15 import { applyFilters } from '@wordpress/hooks';
16 import { __ } from '@wordpress/i18n';
17
18 import ApplyFilters from '../../components/apply-filters';
19 import ColorIndicator from '../../components/color-indicator';
20 import ColorPicker from '../../components/color-picker';
21 import RangeControl from '../../components/range-control';
22
23 /**
24 * Block Edit Class.
25 *
26 * @param props
27 */
28 export default function BlockEdit(props) {
29 const { attributes, setAttributes, isSelected, toggleSelection } = props;
30
31 let { className = '' } = props;
32
33 const {
34 caption,
35 height,
36 percent,
37 borderRadius,
38 striped,
39 animateInViewport,
40 showCount,
41 countPrefix,
42 countSuffix,
43 color,
44 backgroundColor,
45 hoverColor,
46 hoverBackgroundColor,
47 } = attributes;
48
49 className = classnames('ghostkit-progress', className);
50
51 className = applyFilters('ghostkit.editor.className', className, props);
52
53 const blockProps = useBlockProps({ className });
54
55 return (
56 <>
57 <InspectorControls>
58 <PanelBody>
59 <RangeControl
60 label={__('Height', 'ghostkit')}
61 value={height || ''}
62 onChange={(value) => setAttributes({ height: value })}
63 min={1}
64 allowCustomMax
65 />
66 <RangeControl
67 label={__('Percent', 'ghostkit')}
68 value={percent || ''}
69 onChange={(value) => setAttributes({ percent: value })}
70 min={0}
71 max={100}
72 />
73 <RangeControl
74 label={__('Corner Radius', 'ghostkit')}
75 value={borderRadius}
76 min={0}
77 max={10}
78 onChange={(value) =>
79 setAttributes({ borderRadius: value })
80 }
81 allowCustomMax
82 />
83 </PanelBody>
84 <PanelBody>
85 <ToggleControl
86 label={__('Show Count', 'ghostkit')}
87 checked={!!showCount}
88 onChange={(val) => setAttributes({ showCount: val })}
89 />
90 {showCount ? (
91 <>
92 <TextControl
93 label={__('Count Prefix', 'ghostkit')}
94 value={countPrefix}
95 onChange={(value) =>
96 setAttributes({ countPrefix: value })
97 }
98 />
99 <TextControl
100 label={__('Count Suffix', 'ghostkit')}
101 value={countSuffix}
102 onChange={(value) =>
103 setAttributes({ countSuffix: value })
104 }
105 />
106 </>
107 ) : null}
108 <ToggleControl
109 label={__('Striped', 'ghostkit')}
110 checked={!!striped}
111 onChange={(val) => setAttributes({ striped: val })}
112 />
113 <ToggleControl
114 label={__('Animate in viewport', 'ghostkit')}
115 checked={!!animateInViewport}
116 onChange={(val) =>
117 setAttributes({ animateInViewport: val })
118 }
119 />
120 </PanelBody>
121 <PanelBody
122 title={
123 <>
124 {__('Colors', 'ghostkit')}
125 <ColorIndicator colorValue={color} />
126 <ColorIndicator colorValue={backgroundColor} />
127 </>
128 }
129 initialOpen={false}
130 >
131 <TabPanel
132 className="ghostkit-control-tabs ghostkit-control-tabs-wide"
133 tabs={[
134 {
135 name: 'normal',
136 title: __('Normal', 'ghostkit'),
137 className: 'ghostkit-control-tabs-tab',
138 },
139 {
140 name: 'hover',
141 title: __('Hover', 'ghostkit'),
142 className: 'ghostkit-control-tabs-tab',
143 },
144 ]}
145 >
146 {(tabData) => {
147 const isHover = tabData.name === 'hover';
148 return (
149 <>
150 <ApplyFilters
151 name="ghostkit.editor.controls"
152 attribute={
153 isHover ? 'hoverColor' : 'color'
154 }
155 props={props}
156 >
157 <ColorPicker
158 label={__('Bar', 'ghostkit')}
159 value={isHover ? hoverColor : color}
160 onChange={(val) =>
161 setAttributes(
162 isHover
163 ? { hoverColor: val }
164 : { color: val }
165 )
166 }
167 alpha
168 gradient
169 />
170 </ApplyFilters>
171 <ApplyFilters
172 name="ghostkit.editor.controls"
173 attribute={
174 isHover
175 ? 'hoverBackgroundColor'
176 : 'backgroundColor'
177 }
178 props={props}
179 >
180 <ColorPicker
181 label={__('Background', 'ghostkit')}
182 value={
183 isHover
184 ? hoverBackgroundColor
185 : backgroundColor
186 }
187 onChange={(val) =>
188 setAttributes(
189 isHover
190 ? {
191 hoverBackgroundColor:
192 val,
193 }
194 : {
195 backgroundColor:
196 val,
197 }
198 )
199 }
200 alpha
201 gradient
202 />
203 </ApplyFilters>
204 </>
205 );
206 }}
207 </TabPanel>
208 </PanelBody>
209 </InspectorControls>
210 <div {...blockProps}>
211 {!RichText.isEmpty(caption) || isSelected ? (
212 <RichText
213 inlineToolbar
214 tagName="div"
215 className="ghostkit-progress-caption"
216 placeholder={__('Write caption…', 'ghostkit')}
217 value={caption}
218 onChange={(newCaption) =>
219 setAttributes({ caption: newCaption })
220 }
221 />
222 ) : null}
223 {showCount ? (
224 <div
225 className="ghostkit-progress-bar-count"
226 style={{ width: `${percent}%` }}
227 >
228 <div>
229 {countPrefix}
230 {percent}
231 {countSuffix}
232 </div>
233 </div>
234 ) : null}
235 <ResizableBox
236 className={classnames({ 'is-selected': isSelected })}
237 size={{
238 width: '100%',
239 height,
240 }}
241 minWidth="0%"
242 maxWidth="100%"
243 minHeight="1"
244 enable={{ bottom: true }}
245 onResizeStart={() => {
246 toggleSelection(false);
247 }}
248 onResizeStop={(event, direction, elt, delta) => {
249 setAttributes({
250 height: parseInt(height + delta.height, 10),
251 });
252 toggleSelection(true);
253 }}
254 >
255 <div
256 className={classnames({
257 'ghostkit-progress-wrap': true,
258 'ghostkit-progress-bar-striped': striped,
259 })}
260 >
261 <ResizableBox
262 className={classnames('ghostkit-progress-bar', {
263 'is-selected': isSelected,
264 })}
265 size={{ width: `${percent}%` }}
266 minWidth="0%"
267 maxWidth="100%"
268 minHeight="100%"
269 maxHeight="100%"
270 enable={{ right: true }}
271 onResizeStart={() => {
272 toggleSelection(false);
273 }}
274 onResizeStop={(event, direction, elt, delta) => {
275 setAttributes({
276 percent: Math.min(
277 100,
278 Math.max(
279 0,
280 percent +
281 parseInt(
282 (100 * delta.width) /
283 elt.parentNode.getBoundingClientRect()
284 .width,
285 10
286 )
287 )
288 ),
289 });
290 toggleSelection(true);
291 }}
292 />
293 </div>
294 </ResizableBox>
295 </div>
296 </>
297 );
298 }
299