On this page Snackbar Snackbar

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.

Installation
npm i @m3e/snackbar
Usage

This section outlines usage examples and configuration guidance for the components in this package.

Snackbar service

Use the open method of the M3eSnackbar service to open a snackbar.

Delete file
M3eSnackbar.open("File deleted");
Actions

You can include a single action and callback when opening a snackbar message.

Delete file
M3eSnackbar.open("File deleted", "Undo", {
  actionCallback: () => {
    // Undo logic here
  },
});
Dismissal

A snackbar message can optionally include a dismiss button.

Delete file
M3eSnackbar.open("File deleted", true);
Options

When opening a snackbar message, you can pass a SnackbarOptions object that includes the following properties.

Accessibility

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.

Native module support

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.

API

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.