Download src/components/Modal.tsx from AnesKAM/gen: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/AnesKAM/gen/resolve/main/src/components/Modal.tsx
- Command line
-
hf download hf://spaces/AnesKAM/gen/src/components/Modal.tsx
-
curl -L -o Modal.tsx https://huggingface.co/spaces/AnesKAM/gen/resolve/main/src/components/Modal.tsx
1.93 kB
| "use client"; | |
| import { useEffect, type ReactNode } from "react"; | |
| import Icon from "@/components/Icon"; | |
| export default function Modal({ | |
| open, | |
| onClose, | |
| title, | |
| children, | |
| footer, | |
| }: { | |
| open: boolean; | |
| onClose: () => void; | |
| title: string; | |
| children: ReactNode; | |
| footer?: ReactNode; | |
| }) { | |
| useEffect(() => { | |
| if (!open) return; | |
| const onKey = (e: KeyboardEvent) => { | |
| if (e.key === "Escape") onClose(); | |
| }; | |
| window.addEventListener("keydown", onKey); | |
| document.body.style.overflow = "hidden"; | |
| return () => { | |
| window.removeEventListener("keydown", onKey); | |
| document.body.style.overflow = ""; | |
| }; | |
| }, [open, onClose]); | |
| if (!open) return null; | |
| return ( | |
| <div | |
| className="fixed inset-0 z-[90] flex items-end justify-center bg-black/60 p-0 backdrop-blur-sm sm:items-center sm:p-6" | |
| onMouseDown={(e) => { | |
| if (e.target === e.currentTarget) onClose(); | |
| }} | |
| > | |
| <div className="w-full max-w-lg animate-pop rounded-t-2xl border border-slate-200 bg-white shadow-2xl dark:border-[#2a2e39] dark:bg-[#1c1f26] sm:rounded-2xl"> | |
| <div className="flex items-center justify-between border-b border-slate-100 px-5 py-4 dark:border-[#262932]"> | |
| <h2 className="text-base font-semibold text-slate-900 dark:text-white">{title}</h2> | |
| <button | |
| onClick={onClose} | |
| className="rounded-full p-1.5 text-slate-400 transition hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-[#282c36] dark:hover:text-white" | |
| aria-label="Close" | |
| > | |
| <Icon name="x" className="h-5 w-5" /> | |
| </button> | |
| </div> | |
| <div className="max-h-[70vh] overflow-y-auto px-5 py-4">{children}</div> | |
| {footer && ( | |
| <div className="flex justify-end gap-2 border-t border-slate-100 px-5 py-3 dark:border-[#262932]"> | |
| {footer} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } | |