Feedback

Toast

Brief notifications that stack, pause while you read them, and leave on their own.

Copy
<template>
  <JButton variant="outline" size="sm" @click="toast('Event created', { description: 'Friday, 10:00 | Design review' })">Default</JButton>
  <JButton variant="outline" size="sm" @click="toast.success('Deployment ready')">Success</JButton>
  <JButton variant="outline" size="sm" @click="toast.info('A new version is available')">Info</JButton>
  <JButton variant="outline" size="sm" @click="toast.warning('Approaching usage limit', { description: '92% of your monthly builds used.' })">Warning</JButton>
  <JButton variant="outline" size="sm" @click="toast.error('Build failed', { description: 'Exited with code 1 during typecheck.' })">Error</JButton>
  <JButton variant="outline" size="sm" @click="toast.loading('Uploading assets…', { duration: 3000 })">Loading</JButton>
</template>

Installation #

With the Nuxt module, every component and composable is auto-imported — there is nothing to add. In a plain Vue project, import what you use:

Copy
import { JToaster, toast } from '@juxtui/ui'

Usage #

Copy
<!-- once, e.g. in app.vue -->
<JToaster />

<script setup lang="ts">
import { toast } from '@juxtui/ui'

toast.success('Changes saved')
</script>

toast() works anywhere — in components, stores or plain functions. In Nuxt it is auto-imported.

Timers pause while the pointer is over the stack, while a toast has focus, and while the tab is hidden. The hairline at the bottom shows the time left.

On touch screens, swipe a toast sideways to dismiss it.

Variants & examples #

With an action#

Offer undo instead of asking for confirmation.

Copy
<script setup lang="ts">
function archive() {
  toast('Conversation archived', {
    action: { label: 'Undo', onClick: () => toast.success('Restored') },
  })
}
</script>

<template>
  <JButton variant="outline" @click="archive">Archive conversation</JButton>
</template>

Following a promise#

One toast moves from loading to success or error.

API #

JToaster

PropTypeDefault Description
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Where the stack sits. Full width on small screens.
maxnumber4Visible at once. Extra toasts wait their turn.
hotkeystring'alt+t'Moves focus to the newest toast.
labelstring'Notifications'Accessible name of the region.

toast()

PropTypeDefault Description
descriptionstring—Secondary line.
type'default' | 'success' | 'error' | 'warning' | 'info' | 'loading''default'Icon and emphasis.
durationnumber5000In ms; errors get 2s more. Infinity keeps it open.
action{ label, onClick }—A single action button.
dismissiblebooleantrueShow the close button and allow Escape / swipe.
idstring—Reuse an id to replace a toast instead of stacking.
onDismiss() => void—Called when the toast leaves.

Functions

MethodSignature Description
toast(title, options?)stringShow a toast. Returns its id.
toast.success / error / warning / infostringTyped shortcuts.
toast.loading(title)stringStays until updated or dismissed.
toast.promise(promise, messages)Promise<T>{ loading, success, error } — messages can be functions of the result.
toast.update(id, patch)voidChange a toast in place; its timer restarts.
toast.dismiss(id?)voidDismiss one toast, or all of them.

Accessibility #

  • Toasts are inserted into a persistent aria-live="polite" region, so they are announced reliably without interrupting.
  • Errors use role="alert" and are announced immediately.
  • Nothing auto-dismisses while it has focus or the pointer is over it.
  • Don’t put the only path to something important in a toast — it will go away.

Keyboard #

Key Action
AltTFocus the newest toast.
TabMove between toasts and their buttons.
EscDismiss the focused toast.