/** * Some code of the Drawer component is based on the Modal component from Gutenberg: * https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/modal/index.tsx */ /** * External dependencies */ import classNames from 'classnames'; import { useDebounce } from 'use-debounce'; import type { ForwardedRef, KeyboardEvent, RefObject } from 'react'; import { __ } from '@wordpress/i18n'; import { createPortal, useEffect, useRef, forwardRef, } from '@wordpress/element'; import { close } from '@wordpress/icons'; import { useFocusReturn, useFocusOnMount, useConstrainedTabbing, useMergeRefs, } from '@wordpress/compose'; /** * Internal dependencies */ import Button from '../button'; import * as ariaHelper from './utils/aria-helper'; import './style.scss'; interface DrawerProps { children: JSX.Element; className?: string; isOpen: boolean; onClose: () => void; slideIn?: boolean; slideOut?: boolean; } interface CloseButtonPortalProps { onClick: () => void; contentRef: RefObject< HTMLDivElement >; } const CloseButtonPortal = ( { onClick, contentRef, }: CloseButtonPortalProps ) => { const closeButtonWrapper = contentRef?.current?.querySelector( '.wc-block-components-drawer__close-wrapper' ); return closeButtonWrapper ? createPortal(