-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDrawerPortal.tsx
More file actions
43 lines (41 loc) · 1.5 KB
/
DrawerPortal.tsx
File metadata and controls
43 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/** @jsxImportSource @emotion/react */
import { Button } from '@jdesignlab/button';
import { Close } from '@jdesignlab/react-icons';
import { Overlay, Portal } from '@jdesignlab/react-utils';
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: DrawerPortalProps) => {
const { children, width = 300, height = 300, ...restProps } = props;
const { id, isOpen, onClose, hasCloseIcon, disableOverlayClose, placement, full } = useContext(DrawerContext);
return (
<Portal className={createClassVariant('drawer', 'portal')}>
{isOpen && (
<Overlay onClick={() => disableOverlayClose || onClose()} className={createClassVariant('drawer', 'overlay')} />
)}
<div
role="dialog"
id={`drawer-${id}`}
aria-modal
className={`${createClassVariant('drawer', 'content')} ${isOpen ? 'open' : ''}`}
css={Style.portal(width, height, placement, full)}
{...restProps}
>
{hasCloseIcon && (
<div css={Style.closeIconWrapper}>
<Button
onClick={onClose}
variant="unstyled"
icon={<Close width={16} height={16} />}
css={Style.closeIcon}
/>
</div>
)}
{children}
</div>
</Portal>
);
};
DrawerPortal.displayName = 'Drawer.Portal';