diff --git a/packages/drawer/src/components/Drawer.tsx b/packages/drawer/src/components/Drawer.tsx index ee125d8..aa46222 100644 --- a/packages/drawer/src/components/Drawer.tsx +++ b/packages/drawer/src/components/Drawer.tsx @@ -1,11 +1,11 @@ /** @jsxImportSource @emotion/react */ import { filterComponent } from '@jdesignlab/react-utils'; +import { useId, useMemo } from 'react'; import { DrawerTrigger } from './DrawerTrigger'; import { DrawerPortal } from './DrawerPortal'; import { useToggleLayer } from '../hooks/useToggleLayer'; -import { useId } from 'react'; import { DrawerContext } from '../context'; -import { DrawerProps } from '../types'; +import type { DrawerProps } from '../types'; export const Drawer = (props: DrawerProps) => { const { @@ -16,8 +16,7 @@ export const Drawer = (props: DrawerProps) => { hasCloseIcon = true, disableOverlayClose = false, placement = 'right', - full = false, - ...restProps + full = false } = props; const { isOpen, onOpen, onClose } = useToggleLayer(openProp, onOpenProp, onCloseProp); const id = useId(); @@ -25,8 +24,22 @@ export const Drawer = (props: DrawerProps) => { const triggerComponent = filterComponent(children, DrawerTrigger, true); const portalComponent = filterComponent(children, DrawerPortal, true); + const providerValue = useMemo( + () => ({ + id, + isOpen, + onOpen, + onClose, + hasCloseIcon, + disableOverlayClose, + placement, + full + }), + [id, isOpen, onOpen, onClose, hasCloseIcon, disableOverlayClose, placement, full] + ); + return ( - + {triggerComponent} {portalComponent} diff --git a/packages/drawer/src/components/DrawerPortal.tsx b/packages/drawer/src/components/DrawerPortal.tsx index 4068e77..2598902 100644 --- a/packages/drawer/src/components/DrawerPortal.tsx +++ b/packages/drawer/src/components/DrawerPortal.tsx @@ -1,5 +1,4 @@ /** @jsxImportSource @emotion/react */ - import { Button } from '@jdesignlab/button'; import { Close } from '@jdesignlab/react-icons'; import { Overlay, Portal } from '@jdesignlab/react-utils'; @@ -7,8 +6,9 @@ import { createClassVariant } from '@jdesignlab/theme'; import { useContext } from 'react'; import { DrawerContext } from '../context'; import * as Style from '../styles'; +import type { DrawerPortalProps } from '../types'; -export const DrawerPortal = (props: any) => { +export const DrawerPortal = (props: DrawerPortalProps) => { const { children, width = 300, height = 300, ...restProps } = props; const { id, isOpen, onClose, hasCloseIcon, disableOverlayClose, placement, full } = useContext(DrawerContext); return ( @@ -19,15 +19,19 @@ export const DrawerPortal = (props: any) => {