import Button from "./Button"; import React, { useState, Fragment, ReactNode } from "react"; import Stack from "./Stack"; import Typography from "./Typography"; import classNames from "./lib/classNames"; import { Dialog, Transition } from "@headlessui/react"; import { XIcon } from "@heroicons/react/outline"; const { Overlay, Title, Description } = Dialog; export function getDrawerOverlayStyles() { const drawerOverlayStyles = { base: "bg-black bg-opacity-40 fixed inset-0", }; return classNames(drawerOverlayStyles.base); } export function getDrawerContentStyles() { const drawerContentStyles = { base: "bg-white w-full max-w-md fixed divide-y top-0 right-0 bottom-0 focus:outline-none", }; return classNames(drawerContentStyles.base); } export interface CustomDrawerProps { children?: ReactNode | (({ onClose }: { onClose?: () => void }) => ReactNode); overlayClassName?: string; contentClassName?: string; showCloseButton?: boolean; onClose?: () => void; description?: string; heading?: string; } export interface DrawerProps extends CustomDrawerProps {} export default function Drawer({ showCloseButton = true, overlayClassName, contentClassName, description, heading, children, onClose, }: DrawerProps) { const [open, setOpen] = useState(true); function handleClose() { if (!onClose) return; setOpen(false); setTimeout(() => { onClose(); }, 300); } return (
{heading && ( {heading && ( <Typography.Heading level={3}>{heading}</Typography.Heading> )} {showCloseButton && ( )} )} {description && ( {description} )} {children && (typeof children === "function" ? children({ onClose: handleClose }) : children)}
); }