forked from rajun/ar-test
feat: add dialog actions footer
This commit is contained in:
parent
9e3f0c518b
commit
31806455b4
30
app/components/ui/dialog-actions.tsx
Normal file
30
app/components/ui/dialog-actions.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user