Skip to content

Commit

Permalink
feat: add modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Sep 19, 2024
1 parent 047a52d commit d7ecdd7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/shared/ui/Modal/Modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.Modal {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100%;
z-index: var(--z-index-image-modal);
}

.ModalDim {
width: 100%;
height: 100%;
background-color: #00000080;
}

.ModalWrapper {
position: absolute;
top: 50%;
left: calc(50% - min(240px, 50%) + 20px);
transform: translateY(-50%);
width: min(calc(100% - 40px), 440px);

pointer-events: bounding-box;

display: flex;
justify-content: center;
align-items: center;

background-color: var(--color-neutral-0);
border-radius: 16px;
}
31 changes: 31 additions & 0 deletions src/shared/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Portal } from '@radix-ui/react-portal';
import styles from './Modal.module.css';
import { PropsWithChildren } from 'react';

type ModalProps = PropsWithChildren<{
showModal: boolean;
closeModal: () => void;
closeOnClickOutside?: boolean;
wrapperClassName?: string;
}>;

export const Modal = ({
wrapperClassName = '',
showModal,
closeModal,
closeOnClickOutside = true,
children,
}: ModalProps) => {
return (
<>
{showModal && (
<Portal>
<div className={styles.Modal}>
<div className={styles.ModalDim} onClick={closeOnClickOutside ? closeModal : undefined} />
<div className={`${styles.ModalWrapper} ${wrapperClassName}`}>{children}</div>
</div>
</Portal>
)}
</>
);
};

0 comments on commit d7ecdd7

Please sign in to comment.