PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.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 / transition-presets-control / index.js

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

85 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useState } from '@wordpress/element';
2 import { __ } from '@wordpress/i18n';
3
4 import Select from '../select';
5 import PRESETS from './presets';
6
7 export default function TransitionPresetsControl(props) {
8 const { label, value, onChange } = props;
9
10 const [preset, setPreset] = useState();
11
12 // Find default preset
13 useEffect(() => {
14 let newPreset = 'custom';
15
16 const currentReveal = { ...(value || {}) };
17
18 // Remove transition from the comparison.
19 if (currentReveal?.transition) {
20 delete currentReveal.transition;
21 }
22
23 Object.keys(PRESETS).forEach((slug) => {
24 const presetData = { ...PRESETS[slug].data };
25
26 // Remove transition from the comparison.
27 if (presetData?.transition) {
28 delete presetData.transition;
29 }
30
31 if (JSON.stringify(currentReveal) === JSON.stringify(presetData)) {
32 newPreset = slug;
33 }
34 });
35
36 setPreset(newPreset);
37 }, [preset, value]);
38
39 const presetOptions = [
40 ...(preset === 'custom'
41 ? [
42 {
43 value: 'custom',
44 label: __('-- Presets --', 'ghostkit'),
45 },
46 ]
47 : []),
48 ...Object.keys(PRESETS).map((name) => {
49 return {
50 value: name,
51 label: PRESETS[name].label,
52 icon: PRESETS[name].icon,
53 };
54 }),
55 ];
56
57 const presetValue = {
58 value: preset,
59 label: preset,
60 };
61
62 // Find actual label.
63 if (presetValue.value) {
64 presetOptions.forEach((presetData) => {
65 if (presetValue.value === presetData.value) {
66 presetValue.label = presetData.label;
67 }
68 });
69 }
70
71 return (
72 <Select
73 label={label}
74 value={presetValue}
75 onChange={(val) => {
76 if (PRESETS?.[val.value]?.data) {
77 onChange(PRESETS[val.value].data);
78 }
79 }}
80 options={presetOptions}
81 isSearchable={false}
82 />
83 );
84 }
85