-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcomponent.tsx
More file actions
94 lines (87 loc) · 2.34 KB
/
Copy pathcomponent.tsx
File metadata and controls
94 lines (87 loc) · 2.34 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import ReactModal from 'react-modal';
import * as Styled from './styles';
import { BBBTypography } from '../Typography';
import { MdClose } from 'react-icons/md';
import { BBBDivider } from '../Divider';
import { ModalProps } from './types';
import { MODAL_PRIORITY_Z_INDEX } from './constants';
import { BBButton } from '../..';
/**
* A versatile BBBModal component
*
* This component provides a customizable modal with optional title, body, and footer.
* It supports accessibility, dividers, scrollable body, and sticky footer.
*
* Use the `priority` prop to control z-index stacking when multiple modals
* coexist: `'low'` (1001), `'medium'` (1002), `'high'` (1003).
*/
const Modal: React.FC<ModalProps> = ({
isOpen = true,
onRequestClose,
appElement,
title,
contentLabel,
showDividers = false,
shouldCloseOnOverlayClick = false,
shouldCloseOnEsc = false,
allowScroll = true,
noFooter = false,
footerContent = null,
stickyFooter = true,
children,
priority,
...rest
}) => {
const overlayStyle = priority
? { ...Styled.modalStyles.overlay, zIndex: MODAL_PRIORITY_Z_INDEX[priority] }
: Styled.modalStyles.overlay;
const modalStyles = {
overlay: overlayStyle,
content: Styled.modalStyles.content,
};
return (
<ReactModal
{...rest}
isOpen={isOpen}
onRequestClose={onRequestClose}
contentLabel={contentLabel}
style={modalStyles}
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick}
shouldCloseOnEsc={shouldCloseOnEsc}
appElement={appElement}
>
<Styled.ModalHeader>
<BBBTypography
variant="header"
>
{title}
</BBBTypography>
<BBButton
layout="circle"
icon={<MdClose size="1.5rem" />}
onClick={onRequestClose}
variant="subtle"
ariaLabel="close"
/>
</Styled.ModalHeader>
{showDividers && <BBBDivider />}
<Styled.ModalBody
$allowScroll={allowScroll}
>
{children}
</Styled.ModalBody>
{(!noFooter || footerContent) && (
<>
{showDividers && (<BBBDivider />)}
<Styled.ModalFooter
$stickyFooter={stickyFooter}
>
{footerContent}
</Styled.ModalFooter>
</>
)}
</ReactModal>
)
}
export default Modal;