| 1 |
import { |
| 2 |
__experimentalToolsPanelItem as ExperimentalToolsPanelItem, |
| 3 |
__stableToolsPanelItem as StableToolsPanelItem, |
| 4 |
SelectControl, |
| 5 |
TextareaControl, |
| 6 |
} from '@wordpress/components'; |
| 7 |
import { addFilter } from '@wordpress/hooks'; |
| 8 |
import { __ } from '@wordpress/i18n'; |
| 9 |
|
| 10 |
import ResponsiveToggle from '../../../components/responsive-toggle'; |
| 11 |
import useResponsive from '../../../hooks/use-responsive'; |
| 12 |
import useStyles from '../../../hooks/use-styles'; |
| 13 |
import PRESETS from './presets'; |
| 14 |
|
| 15 |
const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem; |
| 16 |
|
| 17 |
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks'; |
| 18 |
|
| 19 |
const optionPresets = [ |
| 20 |
{ |
| 21 |
value: '', |
| 22 |
label: __('Custom', 'ghostkit'), |
| 23 |
}, |
| 24 |
...Object.keys(PRESETS).map((value) => { |
| 25 |
return { |
| 26 |
value, |
| 27 |
label: PRESETS[value], |
| 28 |
}; |
| 29 |
}), |
| 30 |
]; |
| 31 |
|
| 32 |
function CustomCSSClipPathTools(props) { |
| 33 |
const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props); |
| 34 |
|
| 35 |
const { device, allDevices } = useResponsive(); |
| 36 |
|
| 37 |
let hasClipPath = false; |
| 38 |
|
| 39 |
['', ...Object.keys(allDevices)].forEach((thisDevice) => { |
| 40 |
hasClipPath = hasClipPath || hasStyle('clip-path', thisDevice); |
| 41 |
}); |
| 42 |
|
| 43 |
return ( |
| 44 |
<ToolsPanelItem |
| 45 |
label={__('Clip Path', 'ghostkit')} |
| 46 |
hasValue={() => !!hasClipPath} |
| 47 |
onSelect={() => { |
| 48 |
if (!hasStyle('clip-path')) { |
| 49 |
setStyles({ 'clip-path': optionPresets[1].value }); |
| 50 |
} |
| 51 |
}} |
| 52 |
onDeselect={() => { |
| 53 |
resetStyles(['clip-path'], true); |
| 54 |
}} |
| 55 |
isShownByDefault={false} |
| 56 |
> |
| 57 |
<SelectControl |
| 58 |
label={ |
| 59 |
<> |
| 60 |
{__('Clip Path', 'ghostkit')} |
| 61 |
<ResponsiveToggle |
| 62 |
checkActive={(checkMedia) => { |
| 63 |
return hasStyle('clip-path', checkMedia); |
| 64 |
}} |
| 65 |
/> |
| 66 |
</> |
| 67 |
} |
| 68 |
value={getStyle('clip-path', device)} |
| 69 |
onChange={(val) => { |
| 70 |
setStyles({ 'clip-path': val }, device); |
| 71 |
}} |
| 72 |
options={optionPresets} |
| 73 |
/> |
| 74 |
<br /> |
| 75 |
<TextareaControl |
| 76 |
value={getStyle('clip-path', device)} |
| 77 |
onChange={(val) => { |
| 78 |
setStyles({ 'clip-path': val }, device); |
| 79 |
}} |
| 80 |
/> |
| 81 |
</ToolsPanelItem> |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
addFilter( |
| 86 |
'ghostkit.extension.customCSS.tools', |
| 87 |
'ghostkit/extension/customCSS/tools/clipPath', |
| 88 |
(children, { props }) => { |
| 89 |
const hasClipPathSupport = |
| 90 |
hasBlockSupport(props.name, [ |
| 91 |
'ghostkit', |
| 92 |
'customCSS', |
| 93 |
'clipPath', |
| 94 |
]) || |
| 95 |
getBlockSupport(props.name, ['ghostkit', 'customCSS']) === true; |
| 96 |
|
| 97 |
if (!hasClipPathSupport) { |
| 98 |
return children; |
| 99 |
} |
| 100 |
|
| 101 |
return ( |
| 102 |
<> |
| 103 |
{children} |
| 104 |
<CustomCSSClipPathTools {...props} /> |
| 105 |
</> |
| 106 |
); |
| 107 |
} |
| 108 |
); |
| 109 |
|