diff --git a/packages/components/src/drop-zone/index.tsx b/packages/components/src/drop-zone/index.tsx index f620e6a03c6b85..95900897acbe69 100644 --- a/packages/components/src/drop-zone/index.tsx +++ b/packages/components/src/drop-zone/index.tsx @@ -25,6 +25,71 @@ import { import type { DropType, DropZoneProps } from './types'; import type { WordPressComponentProps } from '../context'; +function DropIndicator( { label }: { label?: string } ) { + const disableMotion = useReducedMotion(); + const backdrop = { + hidden: { opacity: 0 }, + show: { + opacity: 1, + transition: { + type: 'tween', + duration: 0.2, + delay: 0, + delayChildren: 0.1, + }, + }, + exit: { + opacity: 0, + transition: { + duration: 0.2, + delayChildren: 0, + }, + }, + }; + + const foreground = { + hidden: { opacity: 0, scale: 0.9 }, + show: { + opacity: 1, + scale: 1, + transition: { + duration: 0.1, + }, + }, + exit: { opacity: 0, scale: 0.9 }, + }; + + const children = ( + + + + + { label ? label : __( 'Drop files to upload' ) } + + + + ); + + if ( disableMotion ) { + return children; + } + + return { children }; +} + /** * `DropZone` is a component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event. * @@ -116,67 +181,6 @@ export function DropZoneComponent( { setIsDraggingOverElement( false ); }, } ); - const disableMotion = useReducedMotion(); - - let children; - const backdrop = { - hidden: { opacity: 0 }, - show: { - opacity: 1, - transition: { - type: 'tween', - duration: 0.2, - delay: 0, - delayChildren: 0.1, - }, - }, - exit: { - opacity: 0, - transition: { - duration: 0.2, - delayChildren: 0, - }, - }, - }; - - const foreground = { - hidden: { opacity: 0, scale: 0.9 }, - show: { - opacity: 1, - scale: 1, - transition: { - duration: 0.1, - }, - }, - exit: { opacity: 0, scale: 0.9 }, - }; - - if ( isDraggingOverElement ) { - children = ( - - - - - { label ? label : __( 'Drop files to upload' ) } - - - - ); - } - const classes = classnames( 'components-drop-zone', className, { 'is-active': ( isDraggingOverDocument || isDraggingOverElement ) && @@ -190,11 +194,7 @@ export function DropZoneComponent( { return (
- { disableMotion ? ( - children - ) : ( - { children } - ) } + { isDraggingOverElement && }
); }