The @m3e/snackbar package provides the M3eSnackbar global service on
window (globalThis) used to present short updates about application processes at the
bottom of the screen from anywhere in an application.
npm i @m3e/snackbar
This section outlines usage examples and configuration guidance for the components in this package.
Use the open method of the M3eSnackbar service to open a snackbar.
M3eSnackbar.open("File deleted");
You can include a single action and callback when opening a snackbar message.
M3eSnackbar.open("File deleted", "Undo", {
actionCallback: () => {
// Undo logic here
},
});
A snackbar message can optionally include a dismiss button.
M3eSnackbar.open("File deleted", true);
When opening a snackbar message, you can pass a SnackbarOptions object that includes the following
properties.
duration?: number — The length of time, in milliseconds, to wait before automatically dismissing
the snackbar.
closeLabel?: string — The accessible label given to the close button used to dismiss the
snackbar.
actionCallback?: () => void — The callback function invoked when the action is clicked.
Snackbar messages are given ARIA role="status" and aria-live="polite", indicating that
they are polite live regions intended to be announced by assistive technologies without requiring focus.
This package uses JavaScript Modules. To use it directly in a browser without a bundler, use a module script similar to the following.
<script type="module" src="/node_modules/@m3e/snackbar/dist/index.js"></script>
You also need a module script for @m3e/button and @m3e/icon-button due to being a
dependency.
<script type="module" src="/node_modules/@m3e/button/dist/index.js"></script> <script type="module" src="/node_modules/@m3e/icon-button/dist/index.js"></script>
In addition, you must use an import map to include additional dependencies.
<script type="importmap">
{
"imports": {
"lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
"@m3e/core": "/node_modules/@m3e/core/dist/index.js"
}
}
</script>
For production, use index.min.js for faster load times.
This package includes a Custom Elements Manifest (custom-elements.json), which
documents the properties, attributes, slots, events and CSS custom properties of each component.
You can explore the API below, or integrate the manifest into your own tooling.