PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
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 / components / range-control / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at gutenberg/components/range-control/index.js

68 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BaseControl, RangeControl, TextControl } from '@wordpress/components';
2 import { useEffect, useState } from '@wordpress/element';
3
4 /**
5 * Component Class
6 *
7 * @param root0
8 * @param root0.allowCustomMin
9 * @param root0.allowCustomMax
10 * @param root0.label
11 */
12 export default function CustomRangeControl({
13 allowCustomMin,
14 allowCustomMax,
15 label,
16 ...props
17 }) {
18 const [min, setMin] = useState(parseFloat(props.min) || 0);
19 const [max, setMax] = useState(parseFloat(props.max) || 100);
20
21 useEffect(() => {
22 if (allowCustomMin && props.value && props.value < min) {
23 setMin(props.value);
24 }
25 if (allowCustomMax && props.value && props.value > max) {
26 setMax(props.value);
27 }
28 // eslint-disable-next-line react-hooks/exhaustive-deps
29 }, [props.value]);
30
31 if (allowCustomMin || allowCustomMax) {
32 return (
33 <BaseControl
34 id={label}
35 label={label}
36 className="ghostkit-component-range-control"
37 >
38 <RangeControl
39 {...props}
40 min={min}
41 max={max}
42 withInputField={false}
43 />
44 <TextControl
45 type="number"
46 value={props.value}
47 min={min}
48 max={max}
49 step={props.step}
50 onChange={(val) => {
51 const result = val === '' ? undefined : parseFloat(val);
52
53 if (!allowCustomMin && val < min) {
54 props.onChange(min);
55 } else if (!allowCustomMax && val > max) {
56 props.onChange(max);
57 } else {
58 props.onChange(result);
59 }
60 }}
61 />
62 </BaseControl>
63 );
64 }
65
66 return <RangeControl {...props} label={label} min={min} max={max} />;
67 }
68