components/linyi/alert-dialog.tsx
@base-ui/reactclass-variance-authority
"use client"; import * as React from "react";import { AlertDialog as BaseAlertDialog } from "@base-ui/react/alert-dialog";import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/lib/cn"; export const AlertDialog = BaseAlertDialog.Root;export const AlertDialogTrigger = BaseAlertDialog.Trigger; export const alertDialogContentVariants = cva( [ "relative w-full rounded-panel bg-surface text-fg border border-line-strong shadow-dialog p-5 outline-none", "transition-[opacity,transform] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none", "data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:translate-y-2", "data-[ending-style]:opacity-0 data-[ending-style]:scale-95 data-[ending-style]:translate-y-1", ].join(" "), { variants: { size: { sm: "max-w-sm", md: "max-w-md", }, }, defaultVariants: { size: "sm", }, }); export const alertDialogActionVariants = cva( "ui-btn h-control-sm rounded-[8px] px-3.5 text-xs outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-canvas", { variants: { intent: { danger: "ui-btn-danger", accent: "ui-btn-accent", solid: "ui-btn-solid", }, }, defaultVariants: { intent: "danger", }, }); export interface AlertDialogContentProps extends Omit< React.ComponentPropsWithRef<typeof BaseAlertDialog.Popup>, "className" >, VariantProps<typeof alertDialogContentVariants> { className?: string;} export function AlertDialogContent({ className, size = "sm", children, ...props}: AlertDialogContentProps) { return ( <BaseAlertDialog.Portal> <BaseAlertDialog.Backdrop className="fixed inset-0 z-[var(--z-modal)] bg-[var(--scrim-backdrop)] backdrop-blur-[4px] transition-opacity duration-200 motion-reduce:transition-none data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" /> <BaseAlertDialog.Viewport className="fixed inset-0 z-[var(--z-modal)] flex items-center justify-center p-4"> <BaseAlertDialog.Popup className={cn(alertDialogContentVariants({ size }), className)} {...props} > {children} </BaseAlertDialog.Popup> </BaseAlertDialog.Viewport> </BaseAlertDialog.Portal> );} export function AlertDialogHeader({ className, ...props}: React.ComponentPropsWithRef<"div">) { return <div className={cn("space-y-1.5", className)} {...props} />;} export function AlertDialogTitle({ className, ...props}: Omit< React.ComponentPropsWithRef<typeof BaseAlertDialog.Title>, "className"> & { className?: string;}) { return ( <BaseAlertDialog.Title className={cn("text-sm font-semibold tracking-tight text-fg", className)} {...props} /> );} export function AlertDialogDescription({ className, ...props}: Omit< React.ComponentPropsWithRef<typeof BaseAlertDialog.Description>, "className"> & { className?: string;}) { return ( <BaseAlertDialog.Description className={cn("text-xs leading-relaxed text-fg-secondary", className)} {...props} /> );} export function AlertDialogFooter({ className, ...props}: React.ComponentPropsWithRef<"div">) { return ( <div className={cn( "mt-5 flex items-center justify-end gap-2 pt-3 border-t border-line", className )} {...props} /> );} export function AlertDialogCancel({ className, ...props}: Omit< React.ComponentPropsWithRef<typeof BaseAlertDialog.Close>, "className"> & { className?: string;}) { return ( <BaseAlertDialog.Close className={cn( "ui-btn ui-btn-default h-control-sm rounded-[8px] px-3.5 text-xs outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-canvas", className )} {...props} /> );} export interface AlertDialogActionProps extends Omit< React.ComponentPropsWithRef<typeof BaseAlertDialog.Close>, "className" >, VariantProps<typeof alertDialogActionVariants> { className?: string;} export function AlertDialogAction({ className, intent = "danger", ...props}: AlertDialogActionProps) { return ( <BaseAlertDialog.Close className={cn(alertDialogActionVariants({ intent }), className)} {...props} /> );}