Appearance
Modal Usage
Use the confirmation modal when the user needs to approve an action before it continues.
Common cases:
- deleting data
- logging out
- discarding changes
- publishing or submitting something important
The modal API is promise-based, so the code stays simple and linear.
Basic example
Import useConfirmation() and call confirm().
ts
import { useConfirmation } from '@erag/inertia-toast-vue';
const modal = useConfirmation();
const ok = await modal.confirm({
title: 'Delete?',
message: 'Are you sure?',
type: 'danger',
});ts
import { useConfirmation } from '@erag/inertia-toast-react';
const confirmation = useConfirmation();
const ok = await confirmation.confirm({
title: 'Delete?',
message: 'Are you sure?',
type: 'danger',
});truemeans the user confirmedfalsemeans the user cancelled or closed the modal
Delete action
This is the most common modal flow.
vue
<script setup lang="ts">
import { useConfirmation, useToast } from '@erag/inertia-toast-vue';
const modal = useConfirmation();
const toast = useToast();
const handleDelete = async () => {
const isConfirmed = await modal.confirm({
title: 'Delete account?',
message: 'Are you sure? This action cannot be undone.',
confirmText: 'Yes, Delete',
cancelText: 'No, Keep it',
type: 'danger',
});
if (isConfirmed) {
toast.success('Account deleted successfully');
return;
}
toast.info('Action cancelled');
};
</script>tsx
import { useConfirmation, useToast } from '@erag/inertia-toast-react';
export default function DeleteAccountButton() {
const confirmation = useConfirmation();
const toast = useToast();
const handleDelete = async (): Promise<void> => {
const isConfirmed = await confirmation.confirm({
title: 'Delete account?',
message: 'Are you sure? This action cannot be undone.',
confirmText: 'Yes, Delete',
cancelText: 'No, Keep it',
type: 'danger',
});
if (isConfirmed) {
toast.success('Account deleted successfully');
return;
}
toast.info('Action cancelled');
};
return <button onClick={handleDelete}>Delete account</button>;
}Delete action with Inertia
Use this pattern when the final action should call the server.
vue
<script setup lang="ts">
import { router } from '@inertiajs/vue3';
import { useConfirmation } from '@erag/inertia-toast-vue';
const modal = useConfirmation();
const removePost = async (id: number) => {
const ok = await modal.confirm({
title: 'Delete post',
message: 'This action cannot be undone.',
type: 'danger',
confirmText: 'Delete',
cancelText: 'Cancel',
});
if (!ok) {
return;
}
router.delete(route('posts.destroy', id));
};
</script>tsx
import { router } from '@inertiajs/react';
import { useConfirmation } from '@erag/inertia-toast-react';
export default function PostsIndex() {
const confirmation = useConfirmation();
const removePost = async (id: number): Promise<void> => {
const ok = await confirmation.confirm({
title: 'Delete post',
message: 'This action cannot be undone.',
type: 'danger',
confirmText: 'Delete',
cancelText: 'Cancel',
});
if (!ok) {
return;
}
router.delete(route('posts.destroy', id));
};
}What happens when you await
ts
const ok = await modal.confirm({ ... });Flow:
- Your action starts.
- The modal opens.
- Code pauses at
await. - Confirm resolves
true. - Cancel or close resolves
false. - Your code continues with that result.
Modal types
Use type to control the intent and button styling.
ts
type: 'danger'
type: 'warning'
type: 'info'
type: 'success'ts
type: 'danger'
type: 'warning'
type: 'info'
type: 'success'dangerfor destructive actionswarningfor risky actionsinfofor neutral confirmationsuccessfor positive confirmation
Logout example
ts
const logout = async () => {
const ok = await modal.confirm({
title: 'Logout',
message: 'You have unsaved changes. Do you really want to leave?',
confirmText: 'Logout',
type: 'warning',
});
if (ok) {
// Perform logout
}
};ts
const logout = async (): Promise<void> => {
const ok = await confirmation.confirm({
title: 'Logout',
message: 'You have unsaved changes. Do you really want to leave?',
confirmText: 'Logout',
type: 'warning',
});
if (ok) {
// Perform logout
}
};Custom icon
Pass an SVG string if you want to replace the default icon.
ts
await modal.confirm({
title: 'Custom Icon',
message: 'This modal uses a custom icon.',
icon: `<svg viewBox="0 0 24 24">...</svg>`,
});ts
await confirmation.confirm({
title: 'Custom Icon',
message: 'This modal uses a custom icon.',
icon: `<svg viewBox="0 0 24 24">...</svg>`,
});Modal options
| Option | Type | Description |
|---|---|---|
title | string | Modal heading |
message | string | Modal body text |
confirmText | string | Confirm button label |
cancelText | string | Cancel button label |
type | 'danger' | 'warning' | 'info' | 'success' | Style and intent |
icon | string | Custom icon that replaces the default icon |