1.6 KB64 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import {Button} from 'isl-components/Button';
9import {Icon} from 'isl-components/Icon';
10
11import './Modal.css';
12
13export function Modal({
14 className,
15 children,
16 width,
17 height,
18 maxWidth,
19 maxHeight,
20 'aria-labelledby': ariaLabelledBy,
21 'aria-describedby': ariaDescribedBy,
22 dismiss,
23 dataTestId,
24}: {
25 className?: string;
26 children: React.ReactNode;
27 width?: string | number;
28 height?: number | string;
29 maxWidth?: string | number;
30 maxHeight?: string | number;
31 'aria-labelledby'?: string;
32 'aria-describedby'?: string;
33 /** Callback to dismiss the modal. If provided, an 'x' button is added to the top-right corner of the modal. */
34 dismiss?: () => void;
35 dataTestId?: string;
36}) {
37 const style: React.CSSProperties = {
38 width: width ?? 'fit-content',
39 height: height ?? 'fit-content',
40 maxHeight: maxHeight ?? 'calc(100vh / var(--zoom))',
41 maxWidth: maxWidth ?? 'calc(100vw / var(--zoom))',
42 };
43 return (
44 <div
45 className="modal"
46 role="dialog"
47 aria-modal={true}
48 aria-labelledby={ariaLabelledBy}
49 aria-describedby={ariaDescribedBy}
50 data-testid={dataTestId}>
51 <div className={`modal-contents ${className ?? ''}`} style={style}>
52 {dismiss != null ? (
53 <div className="dismiss-modal">
54 <Button icon onClick={dismiss}>
55 <Icon icon="x" />
56 </Button>
57 </div>
58 ) : null}
59 {children}
60 </div>
61 </div>
62 );
63}
64