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

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

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