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 / extend / position / distance / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.3, at gutenberg/extend/position/distance/index.js

99 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 __experimentalToolsPanelItem as ExperimentalToolsPanelItem,
3 __stableToolsPanelItem as StableToolsPanelItem,
4 } from '@wordpress/components';
5 import { addFilter } from '@wordpress/hooks';
6 import { __ } from '@wordpress/i18n';
7
8 import InputGroup from '../../../components/input-group';
9 import useResponsive from '../../../hooks/use-responsive';
10 import useStyles from '../../../hooks/use-styles';
11
12 const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem;
13
14 import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
15
16 const allOptions = [
17 {
18 name: 'top',
19 label: __('Top', 'ghostkit'),
20 },
21 {
22 name: 'right',
23 label: __('Right', 'ghostkit'),
24 },
25 {
26 name: 'bottom',
27 label: __('Bottom', 'ghostkit'),
28 },
29 {
30 name: 'left',
31 label: __('left', 'ghostkit'),
32 },
33 ];
34
35 function PositionDistanceTools(props) {
36 const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props);
37
38 const { allDevices } = useResponsive();
39
40 let hasDistance = false;
41
42 ['', ...Object.keys(allDevices)].forEach((thisDevice) => {
43 allOptions.forEach((thisDistance) => {
44 hasDistance =
45 hasDistance || hasStyle(thisDistance.name, thisDevice);
46 });
47 });
48
49 return (
50 <ToolsPanelItem
51 label={__('Distance', 'ghostkit')}
52 hasValue={() => !!hasDistance}
53 onDeselect={() => {
54 resetStyles(
55 allOptions.map((item) => {
56 return item.name;
57 }),
58 true
59 );
60 }}
61 isShownByDefault={false}
62 >
63 <InputGroup
64 label={__('Distance', 'ghostkit')}
65 inputs={allOptions}
66 hasValue={(name, media) => hasStyle(name, media)}
67 getValue={(name, media) => getStyle(name, media)}
68 onChange={(name, value, media) =>
69 setStyles({ [name]: value }, media)
70 }
71 withResponsive
72 withImportant
73 expandOnFocus={6}
74 />
75 </ToolsPanelItem>
76 );
77 }
78
79 addFilter(
80 'ghostkit.extension.position.tools',
81 'ghostkit/extension/position/tools/distance',
82 (children, { props }) => {
83 const hasDistanceSupport =
84 hasBlockSupport(props.name, ['ghostkit', 'position', 'distance']) ||
85 getBlockSupport(props.name, ['ghostkit', 'position']) === true;
86
87 if (!hasDistanceSupport) {
88 return children;
89 }
90
91 return (
92 <>
93 {children}
94 <PositionDistanceTools {...props} />
95 </>
96 );
97 }
98 );
99