forked from rajun/ar-test
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { Loader2 } from 'lucide-react';
|
|
import { Button, type ButtonProps } from '~/components/ui/button';
|
|
import { DialogClose, DialogFooter } from '~/components/ui/dialog';
|
|
|
|
interface DialogActionsProps {
|
|
confirmLabel: string;
|
|
pendingLabel?: string;
|
|
cancelLabel?: string;
|
|
pending?: boolean;
|
|
disabled?: boolean;
|
|
variant?: ButtonProps['variant'];
|
|
onConfirm?: () => void;
|
|
}
|
|
|
|
// Cancel + confirm footer; without `onConfirm` the confirm button submits the surrounding form
|
|
export function DialogActions({ confirmLabel, pendingLabel, cancelLabel = 'Cancel', pending, disabled, variant, onConfirm }: DialogActionsProps) {
|
|
return (
|
|
<DialogFooter>
|
|
<DialogClose asChild>
|
|
<Button type='button' variant='secondary' disabled={pending}>
|
|
{cancelLabel}
|
|
</Button>
|
|
</DialogClose>
|
|
<Button type={onConfirm ? 'button' : 'submit'} variant={variant} disabled={pending || disabled} onClick={onConfirm}>
|
|
{pending && <Loader2 size={15} className='animate-spin' />}
|
|
{pending ? (pendingLabel ?? confirmLabel) : confirmLabel}
|
|
</Button>
|
|
</DialogFooter>
|
|
);
|
|
}
|