OpChan/app/src/components/ui/drawer.tsx

117 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-08-30 18:34:50 +05:30
import * as React from 'react';
import { Drawer as DrawerPrimitive } from 'vaul';
2025-04-15 16:28:03 +05:30
2025-08-30 18:34:50 +05:30
import { cn } from '@/lib/utils';
2025-04-15 16:28:03 +05:30
const Drawer = ({
shouldScaleBackground = true,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
<DrawerPrimitive.Root
shouldScaleBackground={shouldScaleBackground}
{...props}
/>
2025-08-30 18:34:50 +05:30
);
Drawer.displayName = 'Drawer';
2025-04-15 16:28:03 +05:30
2025-08-30 18:34:50 +05:30
const DrawerTrigger = DrawerPrimitive.Trigger;
2025-04-15 16:28:03 +05:30
2025-08-30 18:34:50 +05:30
const DrawerPortal = DrawerPrimitive.Portal;
2025-04-15 16:28:03 +05:30
2025-08-30 18:34:50 +05:30
const DrawerClose = DrawerPrimitive.Close;
2025-04-15 16:28:03 +05:30
const DrawerOverlay = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
2025-08-30 18:34:50 +05:30
className={cn('fixed inset-0 z-50 bg-black/80', className)}
2025-04-15 16:28:03 +05:30
{...props}
/>
2025-08-30 18:34:50 +05:30
));
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
2025-04-15 16:28:03 +05:30
const DrawerContent = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerOverlay />
<DrawerPrimitive.Content
ref={ref}
className={cn(
2025-08-30 18:34:50 +05:30
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background',
2025-04-15 16:28:03 +05:30
className
)}
{...props}
>
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
2025-08-30 18:34:50 +05:30
));
DrawerContent.displayName = 'DrawerContent';
2025-04-15 16:28:03 +05:30
const DrawerHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
2025-08-30 18:34:50 +05:30
className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)}
2025-04-15 16:28:03 +05:30
{...props}
/>
2025-08-30 18:34:50 +05:30
);
DrawerHeader.displayName = 'DrawerHeader';
2025-04-15 16:28:03 +05:30
const DrawerFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
2025-08-30 18:34:50 +05:30
className={cn('mt-auto flex flex-col gap-2 p-4', className)}
2025-04-15 16:28:03 +05:30
{...props}
/>
2025-08-30 18:34:50 +05:30
);
DrawerFooter.displayName = 'DrawerFooter';
2025-04-15 16:28:03 +05:30
const DrawerTitle = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Title
ref={ref}
className={cn(
2025-08-30 18:34:50 +05:30
'text-lg font-semibold leading-none tracking-tight',
2025-04-15 16:28:03 +05:30
className
)}
{...props}
/>
2025-08-30 18:34:50 +05:30
));
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
2025-04-15 16:28:03 +05:30
const DrawerDescription = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Description
ref={ref}
2025-08-30 18:34:50 +05:30
className={cn('text-sm text-muted-foreground', className)}
2025-04-15 16:28:03 +05:30
{...props}
/>
2025-08-30 18:34:50 +05:30
));
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
2025-04-15 16:28:03 +05:30
export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
2025-08-30 18:34:50 +05:30
};