ar-test/app/components/ui/dialog.tsx

50 lines
2.6 KiB
TypeScript

import type { ComponentProps } from 'react';
import { Root, Trigger, Portal, Close, Overlay, Content, Title, Description } from '@radix-ui/react-dialog';
import { X } from 'lucide-react';
import { cn } from '~/lib/utils';
export const Dialog = Root;
export const DialogTrigger = Trigger;
export const DialogClose = Close;
export function DialogContent({ className, children, ...props }: ComponentProps<typeof Content>) {
return (
<Portal>
<Overlay className='fixed inset-0 z-50 bg-overlay backdrop-blur-[3px] data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0' />
<Content
className={cn(
'fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-3rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-y-auto rounded-panel bg-surface-dialog shadow-[0_40px_80px] shadow-shadow/50 ring-1 ring-inset ring-border-dialog data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
className,
)}
{...props}
>
{children}
<Close className='absolute top-5 right-5 flex h-[30px] w-[30px] cursor-pointer items-center justify-center rounded-item text-text-subtle transition-colors hover:bg-surface-hover hover:text-text-primary focus:outline-none'>
<X size={14} />
<span className='sr-only'>Close</span>
</Close>
</Content>
</Portal>
);
}
export function DialogHeader({ className, ...props }: ComponentProps<'div'>) {
return <div className={cn('flex flex-col gap-1 border-b border-border-divider px-6 py-5 pr-16', className)} {...props} />;
}
export function DialogBody({ className, ...props }: ComponentProps<'div'>) {
return <div className={cn('flex flex-col gap-5 px-6 py-[22px]', className)} {...props} />;
}
export function DialogFooter({ className, ...props }: ComponentProps<'div'>) {
return <div className={cn('flex flex-col-reverse gap-2.5 border-t border-border-divider px-6 py-4 sm:flex-row sm:justify-end', className)} {...props} />;
}
export function DialogTitle({ className, ...props }: ComponentProps<typeof Title>) {
return <Title className={cn('text-lg font-semibold text-text-primary', className)} {...props} />;
}
export function DialogDescription({ className, ...props }: ComponentProps<typeof Description>) {
return <Description className={cn('text-sm text-text-subtle', className)} {...props} />;
}