import * as React from 'react'; import { type PortalProps } from '@radix-ui/react-portal'; import { Presence } from '@radix-ui/react-presence'; import type * as Radix from '@radix-ui/react-primitive'; import { Primitive } from '@radix-ui/react-primitive'; import { RemoveScroll } from 'react-remove-scroll'; import { cn } from '../../utils/cn'; import { composeEventHandlers } from '../../utils/compose-event-handler'; import { withAttr } from '../../utils/withAttr'; import { useSidebarContext } from './sidebar.context'; type SidebarOverlayImplElement = React.ElementRef; type PrimitiveDivProps = Radix.ComponentPropsWithoutRef; interface SidebarOverlayImplProps extends PrimitiveDivProps {} const SidebarOverlayImpl = React.forwardRef( (props: SidebarOverlayImplProps, forwardedRef) => { const { open, setOpen } = useSidebarContext(); return ( { if (e.target['ariaHidden'] === 'true') return; setOpen(false); })} /> ); } ); const OVERLAY_NAME = 'SidebarOverlay'; type SidebarOverlayElement = SidebarOverlayImplElement; export interface SidebarOverlayProps extends SidebarOverlayImplProps { /** * Specify a container element to portal the content into. */ container?: PortalProps['container']; /** * Used to force mounting when more control is needed. Useful when * controlling animation with React animation libraries. */ forceMount?: true; } export const SidebarOverlay = React.forwardRef( (props: SidebarOverlayProps, forwardedRef) => { const { forceMount, className, container, ...etc } = props; const { open, isMobile } = useSidebarContext(); if (!isMobile) return null; return ( ); } ); SidebarOverlay.displayName = OVERLAY_NAME;