PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.4.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.4.1
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 / custom-css / overflow / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.4.1, at gutenberg/extend/custom-css/overflow/index.js

164 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 __experimentalGrid as ExperimentalGrid,
3 __experimentalToolsPanelItem as ExperimentalToolsPanelItem,
4 __stableGrid as StableGrid,
5 __stableToolsPanelItem as StableToolsPanelItem,
6 BaseControl,
7 SelectControl,
8 } from '@wordpress/components';
9 import { addFilter } from '@wordpress/hooks';
10 import { __ } from '@wordpress/i18n';
11
12 import ResponsiveToggle from '../../../components/responsive-toggle';
13 import useResponsive from '../../../hooks/use-responsive';
14 import useStyles from '../../../hooks/use-styles';
15
16 const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem;
17 const Grid = StableGrid || ExperimentalGrid;
18
19 import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
20
21 function CustomCSSOverflowTools(props) {
22 const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props);
23
24 const { device, allDevices } = useResponsive();
25
26 let hasOverflow = false;
27
28 ['', ...Object.keys(allDevices)].forEach((thisDevice) => {
29 hasOverflow =
30 hasOverflow ||
31 hasStyle('overflow-x', thisDevice) ||
32 hasStyle('overflow-y', thisDevice);
33 });
34
35 const baseControlLabel = (
36 <>
37 {__('Overflow', 'ghostkit')}
38 <ResponsiveToggle
39 checkActive={(checkMedia) => {
40 return (
41 hasStyle('overflow-x', checkMedia) ||
42 hasStyle('overflow-y', checkMedia)
43 );
44 }}
45 />
46 </>
47 );
48
49 return (
50 <ToolsPanelItem
51 label={__('Overflow', 'ghostkit')}
52 hasValue={() => !!hasOverflow}
53 onSelect={() => {
54 if (!hasStyle('overflow-x') || !hasStyle('overflow-y')) {
55 setStyles({
56 'overflow-x': 'hidden',
57 'overflow-y': 'hidden',
58 });
59 }
60 }}
61 onDeselect={() => {
62 resetStyles(['overflow-x', 'overflow-y'], true);
63 }}
64 isShownByDefault={false}
65 >
66 <BaseControl
67 id={baseControlLabel}
68 label={baseControlLabel}
69 __nextHasNoMarginBottom
70 >
71 <Grid columns={2}>
72 <SelectControl
73 help={__('X', 'ghostkit')}
74 value={getStyle('overflow-x', device)}
75 onChange={(val) => {
76 setStyles({ 'overflow-x': val }, device);
77 }}
78 options={[
79 {
80 value: 'hidden',
81 label: __('Hidden', 'ghostkit'),
82 },
83 {
84 value: 'visible',
85 label: __('Visible', 'ghostkit'),
86 },
87 {
88 value: 'clip',
89 label: __('Clip', 'ghostkit'),
90 },
91 {
92 value: 'scroll',
93 label: __('Scroll', 'ghostkit'),
94 },
95 {
96 value: 'auto',
97 label: __('Auto', 'ghostkit'),
98 },
99 ]}
100 __next40pxDefaultSize
101 __nextHasNoMarginBottom
102 />
103 <SelectControl
104 help={__('Y', 'ghostkit')}
105 value={getStyle('overflow-y', device)}
106 onChange={(val) => {
107 setStyles({ 'overflow-y': val }, device);
108 }}
109 options={[
110 {
111 value: 'hidden',
112 label: __('Hidden', 'ghostkit'),
113 },
114 {
115 value: 'visible',
116 label: __('Visible', 'ghostkit'),
117 },
118 {
119 value: 'clip',
120 label: __('Clip', 'ghostkit'),
121 },
122 {
123 value: 'scroll',
124 label: __('Scroll', 'ghostkit'),
125 },
126 {
127 value: 'auto',
128 label: __('Auto', 'ghostkit'),
129 },
130 ]}
131 __next40pxDefaultSize
132 __nextHasNoMarginBottom
133 />
134 </Grid>
135 </BaseControl>
136 </ToolsPanelItem>
137 );
138 }
139
140 addFilter(
141 'ghostkit.extension.customCSS.tools',
142 'ghostkit/extension/customCSS/tools/overflow',
143 (children, { props }) => {
144 const hasOverflowSupport =
145 hasBlockSupport(props.name, [
146 'ghostkit',
147 'customCSS',
148 'overflow',
149 ]) ||
150 getBlockSupport(props.name, ['ghostkit', 'customCSS']) === true;
151
152 if (!hasOverflowSupport) {
153 return children;
154 }
155
156 return (
157 <>
158 {children}
159 <CustomCSSOverflowTools {...props} />
160 </>
161 );
162 }
163 );
164