addons/isl/src/Modal.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {Button} from 'isl-components/Button';
b69ab319import {Icon} from 'isl-components/Icon';
b69ab3110
b69ab3111import './Modal.css';
b69ab3112
b69ab3113export function Modal({
b69ab3114 className,
b69ab3115 children,
b69ab3116 width,
b69ab3117 height,
b69ab3118 maxWidth,
b69ab3119 maxHeight,
b69ab3120 'aria-labelledby': ariaLabelledBy,
b69ab3121 'aria-describedby': ariaDescribedBy,
b69ab3122 dismiss,
b69ab3123 dataTestId,
b69ab3124}: {
b69ab3125 className?: string;
b69ab3126 children: React.ReactNode;
b69ab3127 width?: string | number;
b69ab3128 height?: number | string;
b69ab3129 maxWidth?: string | number;
b69ab3130 maxHeight?: string | number;
b69ab3131 'aria-labelledby'?: string;
b69ab3132 'aria-describedby'?: string;
b69ab3133 /** Callback to dismiss the modal. If provided, an 'x' button is added to the top-right corner of the modal. */
b69ab3134 dismiss?: () => void;
b69ab3135 dataTestId?: string;
b69ab3136}) {
b69ab3137 const style: React.CSSProperties = {
b69ab3138 width: width ?? 'fit-content',
b69ab3139 height: height ?? 'fit-content',
b69ab3140 maxHeight: maxHeight ?? 'calc(100vh / var(--zoom))',
b69ab3141 maxWidth: maxWidth ?? 'calc(100vw / var(--zoom))',
b69ab3142 };
b69ab3143 return (
b69ab3144 <div
b69ab3145 className="modal"
b69ab3146 role="dialog"
b69ab3147 aria-modal={true}
b69ab3148 aria-labelledby={ariaLabelledBy}
b69ab3149 aria-describedby={ariaDescribedBy}
b69ab3150 data-testid={dataTestId}>
b69ab3151 <div className={`modal-contents ${className ?? ''}`} style={style}>
b69ab3152 {dismiss != null ? (
b69ab3153 <div className="dismiss-modal">
b69ab3154 <Button icon onClick={dismiss}>
b69ab3155 <Icon icon="x" />
b69ab3156 </Button>
b69ab3157 </div>
b69ab3158 ) : null}
b69ab3159 {children}
b69ab3160 </div>
b69ab3161 </div>
b69ab3162 );
b69ab3163}