|
| 1 | +/** |
| 2 | + * WordPress dependencies |
| 3 | + */ |
| 4 | +import { useSelect } from '@wordpress/data'; |
| 5 | +import { useReducedMotion } from '@wordpress/compose'; |
| 6 | +import { __unstableMotion as motion } from '@wordpress/components'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Internal dependencies |
| 10 | + */ |
| 11 | +import { store as blockEditorStore } from '../../store'; |
| 12 | +import BlockPopover from './index'; |
| 13 | + |
| 14 | +const animateVariants = { |
| 15 | + hide: { opacity: 0, scaleY: 0.75 }, |
| 16 | + show: { opacity: 1, scaleY: 1 }, |
| 17 | + exit: { opacity: 0, scaleY: 0.9 }, |
| 18 | +}; |
| 19 | + |
| 20 | +function BlockDropZonePopover( { |
| 21 | + __unstablePopoverSlot, |
| 22 | + __unstableContentRef, |
| 23 | +} ) { |
| 24 | + const { clientId } = useSelect( ( select ) => { |
| 25 | + const { getBlockOrder, getBlockInsertionPoint } = |
| 26 | + select( blockEditorStore ); |
| 27 | + const insertionPoint = getBlockInsertionPoint(); |
| 28 | + const order = getBlockOrder( insertionPoint.rootClientId ); |
| 29 | + |
| 30 | + if ( ! order.length ) { |
| 31 | + return {}; |
| 32 | + } |
| 33 | + |
| 34 | + return { |
| 35 | + clientId: order[ insertionPoint.index ], |
| 36 | + }; |
| 37 | + }, [] ); |
| 38 | + const reducedMotion = useReducedMotion(); |
| 39 | + |
| 40 | + return ( |
| 41 | + <BlockPopover |
| 42 | + clientId={ clientId } |
| 43 | + __unstableCoverTarget |
| 44 | + __unstablePopoverSlot={ __unstablePopoverSlot } |
| 45 | + __unstableContentRef={ __unstableContentRef } |
| 46 | + className="block-editor-block-popover__drop-zone" |
| 47 | + > |
| 48 | + <motion.div |
| 49 | + data-testid="block-popover-drop-zone" |
| 50 | + initial={ |
| 51 | + reducedMotion ? animateVariants.show : animateVariants.hide |
| 52 | + } |
| 53 | + animate={ animateVariants.show } |
| 54 | + exit={ |
| 55 | + reducedMotion ? animateVariants.show : animateVariants.exit |
| 56 | + } |
| 57 | + className="block-editor-block-popover__drop-zone-foreground" |
| 58 | + /> |
| 59 | + </BlockPopover> |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +export default BlockDropZonePopover; |
0 commit comments