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 / custom-css / overflow / index.js

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

156 lines 3.5 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 id={baseControlLabel} label={baseControlLabel}>
67 <Grid columns={2}>
68 <SelectControl
69 help={__('X', 'ghostkit')}
70 value={getStyle('overflow-x', device)}
71 onChange={(val) => {
72 setStyles({ 'overflow-x': val }, device);
73 }}
74 options={[
75 {
76 value: 'hidden',
77 label: __('Hidden', 'ghostkit'),
78 },
79 {
80 value: 'visible',
81 label: __('Visible', 'ghostkit'),
82 },
83 {
84 value: 'clip',
85 label: __('Clip', 'ghostkit'),
86 },
87 {
88 value: 'scroll',
89 label: __('Scroll', 'ghostkit'),
90 },
91 {
92 value: 'auto',
93 label: __('Auto', 'ghostkit'),
94 },
95 ]}
96 />
97 <SelectControl
98 help={__('Y', 'ghostkit')}
99 value={getStyle('overflow-y', device)}
100 onChange={(val) => {
101 setStyles({ 'overflow-y': val }, device);
102 }}
103 options={[
104 {
105 value: 'hidden',
106 label: __('Hidden', 'ghostkit'),
107 },
108 {
109 value: 'visible',
110 label: __('Visible', 'ghostkit'),
111 },
112 {
113 value: 'clip',
114 label: __('Clip', 'ghostkit'),
115 },
116 {
117 value: 'scroll',
118 label: __('Scroll', 'ghostkit'),
119 },
120 {
121 value: 'auto',
122 label: __('Auto', 'ghostkit'),
123 },
124 ]}
125 />
126 </Grid>
127 </BaseControl>
128 </ToolsPanelItem>
129 );
130 }
131
132 addFilter(
133 'ghostkit.extension.customCSS.tools',
134 'ghostkit/extension/customCSS/tools/overflow',
135 (children, { props }) => {
136 const hasOverflowSupport =
137 hasBlockSupport(props.name, [
138 'ghostkit',
139 'customCSS',
140 'overflow',
141 ]) ||
142 getBlockSupport(props.name, ['ghostkit', 'customCSS']) === true;
143
144 if (!hasOverflowSupport) {
145 return children;
146 }
147
148 return (
149 <>
150 {children}
151 <CustomCSSOverflowTools {...props} />
152 </>
153 );
154 }
155 );
156