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

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

90 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 RangeControl,
5 } from '@wordpress/components';
6 import { addFilter } from '@wordpress/hooks';
7 import { __ } from '@wordpress/i18n';
8
9 import ResponsiveToggle from '../../../components/responsive-toggle';
10 import useResponsive from '../../../hooks/use-responsive';
11 import useStyles from '../../../hooks/use-styles';
12
13 const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem;
14
15 import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
16
17 function CustomCSSOpacityTools(props) {
18 const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props);
19
20 const { device, allDevices } = useResponsive();
21
22 let hasOpacity = false;
23
24 ['', ...Object.keys(allDevices)].forEach((thisDevice) => {
25 hasOpacity = hasOpacity || hasStyle('opacity', thisDevice);
26 });
27
28 return (
29 <ToolsPanelItem
30 label={__('Opacity', 'ghostkit')}
31 hasValue={() => !!hasOpacity}
32 onSelect={() => {
33 if (!hasStyle('opacity')) {
34 setStyles({ opacity: 1 });
35 }
36 }}
37 onDeselect={() => {
38 resetStyles(['opacity'], true);
39 }}
40 isShownByDefault={false}
41 >
42 <RangeControl
43 label={
44 <>
45 {__('Opacity', 'ghostkit')}
46 <ResponsiveToggle
47 checkActive={(checkMedia) => {
48 return hasStyle('opacity', checkMedia);
49 }}
50 />
51 </>
52 }
53 value={getStyle('opacity', device)}
54 placeholder={1}
55 onChange={(val) =>
56 setStyles(
57 { opacity: val === '' ? undefined : parseFloat(val) },
58 device
59 )
60 }
61 min={0}
62 max={1}
63 step={0.01}
64 style={{ flex: 1 }}
65 />
66 </ToolsPanelItem>
67 );
68 }
69
70 addFilter(
71 'ghostkit.extension.customCSS.tools',
72 'ghostkit/extension/customCSS/tools/opacity',
73 (children, { props }) => {
74 const hasOpacitySupport =
75 hasBlockSupport(props.name, ['ghostkit', 'customCSS', 'opacity']) ||
76 getBlockSupport(props.name, ['ghostkit', 'customCSS']) === true;
77
78 if (!hasOpacitySupport) {
79 return children;
80 }
81
82 return (
83 <>
84 {children}
85 <CustomCSSOpacityTools {...props} />
86 </>
87 );
88 }
89 );
90