diff options
| author | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2024-01-20 11:03:44 +0100 |
|---|---|---|
| committer | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2024-01-20 11:03:44 +0100 |
| commit | 363936641a31b0b508197d41bea1ce116931b5d4 (patch) | |
| tree | ff5faa88b40b79b71ce32e648ac0a1dcfeffb91c /frontend/src/components/Dialog.tsx | |
| parent | 32180f5b46fe594b01c40ca1d837734b1be894d6 (diff) | |
Diffstat (limited to 'frontend/src/components/Dialog.tsx')
| -rw-r--r-- | frontend/src/components/Dialog.tsx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/frontend/src/components/Dialog.tsx b/frontend/src/components/Dialog.tsx new file mode 100644 index 0000000..4fa6bf7 --- /dev/null +++ b/frontend/src/components/Dialog.tsx @@ -0,0 +1,54 @@ +import { FC, PropsWithChildren, useEffect, useRef } from 'react'; + +interface DialogProps { + visible: boolean; + closeDialog: () => void; +} + +const Dialog: FC<PropsWithChildren<DialogProps>> = ({ + visible, + closeDialog, + children, +}) => { + const dialogRef = useRef<HTMLDialogElement>(null); + + useEffect(() => { + if (visible) { + dialogRef.current?.showModal(); + } else { + dialogRef.current?.close(); + } + }, [visible]); + + const handleButtonClick = (e: React.MouseEvent<HTMLButtonElement>) => { + e.preventDefault(); + closeDialog(); + }; + + return ( + <dialog ref={dialogRef}> + <div className="p-4 flex flex-col max-w-[90vw] md:max-w-[50vw] bg-white shadow"> + <div className="flex w-full"> + <button className="ml-auto" onClick={handleButtonClick}> + <svg + xmlns="http://www.w3.org/2000/svg" + fill="none" + viewBox="0 0 24 24" + strokeWidth={1.5} + stroke="currentColor" + className="w-6 h-6"> + <path + strokeLinecap="round" + strokeLinejoin="round" + d="M6 18 18 6M6 6l12 12" + /> + </svg> + </button> + </div> + {children} + </div> + </dialog> + ); +}; + +export default Dialog; |
