2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];
This commit is contained in:
1 parent
5a5f104174
commit
a31c44eb7b
121 files changed
+14802
-84
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import { Button } from 'antd'
|
||||
import { useEffect } from 'react'
|
||||
import CloseBtn from 'src/ui/CloseBtn'
|
||||
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
|
||||
import './modal.scss'
|
||||
|
||||
|
||||
const Modal = ({
|
||||
open,
|
||||
onOk = () => {},
|
||||
footer,
|
||||
title,
|
||||
children,
|
||||
onClose = () => {}
|
||||
}: ModalPropsType) => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
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={(event) => event.stopPropagation()}>
|
||||
<h1 className="modal__title">{title}</h1>
|
||||
<div className="modal__content">{children}</div>
|
||||
{footer && (
|
||||
<div className="modal__footer">
|
||||
<Button type="default" onClick={closeModal}>
|
||||
{footer.onCanselText}
|
||||
</Button>
|
||||
<Button type="primary" onClick={onOk}>
|
||||
{footer.onOkText}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<CloseBtn onClick={closeModal} ariaLabel="close" />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
Reference in new issue
Block a user