A modern, dependency-free web component powered by the Popover API
Install via npm:
npm install @aegisjsproject/toast-messageYou can use the component without a build step by utilizing an import map and a CDN like unpkg:
<script type="importmap">
{
"imports": {
"@aegisjsproject/toast-message": "https://unpkg.com/@aegisjsproject/toast-message@1.0.1/toast-message.min.js"
}
}
</script>You can write the element directly in your HTML. Using the autoshow attribute will trigger it immediately when added to the DOM.
<toast-message autoshow duration="5000" position="bottom-center" theme="dark">
<span slot="content">Your profile has been updated successfully.</span>
</toast-message>You can import the class and use its static methods to dynamically generate and display toasts from JavaScript.
<button id="toast-btn" type="button">Show Toast</button>
<script type="module">
import { HTMLToastMessageElement } from '@aegisjsproject/toast-message';
document.getElementById('toast-btn').addEventListener('click', () => {
HTMLToastMessageElement.toast('Action completed successfully!', {
duration: 3000,
position: 'top-end',
theme: 'light',
autoRemove: true
});
});
</script>