MSP-3104 update basic modal

This commit is contained in:
veselovnk committed 2024-04-11 11:24:55 +03:00
1 parent c286448f04
commit f2e08329b5
4 files changed
+66 -23

No files matched your search

+1
View File
@@ -7,4 +7,5 @@ $text-size-header2: 1.25rem;
$text-color-gray: var(--ant-primary-color);
$background-color: #F0F2F5;
$grey:#606060;
+31 -16
View File
@@ -1,35 +1,50 @@
import { Button } from 'antd'
import { Dispatch, MouseEvent, ReactNode, SetStateAction } from 'react'
import { useEffect } from 'react'
import CloseBtn from 'src/ui/CloseBtn'
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
import './modal.scss'
interface ModalPropsType {
onOk?: () => void
title: string
children: ReactNode
setIsOpenModal: Dispatch<SetStateAction<boolean>>
footer?: { onOkText: string; onCanselText: string }
}
const Modal = ({
onOk,
open,
onOk = () => {},
footer,
title,
children,
setIsOpenModal
onClose = () => {}
}: ModalPropsType) => {
const closeModal = () => {
setIsOpenModal(false)
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
onClose()
}
}
const handleModalClick = (event: MouseEvent<HTMLDivElement>) => {
event.stopPropagation()
const closeModal = () => {
onClose()
document.body.classList.remove('modal-open')
}
useEffect(() => {
document.addEventListener('keydown', handleKeyDown)
if (open) {
document.body.classList.add('modal-open')
}
return () => {
document.removeEventListener('keydown', handleKeyDown)
}
}, [open])
if (!open) {
return null
}
return (
<section className="modal" onClick={closeModal}>
<div className="modal__wrap" onClick={handleModalClick}>
<div className="modal__wrap" onClick={(event) => event.stopPropagation()}>
<h1 className="modal__title">{title}</h1>
<div className="modal__content">{children}</div>
{footer && (
@@ -37,7 +52,7 @@ const Modal = ({
<Button type="default" onClick={closeModal}>
{footer.onCanselText}
</Button>
<Button type="default" onClick={onOk}>
<Button type="primary" onClick={onOk}>
{footer.onOkText}
</Button>
</div>
+24 -7
View File
@@ -1,3 +1,5 @@
@import "src/constants/style/styleConst";
.modal {
position: fixed;
top: 50%;
@@ -13,12 +15,19 @@
&__wrap {
min-width: 310px;
min-height: 170px;
max-height: 90vh;
max-width: 90%;
background: white;
color: white;
z-index: 10;
border-radius: 16px;
box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.04);
position: relative;
padding: $basic-padding * 1.5;
display: flex;
flex-direction: column;
justify-content: space-between;
}
&__header {
@@ -28,20 +37,28 @@
border-top-left-radius: 16px;
border-top-right-radius: 16px;
}
&__title {
color: $grey;
}
&__content {
padding: 10px;
font-size: 14px;
color: #2c3e50;
text-align: center;
overflow: auto;
}
&__footer {
position: absolute;
bottom: 8px;
right: 16px;
button:first-child {
margin-right: 8px;
}
display: flex;
justify-content: end;
margin-top: $basic-margin;
button:first-child {
margin-right: 8px;
}
}
}
body.modal-open {
overflow: hidden;
padding-right: 14px;
}
+10
View File
@@ -0,0 +1,10 @@
import { ReactNode } from 'react'
export interface ModalPropsType {
open: boolean
onOk?: () => void
onClose?: () => void
title: string
children: ReactNode
footer?: { onOkText: string; onCanselText: string }
}