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

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

114 lines 2.5 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 hoverSelector = '&:hover';
17
18 const allOptions = [
19 {
20 name: 'border-top-left-radius',
21 label: __('TL', 'ghostkit'),
22 },
23 {
24 name: 'border-top-right-radius',
25 label: __('TR', 'ghostkit'),
26 },
27 {
28 name: 'border-bottom-right-radius',
29 label: __('BR', 'ghostkit'),
30 },
31 {
32 name: 'border-bottom-left-radius',
33 label: __('BL', 'ghostkit'),
34 },
35 ];
36
37 function FrameBorderRadiusTools(props) {
38 const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props);
39 const { allDevices } = useResponsive();
40
41 let hasBorderRadius = false;
42
43 ['', ...Object.keys(allDevices)].forEach((thisDevice) => {
44 allOptions.forEach((thisProp) => {
45 hasBorderRadius =
46 hasBorderRadius ||
47 hasStyle(thisProp.name, thisDevice) ||
48 hasStyle(thisProp.name, thisDevice, hoverSelector);
49 });
50 });
51
52 return (
53 <ToolsPanelItem
54 label={__('Border Radius', 'ghostkit')}
55 hasValue={() => !!hasBorderRadius}
56 onDeselect={() => {
57 resetStyles(
58 allOptions.map((item) => {
59 return item.name;
60 }),
61 true,
62 ['', '&:hover']
63 );
64 }}
65 isShownByDefault={false}
66 >
67 <InputGroup
68 label={__('Border Radius', 'ghostkit')}
69 inputs={allOptions}
70 hasValue={(name, media, isHover) =>
71 hasStyle(name, media, isHover && hoverSelector)
72 }
73 getValue={(name, media, isHover) =>
74 getStyle(name, media, isHover && hoverSelector)
75 }
76 onChange={(name, value, media, isHover) =>
77 setStyles(
78 { [name]: value },
79 media,
80 isHover && hoverSelector
81 )
82 }
83 expandOnFocus={6}
84 withResponsive
85 withState
86 />
87 </ToolsPanelItem>
88 );
89 }
90
91 addFilter(
92 'ghostkit.extension.frame.tools',
93 'ghostkit/extension/frame/tools/borderRadius',
94 (children, { props }) => {
95 const hasBorderRadiusSupport =
96 hasBlockSupport(props.name, [
97 'ghostkit',
98 'frame',
99 'borderRadius',
100 ]) || getBlockSupport(props.name, ['ghostkit', 'frame']) === true;
101
102 if (!hasBorderRadiusSupport) {
103 return children;
104 }
105
106 return (
107 <>
108 {children}
109 <FrameBorderRadiusTools {...props} />
110 </>
111 );
112 }
113 );
114