96 lines
4.0 KiB
TypeScript
96 lines
4.0 KiB
TypeScript
import { Transition } from "@headlessui/react";
|
|
import { t as i18nT } from "i18next";
|
|
import { Fragment, ReactNode, useState } from "react";
|
|
import { useEscapeKeypress } from "~/utils/shared/KeypressUtils";
|
|
import clsx from "clsx";
|
|
import { XIcon } from "~/components/ui/icons/vendor";
|
|
|
|
type size = "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "full";
|
|
interface Props {
|
|
title?: string;
|
|
size?: size;
|
|
paddingContent?: string;
|
|
paddingY?: string;
|
|
content?: ReactNode;
|
|
footer?: ReactNode;
|
|
children?: ReactNode;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export default function SlideOver({ title = "", size = "md", paddingContent = "px-4 sm:px-6", paddingY = "py-6", onClose, content, footer }: Props) {
|
|
const [open] = useState(true);
|
|
|
|
useEscapeKeypress(onClose);
|
|
return (
|
|
<div>
|
|
<div className="bg-foreground/50 absolute inset-0 transition-opacity"></div>
|
|
|
|
<div className="fixed inset-0 z-10 overflow-hidden">
|
|
<div className="absolute inset-0 overflow-hidden">
|
|
<section className="absolute inset-y-0 right-0 flex max-w-full pl-10">
|
|
<Transition
|
|
show={open}
|
|
as={Fragment}
|
|
enter="transform transition ease-in-out duration-500 sm:duration-700"
|
|
enterFrom="-translate-x-full"
|
|
enterTo="translate-x-0"
|
|
leave="transform transition ease-in-out duration-500 sm:duration-700"
|
|
leaveFrom="translate-x-0"
|
|
leaveTo="-translate-x-full"
|
|
>
|
|
<div
|
|
className={clsx(
|
|
// Subframe Drawer panel layout: min-w-[320px] floor on the side panel width.
|
|
"w-screen min-w-[320px] max-w-sm",
|
|
size === "md" && "md:max-w-md",
|
|
size === "lg" && "md:max-w-lg",
|
|
size === "2xl" && "md:max-w-2xl",
|
|
size === "3xl" && "md:max-w-3xl",
|
|
size === "4xl" && "md:max-w-4xl",
|
|
size === "full" && "md:max-w-full"
|
|
)}
|
|
>
|
|
<div className="divide-border-default bg-surface-neutral-primary flex h-full flex-col divide-y shadow-2xl">
|
|
<div className={clsx(paddingY, "h-0 flex-1 space-y-6 overflow-y-scroll")}>
|
|
{title && (
|
|
<div className="px-4 sm:px-6">
|
|
<div className="flex items-start justify-between space-x-3">
|
|
<h2 className="text-text-neutral-primary text-lg font-medium leading-7">{title}</h2>
|
|
<div className="flex h-7 items-center">
|
|
<button
|
|
onClick={() => onClose()}
|
|
aria-label={i18nT("components.slideOver.closePanel")}
|
|
className="hover:text-text-neutral-tertiary text-text-neutral-tertiary transition duration-150 ease-in-out"
|
|
>
|
|
<XIcon className="h-6 w-6" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className={clsx(paddingContent, "relative flex-1")}>
|
|
{content && <div>{content}</div>}
|
|
{footer && <div className="border-border-default flex shrink-0 justify-end space-x-4 border-t px-1 py-4">{footer}</div>}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Transition>
|
|
</section>
|
|
</div>
|
|
<div className="absolute right-10 top-4">
|
|
{!title && (
|
|
<button
|
|
onClick={() => onClose()}
|
|
className="border-border-default text-text-neutral-primary bg-surface-neutral-primary flex items-center space-x-1 rounded-md border px-2 py-1 text-xs font-extrabold uppercase shadow-lg hover:bg-gray-200"
|
|
>
|
|
<div>{i18nT("shared.close")}</div>
|
|
<XIcon className="h-3.5" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|