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 / spacings / margin / index.js

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

98 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: 'margin-top',
19 label: __('Top', 'ghostkit'),
20 },
21 {
22 name: 'margin-right',
23 label: __('Right', 'ghostkit'),
24 },
25 {
26 name: 'margin-bottom',
27 label: __('Bottom', 'ghostkit'),
28 },
29 {
30 name: 'margin-left',
31 label: __('left', 'ghostkit'),
32 },
33 ];
34
35 function SpacingsMarginTools(props) {
36 const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props);
37
38 const { allDevices } = useResponsive();
39
40 let hasMargin = false;
41
42 ['', ...Object.keys(allDevices)].forEach((thisDevice) => {
43 allOptions.forEach((thisMargin) => {
44 hasMargin = hasMargin || hasStyle(thisMargin.name, thisDevice);
45 });
46 });
47
48 return (
49 <ToolsPanelItem
50 label={__('Margin', 'ghostkit')}
51 hasValue={() => !!hasMargin}
52 onDeselect={() => {
53 resetStyles(
54 allOptions.map((item) => {
55 return item.name;
56 }),
57 true
58 );
59 }}
60 isShownByDefault={false}
61 >
62 <InputGroup
63 label={__('Margin', 'ghostkit')}
64 inputs={allOptions}
65 hasValue={(name, media) => hasStyle(name, media)}
66 getValue={(name, media) => getStyle(name, media)}
67 onChange={(name, value, media) =>
68 setStyles({ [name]: value }, media)
69 }
70 withResponsive
71 withImportant
72 expandOnFocus={6}
73 />
74 </ToolsPanelItem>
75 );
76 }
77
78 addFilter(
79 'ghostkit.extension.spacings.tools',
80 'ghostkit/extension/spacings/tools/margin',
81 (children, { props }) => {
82 const hasMarginSupport =
83 hasBlockSupport(props.name, ['ghostkit', 'spacings', 'margin']) ||
84 getBlockSupport(props.name, ['ghostkit', 'spacings']) === true;
85
86 if (!hasMarginSupport) {
87 return children;
88 }
89
90 return (
91 <>
92 {children}
93 <SpacingsMarginTools {...props} />
94 </>
95 );
96 }
97 );
98