Skip to content
bahtuiv0.18.8

<baht-toast>

Toast host. Put one <baht-toast> on the page and call show() from anywhere; toasts stack bottom-right, auto-dismiss, and carry their tone as a left accent. If you would rather not place the host yourself, toast.success('Saved.') from the dialog & toast service mounts one on first use.

Show a toast

Save

show() returns the toast id. duration=0 makes it sticky until dismiss(id) or the × button.

<baht-button id="toast-btn">Save</baht-button>
<baht-toast id="toaster"></baht-toast>

<script>
  const toaster = document.getElementById('toaster');
  document.getElementById('toast-btn').addEventListener('click', () => {
  toaster.show({ message: 'Saved.', tone: 'success' });
  });
</script>

neutral (default), success, info, warning, danger. danger and warning render with role="alert" so screen readers announce them at once; the others ride the polite live region.

All tones

neutralsuccessinfowarningdanger
<baht-button variant="secondary" data-tone="neutral" data-message="Schema reloaded.">neutral</baht-button>
<baht-button variant="secondary" data-tone="success" data-message="Saved.">success</baht-button>
<baht-button variant="secondary" data-tone="info" data-message="3 rows skipped.">info</baht-button>
<baht-button variant="secondary" data-tone="warning" data-message="Draft not saved yet.">warning</baht-button>
<baht-button variant="secondary" data-tone="danger" data-message="Couldn't reach the webhook.">danger</baht-button>
<baht-toast id="tone-host"></baht-toast>

<script>
  const host = document.getElementById('tone-host');
  for (const btn of document.querySelectorAll('[data-tone]')) {
  btn.addEventListener('click', () =>
    host.show({ message: btn.dataset.message, tone: btn.dataset.tone }),
  );
  }
</script>

duration: 0 + dismiss(id)

Start uploadFinish

baht-dismiss fires when the toast goes — manual ×, timer or dismiss(id) — before its exit animation ends.

<baht-button id="sticky-show" variant="secondary">Start upload</baht-button>
<baht-button id="sticky-done">Finish</baht-button>
<baht-toast id="sticky-host"></baht-toast>

<script>
  const host = document.getElementById('sticky-host');
  let id = null;
  document.getElementById('sticky-show').addEventListener('click', () => {
  id = host.show({ message: 'Uploading 4 files…', tone: 'info', duration: 0 });
  });
  document.getElementById('sticky-done').addEventListener('click', () => {
  if (id !== null) host.dismiss(id);
  host.show({ message: 'Upload complete.', tone: 'success' });
  });
</script>
NameTypeDefaultDescription
durationnumber4000Default auto-dismiss ms when show() passes none (0 = sticky)
  • show()
  • dismiss()
Method Notes
show({ message, tone?, duration? }) returns the entry id. tone: 'neutral' | 'success' | 'info' | 'warning' | 'danger'. duration in ms, 0 = sticky, unset = the host’s duration
dismiss(id) removes one toast and emits baht-dismiss

ToastOptions is exported from bank20baht-ui for typing your own wrapper.

EventdetailDescription
baht-dismiss{ id: number, message: string }A toast went away — manual, timer or dismiss(id)
nameCustomEvent
Class What it is
.baht-toaster fixed bottom-right stack, aria-live="polite"
.baht-toast one entry; --success / --info / --warning / --danger set the left accent
.baht-toast--leaving added while the exit animation plays
.baht-toast-message, .baht-toast-dismiss text and × button

Copy is short and dry: “Saved.”, not “Successfully saved your changes!”.