PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
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.7.0, at gutenberg/blocks/progress/edit.js

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