- Implemented a new SettingsPage component for user preferences including appearance, behavior, and account security settings. - Added a ThemeToggle component to switch between light, dark, and system modes. - Created reusable UI components: AlertDialog, Avatar, Badge, Button, Card, Dialog, Input, Label, Progress, ScrollArea, Separator, Sheet, Skeleton, Tooltip. - Introduced utility functions for class name merging and formatting bytes/uptime. - Added a custom hook for media query handling
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { useState, type ReactNode } from 'react';
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from '@/components/ui/alert-dialog';
|
|
import { buttonVariants } from '@/components/ui/button';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
interface ConfirmDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
title: string;
|
|
description?: ReactNode;
|
|
confirmText?: string;
|
|
cancelText?: string;
|
|
destructive?: boolean;
|
|
onConfirm: () => void | Promise<void>;
|
|
}
|
|
|
|
export function ConfirmDialog({
|
|
open,
|
|
onOpenChange,
|
|
title,
|
|
description,
|
|
confirmText = '确认',
|
|
cancelText = '取消',
|
|
destructive = false,
|
|
onConfirm,
|
|
}: ConfirmDialogProps) {
|
|
const [busy, setBusy] = useState(false);
|
|
const handleConfirm = async () => {
|
|
setBusy(true);
|
|
try {
|
|
await onConfirm();
|
|
onOpenChange(false);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
return (
|
|
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
{description && <AlertDialogDescription>{description}</AlertDialogDescription>}
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel disabled={busy}>{cancelText}</AlertDialogCancel>
|
|
<AlertDialogAction
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
void handleConfirm();
|
|
}}
|
|
className={cn(destructive && buttonVariants({ variant: 'destructive' }))}
|
|
disabled={busy}
|
|
>
|
|
{busy ? '处理中…' : confirmText}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
);
|
|
}
|