102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import * as React from 'react';
|
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
import { cn } from '../../lib/utils';
|
|
|
|
const Dialog = DialogPrimitive.Root;
|
|
const DialogTrigger = DialogPrimitive.Trigger;
|
|
const DialogPortal = DialogPrimitive.Portal;
|
|
const DialogClose = DialogPrimitive.Close;
|
|
|
|
const DialogOverlay = React.forwardRef<
|
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
>(({ className, ...props }, ref) => (
|
|
<DialogPrimitive.Overlay
|
|
data-slot="dialog-overlay"
|
|
className={cn(
|
|
'fixed inset-0 z-50 bg-black/60 backdrop-blur-[2px] data-[state=open]:animate-in data-[state=open]:fade-in-0 duration-200',
|
|
className,
|
|
)}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
));
|
|
DialogOverlay.displayName = 'DialogOverlay';
|
|
|
|
/**
|
|
* Content: bottom-sheet na mobile (przylega do dołu, zaokrąglone góra),
|
|
* wyśrodkowany panel na desktopie. max-h 85vh ze scrollowaniem.
|
|
*/
|
|
const DialogContent = React.forwardRef<
|
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
>(({ className, children, ...props }, ref) => (
|
|
<DialogPortal>
|
|
<DialogOverlay />
|
|
<DialogPrimitive.Content
|
|
data-slot="dialog-content"
|
|
ref={ref}
|
|
className={cn(
|
|
'fixed inset-x-0 bottom-0 z-50 max-h-[85vh] w-full overflow-y-auto rounded-t-2xl border border-line bg-card p-5 shadow-card',
|
|
'sm:bottom-auto sm:left-1/2 sm:right-auto sm:top-1/2 sm:max-w-md sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl',
|
|
'duration-200 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-bottom-2',
|
|
'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</DialogPrimitive.Content>
|
|
</DialogPortal>
|
|
));
|
|
DialogContent.displayName = 'DialogContent';
|
|
|
|
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
<div data-slot="dialog-header" className={cn('mb-4 flex items-center justify-between gap-3', className)} {...props} />
|
|
);
|
|
DialogHeader.displayName = 'DialogHeader';
|
|
|
|
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
<div data-slot="dialog-footer" className={cn('mt-5 flex flex-col-reverse gap-3 sm:flex-row sm:items-center sm:justify-end', className)} {...props} />
|
|
);
|
|
DialogFooter.displayName = 'DialogFooter';
|
|
|
|
const DialogTitle = React.forwardRef<
|
|
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
>(({ className, ...props }, ref) => (
|
|
<DialogPrimitive.Title
|
|
data-slot="dialog-title"
|
|
ref={ref}
|
|
className={cn('text-[1.05rem] font-semibold', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DialogTitle.displayName = 'DialogTitle';
|
|
|
|
const DialogDescription = React.forwardRef<
|
|
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
>(({ className, ...props }, ref) => (
|
|
<DialogPrimitive.Description
|
|
data-slot="dialog-description"
|
|
ref={ref}
|
|
className={cn('text-dim text-[0.95rem]', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DialogDescription.displayName = 'DialogDescription';
|
|
|
|
export {
|
|
Dialog,
|
|
DialogClose,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogOverlay,
|
|
DialogPortal,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
};
|