mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 13:56:29 +02:00
add react modal and use it for days wishes
This commit is contained in:
38
src/components/Modal/Modal.tsx
Normal file
38
src/components/Modal/Modal.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { FC, ReactNode, useCallback } from "react"
|
||||
import RModal from "react-modal"
|
||||
import { useSelector } from "react-redux"
|
||||
import { reactAppId } from "../../app"
|
||||
import styles from "./styles.module.scss"
|
||||
import { hideModal, selectActiveModalId } from "../../store/ui"
|
||||
import useAction from "../../utils/useAction"
|
||||
|
||||
type Props = {
|
||||
children: ReactNode
|
||||
modalId: string
|
||||
}
|
||||
|
||||
RModal.setAppElement(`#${reactAppId}`)
|
||||
|
||||
const Modal: FC<Props> = ({ modalId, children }): JSX.Element => {
|
||||
const activeModalId = useSelector(selectActiveModalId)
|
||||
const execHideModal = useAction(hideModal)
|
||||
const onClose = useCallback(() => execHideModal(), [execHideModal])
|
||||
|
||||
const modalIsActive = activeModalId === modalId
|
||||
|
||||
return (
|
||||
<RModal
|
||||
isOpen={modalIsActive}
|
||||
className={styles.modalContent}
|
||||
overlayClassName={styles.modalOverlay}
|
||||
onRequestClose={onClose}
|
||||
>
|
||||
<button type="submit" className={styles.closeButton} onClick={onClose}>
|
||||
✕
|
||||
</button>
|
||||
{children}
|
||||
</RModal>
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
38
src/components/Modal/styles.module.scss
Executable file
38
src/components/Modal/styles.module.scss
Executable file
@@ -0,0 +1,38 @@
|
||||
@import "../../theme/variables";
|
||||
@import "../../theme/mixins";
|
||||
|
||||
.modalOverlay {
|
||||
position: fixed;
|
||||
z-index: 100;
|
||||
inset: 0;
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modalContent {
|
||||
@include horizontal-vertical-center();
|
||||
|
||||
position: absolute;
|
||||
bottom: auto;
|
||||
right: auto;
|
||||
padding: 15px;
|
||||
outline: 0;
|
||||
background-color: $color-white;
|
||||
border-radius: 15px;
|
||||
border: $border-large;
|
||||
}
|
||||
|
||||
.closeButton {
|
||||
position: absolute;
|
||||
padding: 0;
|
||||
z-index: 10;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 0;
|
||||
line-height: 20px;
|
||||
color: $color-grey-dark;
|
||||
text-align: center;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
}
|
Reference in New Issue
Block a user