el.xwx.moe/components/Modal.tsx

34 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-12-01 16:42:45 -06:00
import { MouseEventHandler, ReactNode, useEffect } from "react";
2023-03-28 02:31:50 -05:00
import ClickAwayHandler from "@/components/ClickAwayHandler";
2023-05-01 05:07:01 -05:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2023-12-01 16:42:45 -06:00
import { faClose } from "@fortawesome/free-solid-svg-icons";
2023-03-28 02:31:50 -05:00
type Props = {
toggleModal: Function;
children: ReactNode;
className?: string;
2023-03-28 02:31:50 -05:00
};
export default function Modal({ toggleModal, className, children }: Props) {
2023-03-28 02:31:50 -05:00
return (
2023-12-06 23:33:05 -06:00
<div className="overflow-y-auto pt-2 sm:py-2 fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-30">
<ClickAwayHandler
onClickOutside={toggleModal}
2023-12-06 23:33:05 -06:00
className={`w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl ${
className || ""
}`}
>
2023-12-06 23:33:05 -06:00
<div className="slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl p-5 bg-base-100">
2023-05-01 05:07:01 -05:00
<div
onClick={toggleModal as MouseEventHandler<HTMLDivElement>}
2023-12-15 14:47:08 -06:00
className="absolute top-3 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"
2023-05-01 05:07:01 -05:00
>
2023-12-01 16:42:45 -06:00
<FontAwesomeIcon icon={faClose} className="w-4 h-4 text-neutral" />
2023-05-01 05:07:01 -05:00
</div>
2023-03-28 02:31:50 -05:00
{children}
</div>
</ClickAwayHandler>
</div>
);
}