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 / extend / effects / reveal / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/extend/effects/reveal/index.js

245 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { cloneDeep } from 'lodash';
2
3 import {
4 __experimentalGrid as ExperimentalGrid,
5 __experimentalNumberControl as ExperimentalNumberControl,
6 __experimentalToolsPanelItem as ExperimentalToolsPanelItem,
7 __stableGrid as StableGrid,
8 __stableNumberControl as StableNumberControl,
9 __stableToolsPanelItem as StableToolsPanelItem,
10 } from '@wordpress/components';
11 import { addFilter } from '@wordpress/hooks';
12 import { __ } from '@wordpress/i18n';
13
14 import DropdownPicker from '../../../components/dropdown-picker';
15 import EditorStyles from '../../../components/editor-styles';
16 import ProNote from '../../../components/pro-note';
17 import TransitionPresetsControl from '../../../components/transition-presets-control';
18 import TransitionSelector from '../../../components/transition-selector';
19 import DEFAULTS from './defaults';
20
21 const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem;
22 const NumberControl = StableNumberControl || ExperimentalNumberControl;
23 const Grid = StableGrid || ExperimentalGrid;
24 const { version } = window.ghostkitVariables;
25
26 import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
27
28 function EffectsRevealTools(props) {
29 const { attributes, setAttributes, clientId } = props;
30
31 const hasReveal = attributes?.ghostkit?.effects?.reveal;
32
33 function getValue(prop, defaultValue) {
34 if (
35 typeof attributes?.ghostkit?.effects?.reveal?.[prop] === 'undefined'
36 ) {
37 return defaultValue;
38 }
39
40 return attributes.ghostkit.effects.reveal[prop];
41 }
42
43 function updateValue(newData, reset = false) {
44 const ghostkitData = cloneDeep(attributes?.ghostkit || {});
45
46 if (typeof ghostkitData?.effects === 'undefined') {
47 ghostkitData.effects = {};
48 }
49
50 // Reset all values except transition.
51 if (reset || typeof ghostkitData?.effects?.reveal === 'undefined') {
52 if (ghostkitData.effects.reveal?.transition) {
53 ghostkitData.effects.reveal = {
54 transition: ghostkitData.effects.reveal.transition,
55 };
56 } else {
57 ghostkitData.effects.reveal = {};
58 }
59 }
60
61 Object.keys(newData).forEach((prop) => {
62 ghostkitData.effects.reveal[prop] = newData[prop];
63 });
64
65 setAttributes({ ghostkit: ghostkitData });
66 }
67
68 return (
69 <ToolsPanelItem
70 label={__('Reveal', 'ghostkit')}
71 hasValue={() => !!hasReveal}
72 onSelect={() => {
73 if (
74 typeof attributes?.ghostkit?.effects?.reveal === 'undefined'
75 ) {
76 const ghostkitData = cloneDeep(attributes?.ghostkit || {});
77
78 ghostkitData.effects = {
79 ...ghostkitData.effects,
80 reveal: {
81 opacity: 0,
82 },
83 };
84
85 setAttributes({ ghostkit: ghostkitData });
86 }
87 }}
88 onDeselect={() => {
89 if (
90 typeof attributes?.ghostkit?.effects?.reveal !== 'undefined'
91 ) {
92 const ghostkitData = cloneDeep(attributes?.ghostkit || {});
93
94 delete ghostkitData?.effects?.reveal;
95
96 setAttributes({ ghostkit: ghostkitData });
97 }
98 }}
99 isShownByDefault={false}
100 >
101 <DropdownPicker
102 label={__('Reveal', 'ghostkit')}
103 contentClassName="ghostkit-component-effects-reveal"
104 >
105 <EditorStyles
106 styles={`
107 [data-block="${clientId}"] {
108 transform: translateX(${getValue('x', DEFAULTS.x)}px) translateY(${getValue(
109 'y',
110 DEFAULTS.y
111 )}px) scale(${getValue('scale', DEFAULTS.scale)}) rotate(${getValue(
112 'rotate',
113 DEFAULTS.rotate
114 )}deg);
115 opacity: ${Math.max(0.1, getValue('opacity', DEFAULTS.opacity))};
116 }
117 `}
118 />
119 <TransitionPresetsControl
120 value={hasReveal}
121 onChange={(data) => {
122 updateValue(data, true);
123 }}
124 />
125 <Grid columns={2}>
126 <NumberControl
127 label={__('X', 'ghostkit')}
128 value={getValue('x')}
129 placeholder={DEFAULTS.x}
130 onChange={(val) => {
131 updateValue({
132 x: val === '' ? undefined : parseFloat(val),
133 });
134 }}
135 suffix="px&nbsp;"
136 style={{ flex: 1 }}
137 />
138 <NumberControl
139 label={__('Y', 'ghostkit')}
140 value={getValue('y')}
141 placeholder={DEFAULTS.y}
142 onChange={(val) =>
143 updateValue({
144 y: val === '' ? undefined : parseFloat(val),
145 })
146 }
147 suffix="px&nbsp;"
148 style={{ flex: 1 }}
149 />
150 </Grid>
151 <Grid columns={3}>
152 <NumberControl
153 label={__('Opacity', 'ghostkit')}
154 value={getValue('opacity')}
155 placeholder={DEFAULTS.opacity}
156 onChange={(val) =>
157 updateValue({
158 opacity:
159 val === '' ? undefined : parseFloat(val),
160 })
161 }
162 min={0}
163 max={1}
164 step={0.01}
165 style={{ flex: 1 }}
166 />
167 <NumberControl
168 label={__('Scale', 'ghostkit')}
169 value={getValue('scale')}
170 placeholder={DEFAULTS.scale}
171 onChange={(val) =>
172 updateValue({
173 scale: val === '' ? undefined : parseFloat(val),
174 })
175 }
176 min={0}
177 max={10}
178 step={0.01}
179 style={{ flex: 1 }}
180 />
181 <NumberControl
182 label={__('Rotate', 'ghostkit')}
183 value={getValue('rotate')}
184 placeholder={DEFAULTS.rotate}
185 onChange={(val) =>
186 updateValue({
187 rotate:
188 val === '' ? undefined : parseFloat(val),
189 })
190 }
191 suffix="deg&nbsp;"
192 style={{ flex: 1 }}
193 />
194 </Grid>
195 <TransitionSelector
196 label={__('Transition', 'ghostkit')}
197 value={getValue('transition', DEFAULTS.transition)}
198 onChange={(val) => updateValue({ transition: val })}
199 />
200 <ProNote title={__('Pro Settings', 'ghostkit')} collapsed>
201 <p>
202 {__(
203 'Advanced reveal settings are available in the Ghost Kit Pro plugin only:',
204 'ghostkit'
205 )}
206 </p>
207 <ul>
208 <li>{__('3D Rotation', 'ghostkit')}</li>
209 <li>{__('Custom Viewport', 'ghostkit')}</li>
210 <li>{__('Replay Animation', 'ghostkit')}</li>
211 </ul>
212 <ProNote.Button
213 target="_blank"
214 rel="noopener noreferrer"
215 href={`https://www.ghostkit.io/docs/extensions/effects/?utm_source=plugin&utm_medium=block_settings&utm_campaign=pro_effects&utm_content=${version}`}
216 >
217 {__('Read More', 'ghostkit')}
218 </ProNote.Button>
219 </ProNote>
220 </DropdownPicker>
221 </ToolsPanelItem>
222 );
223 }
224
225 addFilter(
226 'ghostkit.extension.effects.tools',
227 'ghostkit/extension/effects/reveal',
228 (children, { props }) => {
229 const hasRevealSupport =
230 hasBlockSupport(props.name, ['ghostkit', 'effects', 'reveal']) ||
231 getBlockSupport(props.name, ['ghostkit', 'effects']) === true;
232
233 if (!hasRevealSupport) {
234 return children;
235 }
236
237 return (
238 <>
239 {children}
240 <EffectsRevealTools {...props} />
241 </>
242 );
243 }
244 );
245