Components Menus and overlays

Toast

A short notice at the top. Render Toaster once; call toast() or toast.success(), .error(), .loading(), .promise() anywhere, with an id to replace a notice and an action button.

import { Toaster } from '@kition/tessera-ui'

Examples

Levels
toast.tsx
import { Button, toast } from '@kition/tessera-ui'

// Render <Toaster /> once near the root of the editor; toast() can then be called from anywhere.
export default function Demo() {
  return (
    <div className="demo-row">
      <Button onClick={() => toast('success', 'Saved', 'Budget 2027.xlsx')}>Success</Button>
      <Button onClick={() => toast('info', 'Agent is working', 'Rewriting slide 3')}>Info</Button>
      <Button onClick={() => toast('error', 'Could not save', 'The disk is full')}>Error</Button>
    </div>
  )
}
Actions, promises, sticky notices
toast-options.tsx
import { Button, toast } from '@kition/tessera-ui'

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

export default function Demo() {
  return (
    <div className="demo-row">
      <Button onClick={() => toast.info('Row deleted', { action: { label: 'Undo', onClick: () => toast.success('Row restored') } })}>With an action</Button>
      <Button onClick={() => void toast.promise(wait(1500).then(() => 3), { loading: 'Exporting…', success: (count) => `Exported ${count} files`, error: 'Export failed' })}>A promise</Button>
      <Button onClick={() => toast.error('Offline', { id: 'network', duration: Number.POSITIVE_INFINITY, description: 'Changes are kept until you reconnect.' })}>Sticky</Button>
      <Button variant="ghost" onClick={() => toast.dismiss()}>Dismiss all</Button>
    </div>
  )
}

Props

Toaster

Where notices appear: centred at the top, offset px down (below a host's tab strip).

PropTypeDefaultDescription
offsetnumber12
closeButtonbooleantrue