Toast
FeedbackA short message that appears at the edge of the screen and closes by itself: put one <Toaster> in the app's root layout (position, label, closeLabel), then call toast('Saved') from anywhere in the browser. toast.success, toast.info, toast.warning and toast.error set the variant and its icon; options add a description, an action button (Undo), a duration (5 s; an error stays until closed) or an id to update a toast in place. toast.dismiss(id) closes one, toast.dismiss() all. Screen readers hear each toast once (an error as an alert). The timers pause while the pointer is over the toasts or focus is in them; F8 moves focus to them and back, and Escape closes the focused one.
import { Toast } from '@limerdev/zest'; Alert in the page or AlertDialog. A field's error: use Field.Error. More than a line or two, or links to read: use Alert.Examples
Variants
toast() and its variants. The app's root layout has the one <Toaster />.
<script lang="ts">
import { Button, toast } from '@limerdev/zest';
</script>
<div class="flex flex-wrap gap-2">
<Button variant="outline" onclick={() => toast('Copied to the clipboard')}>Default</Button>
<Button variant="outline" onclick={() => toast.info('Reminders go out on Mondays')}>Info</Button>
<Button
variant="outline"
onclick={() => toast.success('Invoice sent', { description: 'To anna@acme.se' })}
>
Success
</Button>
<Button variant="outline" onclick={() => toast.warning('Due in two days')}>Warning</Button>
<Button
variant="outline"
onclick={() =>
toast.error("The invoice wasn't sent", { description: 'The customer has no email address.' })}
>
Error
</Button>
</div> Undo and progress
An action button (Undo), and an id to update one toast as work goes on.
<script lang="ts">
import { Button, toast } from '@limerdev/zest';
let deleted = $state(0);
function remove(): void {
deleted += 1;
toast('Invoice deleted', {
action: { label: 'Undo', onClick: () => (deleted -= 1) }
});
}
function upload(): void {
const files = 3;
for (let file = 1; file <= files; file++) {
setTimeout(
() => {
if (file < files) {
toast(`Uploading ${file} of ${files}`, { id: 'upload', duration: Infinity });
} else {
toast.success('Uploaded 3 files', { id: 'upload' });
}
},
(file - 1) * 900
);
}
}
</script>
<div class="flex flex-wrap items-center gap-2">
<Button variant="outline" onclick={remove}>Delete invoice</Button>
<Button variant="outline" onclick={upload}>Upload files</Button>
<span class="text-sm text-muted">Deleted: {deleted}</span>
</div>