| 1 |
import { |
| 2 |
__experimentalNumberControl as ExperimentalNumberControl, |
| 3 |
__experimentalToolsPanelItem as ExperimentalToolsPanelItem, |
| 4 |
__stableNumberControl as StableNumberControl, |
| 5 |
__stableToolsPanelItem as StableToolsPanelItem, |
| 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 |
|
| 14 |
const ToolsPanelItem = StableToolsPanelItem || ExperimentalToolsPanelItem; |
| 15 |
const NumberControl = StableNumberControl || ExperimentalNumberControl; |
| 16 |
|
| 17 |
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks'; |
| 18 |
|
| 19 |
function PositionZIndexTools(props) { |
| 20 |
const { getStyle, hasStyle, setStyles, resetStyles } = useStyles(props); |
| 21 |
|
| 22 |
const { device, allDevices } = useResponsive(); |
| 23 |
|
| 24 |
let hasZIndex = false; |
| 25 |
|
| 26 |
['', ...Object.keys(allDevices)].forEach((thisDevice) => { |
| 27 |
hasZIndex = hasZIndex || hasStyle('z-index', thisDevice); |
| 28 |
}); |
| 29 |
|
| 30 |
return ( |
| 31 |
<ToolsPanelItem |
| 32 |
label={__('zIndex', 'ghostkit')} |
| 33 |
hasValue={() => !!hasZIndex} |
| 34 |
onDeselect={() => { |
| 35 |
resetStyles(['z-index'], true); |
| 36 |
}} |
| 37 |
isShownByDefault={false} |
| 38 |
> |
| 39 |
<NumberControl |
| 40 |
label={ |
| 41 |
<> |
| 42 |
{__('zIndex', 'ghostkit')} |
| 43 |
<ResponsiveToggle |
| 44 |
checkActive={(checkMedia) => { |
| 45 |
return hasStyle('z-index', checkMedia); |
| 46 |
}} |
| 47 |
/> |
| 48 |
</> |
| 49 |
} |
| 50 |
value={getStyle('z-index', device)} |
| 51 |
onChange={(val) => { |
| 52 |
setStyles({ 'z-index': val }, device); |
| 53 |
}} |
| 54 |
labelPosition="edge" |
| 55 |
__unstableInputWidth="70px" |
| 56 |
/> |
| 57 |
</ToolsPanelItem> |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
addFilter( |
| 62 |
'ghostkit.extension.position.tools', |
| 63 |
'ghostkit/extension/position/tools/zIndex', |
| 64 |
(children, { props }) => { |
| 65 |
const hasZIndexSupport = |
| 66 |
hasBlockSupport(props.name, ['ghostkit', 'position', 'zIndex']) || |
| 67 |
getBlockSupport(props.name, ['ghostkit', 'position']) === true; |
| 68 |
|
| 69 |
if (!hasZIndexSupport) { |
| 70 |
return children; |
| 71 |
} |
| 72 |
|
| 73 |
return ( |
| 74 |
<> |
| 75 |
{children} |
| 76 |
<PositionZIndexTools {...props} /> |
| 77 |
</> |
| 78 |
); |
| 79 |
} |
| 80 |
); |
| 81 |
|