Files
artcraft/frontend/apps/artcraft-webapp/src/components/ui/sheet.tsx
T
2026-09-01 10:25:21 +07:00

116 lines
3.6 KiB
TypeScript

import * as React from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { cn } from "./utils";
const Sheet = DialogPrimitive.Root;
const SheetTrigger = DialogPrimitive.Trigger;
const SheetPortal = DialogPrimitive.Portal;
const SheetOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"ac-sheet-overlay fixed inset-0 z-50 bg-black/60",
className,
)}
{...props}
/>
));
SheetOverlay.displayName = "SheetOverlay";
type SheetContentProps = React.ComponentPropsWithoutRef<
typeof DialogPrimitive.Content
> & {
side?: "left" | "right" | "top" | "bottom";
// When the sheet is non-modal (`modal={false}` on Sheet), Radix renders no
// <Dialog.Overlay>, so we draw our own dimmed backdrop to keep the focus.
// Pass `open` so it can play the same fade in/out via `.ac-sheet-overlay`.
modal?: boolean;
open?: boolean;
};
const SheetContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
SheetContentProps
>(
(
{ side = "right", className, children, modal = true, open, ...props },
ref,
) => (
<SheetPortal>
{modal ? (
<SheetOverlay />
) : (
<div
aria-hidden
data-state={open ? "open" : "closed"}
className="ac-sheet-overlay fixed inset-0 z-50 bg-black/60"
/>
)}
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed z-50 flex flex-col bg-[#101014] transition ease-in-out",
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:duration-300",
side === "left" &&
"inset-y-0 left-0 h-full border-r border-white/15 data-[state=open]:slide-in-from-left data-[state=closed]:slide-out-to-left",
side === "right" &&
"inset-y-0 right-0 h-full border-l border-white/15 data-[state=open]:slide-in-from-right data-[state=closed]:slide-out-to-right",
side === "top" &&
"inset-x-0 top-0 border-b border-white/15 data-[state=open]:slide-in-from-top data-[state=closed]:slide-out-to-top",
side === "bottom" &&
"inset-x-0 bottom-0 border-t border-white/15 data-[state=open]:slide-in-from-bottom data-[state=closed]:slide-out-to-bottom",
className,
)}
{...props}
>
{children}
</DialogPrimitive.Content>
</SheetPortal>
),
);
SheetContent.displayName = "SheetContent";
const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col gap-1 p-4", className)} {...props} />
);
const SheetTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn("text-base font-semibold text-white", className)}
{...props}
/>
));
SheetTitle.displayName = "SheetTitle";
const SheetDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-white/60", className)}
{...props}
/>
));
SheetDescription.displayName = "SheetDescription";
export {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
};