| 1 |
import { |
| 2 |
__experimentalToolsPanelItem as ExperimentalToolsPanelItem, |
| 3 |
__stableToolsPanelItem as StableToolsPanelItem, |
| 4 |
SelectControl, |
| 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 CustomCSSUserSelectTools(props) { |
| 18 |
const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props); |
| 19 |
|
| 20 |
const { device, allDevices } = useResponsive(); |
| 21 |
|
| 22 |
let hasUserSelect = false; |
| 23 |
|
| 24 |
['', ...Object.keys(allDevices)].forEach((thisDevice) => { |
| 25 |
hasUserSelect = hasUserSelect || hasStyle('user-select', thisDevice); |
| 26 |
}); |
| 27 |
|
| 28 |
return ( |
| 29 |
<ToolsPanelItem |
| 30 |
label={__('User Select', 'ghostkit')} |
| 31 |
hasValue={() => !!hasUserSelect} |
| 32 |
onSelect={() => { |
| 33 |
if (!hasStyle('user-select')) { |
| 34 |
setStyles({ 'user-select': 'none' }); |
| 35 |
} |
| 36 |
}} |
| 37 |
onDeselect={() => { |
| 38 |
resetStyles(['user-select'], true); |
| 39 |
}} |
| 40 |
isShownByDefault={false} |
| 41 |
> |
| 42 |
<SelectControl |
| 43 |
label={ |
| 44 |
<> |
| 45 |
{__('User Select', 'ghostkit')} |
| 46 |
<ResponsiveToggle |
| 47 |
checkActive={(checkMedia) => { |
| 48 |
return hasStyle('user-select', checkMedia); |
| 49 |
}} |
| 50 |
/> |
| 51 |
</> |
| 52 |
} |
| 53 |
value={getStyle('user-select', device)} |
| 54 |
onChange={(val) => { |
| 55 |
setStyles({ 'user-select': val }, device); |
| 56 |
}} |
| 57 |
options={[ |
| 58 |
{ |
| 59 |
value: 'none', |
| 60 |
label: __('None', 'ghostkit'), |
| 61 |
}, |
| 62 |
{ |
| 63 |
value: 'auto', |
| 64 |
label: __('Auto', 'ghostkit'), |
| 65 |
}, |
| 66 |
]} |
| 67 |
/> |
| 68 |
</ToolsPanelItem> |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
addFilter( |
| 73 |
'ghostkit.extension.customCSS.tools', |
| 74 |
'ghostkit/extension/customCSS/tools/userSelect', |
| 75 |
(children, { props }) => { |
| 76 |
const hasUserSelectSupport = |
| 77 |
hasBlockSupport(props.name, [ |
| 78 |
'ghostkit', |
| 79 |
'customCSS', |
| 80 |
'userSelect', |
| 81 |
]) || |
| 82 |
getBlockSupport(props.name, ['ghostkit', 'customCSS']) === true; |
| 83 |
|
| 84 |
if (!hasUserSelectSupport) { |
| 85 |
return children; |
| 86 |
} |
| 87 |
|
| 88 |
return ( |
| 89 |
<> |
| 90 |
{children} |
| 91 |
<CustomCSSUserSelectTools {...props} /> |
| 92 |
</> |
| 93 |
); |
| 94 |
} |
| 95 |
); |
| 96 |
|