'use client' import Button from './button' import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog' import type * as _A from '@radix-ui/react-dismissable-layer' import { forwardRef } from 'react' import { tv } from 'tailwind-variants' import type { Merge } from 'type-fest' const alertDialog = tv({ slots: { content: [ '@container', 'fixed left-[50%] top-[50%] -translate-x-1/2 -translate-y-1/2 z-50 w-full max-w-lg', 'sm:rounded-lg', 'border bg-bg--contrast p-6 shadow-lg', 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0', 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]', ], overlay: [ 'fixed inset-0 z-50 bg-[#000]/80', 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0', ], title: 'text-lg font-semibold text-center @md:text-left', description: 'mt-2 text-sm text-fg-weaker text-center @md:text-left', actions: 'mt-4 flex flex-col-reverse gap-2 @md:flex-row @md:justify-end', }, }) const AlertDialogContent = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { portalProps?: React.ComponentProps overlayProps?: React.ComponentProps } > >(({ portalProps, overlayProps, ...props }, ref) => { const { content, overlay } = alertDialog() return ( {props.children} ) }) AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName const AlertDialogTitle = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { title } = alertDialog() return ( ) }) AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName const AlertDialogDescription = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { description } = alertDialog() return ( ) }) AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName const AlertDialogActions = forwardRef, React.ComponentPropsWithRef<'div'>>( (props, ref) => { const { actions } = alertDialog() return
}, ) AlertDialogActions.displayName = 'AlertDialogActions' const AlertDialogAction = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { cancelProps?: React.ComponentPropsWithoutRef } > >(({ cancelProps, children, asChild, ...props }, ref) => { return ( ) }) AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName const AlertDialogCancel = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { cancelProps?: React.ComponentPropsWithoutRef } > >(({ cancelProps, children, asChild, ...props }, ref) => { return ( ) }) AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName const AlertDialog = Object.assign(AlertDialogPrimitive.Root, { Trigger: AlertDialogPrimitive.Trigger, Content: AlertDialogContent, Title: AlertDialogTitle, Description: AlertDialogDescription, Actions: AlertDialogActions, Action: Object.assign({ ...Button }, AlertDialogAction), Cancel: Object.assign({ ...Button }, AlertDialogCancel), }) export default AlertDialog export { alertDialog, AlertDialogPrimitive }