forked from rajun/ar-test
refactor: simplify confirm dialog with dialog actions and icon tile
This commit is contained in:
parent
cbd23f2902
commit
b3f7504459
@ -1,83 +1,30 @@
|
|||||||
import * as React from 'react';
|
import { AlertTriangle } from 'lucide-react';
|
||||||
import {
|
import { Dialog, DialogBody, DialogContent, DialogDescription, DialogTitle } from '~/components/ui/dialog';
|
||||||
Dialog,
|
import { DialogActions } from '~/components/ui/dialog-actions';
|
||||||
DialogContent,
|
import { IconTile } from '~/components/ui/icon-tile';
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
} from '~/components/ui/dialog';
|
|
||||||
import { Button } from '~/components/ui/button';
|
|
||||||
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
|
||||||
|
|
||||||
interface ConfirmDialogProps {
|
interface ConfirmDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
confirmText?: string;
|
confirmLabel?: string;
|
||||||
cancelText?: string;
|
pending?: boolean;
|
||||||
variant?: 'destructive' | 'default';
|
|
||||||
loading?: boolean;
|
|
||||||
onConfirm: () => void;
|
onConfirm: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ConfirmDialog({
|
export function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel = 'Confirm', pending, onConfirm }: ConfirmDialogProps) {
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
confirmText = 'Confirm',
|
|
||||||
cancelText = 'Cancel',
|
|
||||||
variant = 'destructive',
|
|
||||||
loading = false,
|
|
||||||
onConfirm,
|
|
||||||
}: ConfirmDialogProps) {
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-w-md bg-[#121212] border-neutral-850 p-6">
|
<DialogContent className='max-w-md'>
|
||||||
<DialogHeader className="space-y-2">
|
<DialogBody className='flex-row items-start gap-4 pr-16'>
|
||||||
<div className="flex items-center gap-3">
|
<IconTile icon={AlertTriangle} tone='danger' />
|
||||||
<div className="w-10 h-10 rounded-xl bg-red-500/10 border border-red-500/20 flex items-center justify-center text-red-500 shrink-0">
|
<div className='space-y-1.5'>
|
||||||
<AlertTriangle size={20} />
|
<DialogTitle>{title}</DialogTitle>
|
||||||
</div>
|
<DialogDescription>{description}</DialogDescription>
|
||||||
<div>
|
|
||||||
<DialogTitle className="text-base font-bold text-white uppercase tracking-wider">
|
|
||||||
{title}
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription className="text-xs text-neutral-400 mt-1">
|
|
||||||
{description}
|
|
||||||
</DialogDescription>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</DialogHeader>
|
</DialogBody>
|
||||||
|
<DialogActions confirmLabel={confirmLabel} variant='destructive' pending={pending} onConfirm={onConfirm} />
|
||||||
<DialogFooter className="mt-6 flex flex-row items-center justify-end gap-3">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
disabled={loading}
|
|
||||||
onClick={() => onOpenChange(false)}
|
|
||||||
className="h-9"
|
|
||||||
>
|
|
||||||
{cancelText}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant={variant}
|
|
||||||
size="sm"
|
|
||||||
disabled={loading}
|
|
||||||
onClick={onConfirm}
|
|
||||||
className="h-9"
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<RefreshCw size={14} className="animate-spin" />
|
|
||||||
) : (
|
|
||||||
confirmText
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user