Skip to main content

Toast

Non-blocking notification messages that appear at the corner of the screen and dismiss automatically. Powered by the @primus/ui-core JS bundle via the global primus.toast() API.

Requires JS bundle

Toast requires the @primus/ui-core JS bundle. Add it once to your app:

  • Angular: "scripts": ["node_modules/@primus/ui-core/dist/primus-ui.min.js"] in angular.json
  • React: import '@primus/ui-core/dist/primus-ui.min.js' in main.tsx
  • HTML: <script type="module" src="https://unpkg.com/@primus/ui-core/dist/primus-ui.min.js"></script>
Preview ยท Toast variants

Codeโ€‹

<!-- Ensure the JS bundle is loaded first -->
<script type="module" src="https://unpkg.com/@primus/ui-core/dist/primus-ui.min.js"></script>

<script>
// Basic info toast
primus.toast('Syncing data in the background.');

// With title + variant
primus.toast('All changes saved.', 'Saved', { variant: 'success' });
primus.toast('Connection failed.', 'Error', { variant: 'danger' });
primus.toast('Storage at 90%.', 'Warning', { variant: 'warning' });

// Persistent (no auto-dismiss)
primus.toast('Processing your request...', 'Please wait', { duration: 0 });

// Clear all toasts
primus.toast.clear();
primus.toast.clear('bottom-right'); // clear a specific placement
</script>

API Referenceโ€‹

primus.toast(message, title?, options?)โ€‹

ParameterTypeDefaultDescription
messagestringrequiredToast body text
titlestringโ€”Bold heading above message
options.variant'success' | 'danger' | 'warning' | 'info''info'Visual style and icon
options.durationnumber4000Auto-dismiss delay in ms. 0 = persistent
options.placementstring'top-right'Screen position

Placementsโ€‹

ValuePosition
top-leftTop left corner
top-centerTop centre
top-rightTop right corner (default)
bottom-leftBottom left corner
bottom-centerBottom centre
bottom-rightBottom right corner

primus.toast.clear(placement?)โ€‹

Dismiss all visible toasts. Pass a placement string to clear only that stack.

Version history

See the Changelog for version history and breaking changes.