Skip to content

Commit

Permalink
refactor: refactor: popup, popup-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-kolesnikov committed Nov 19, 2023
1 parent 0e2db5a commit c8fd67f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<div id="root"></div>
<div id="popup"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
27 changes: 17 additions & 10 deletions src/components/popup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactNode } from 'react';
import styles from './popup.module.scss';
import { createPortal } from 'react-dom';

type PopupProps = {
openPopup: boolean;
Expand All @@ -8,23 +9,29 @@ type PopupProps = {
additionalClasses?: string;
};

const popupRoot = document.querySelector('#popup');

const Popup: React.FC<PopupProps> = ({
openPopup,
onClickClose,
children,
additionalClasses,
}) => {
return (
<div className={openPopup ? styles['popup__open'] : styles['popup']}>
<div className={`${styles['popup__inner']} ${additionalClasses}`}>
<button
className={styles['popup__button']}
type="button"
onClick={onClickClose}
/>
{children}
</div>
</div>
popupRoot &&
createPortal(
<div className={openPopup ? styles['popup__open'] : styles['popup']}>
<div className={`${styles['popup__inner']} ${additionalClasses}`}>
<button
className={styles['popup__button']}
type="button"
onClick={onClickClose}
/>
{children}
</div>
</div>,
popupRoot
)
);
};

Expand Down
3 changes: 3 additions & 0 deletions src/components/popup/popup.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
background: rgb(3 3 3 / 60%);
backdrop-filter: blur(10px);
z-index: 1111;
top: 0;
left: 0;
}

.popup__inner {
Expand All @@ -40,6 +42,7 @@
border: none;
transition: 0.3s;
cursor: pointer;
border-radius: 50%;

&:hover {
opacity: 0.7;
Expand Down

0 comments on commit c8fd67f

Please sign in to comment.