* Upgrade Stimulus to 3.0 * Remove unused variable * Bump postcss from 8.3.8 to 8.3.9 (#14956) Bumps [postcss](https://github.com/postcss/postcss) from 8.3.8 to 8.3.9. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.3.8...8.3.9) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
31 lines
994 B
JavaScript
31 lines
994 B
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
// Wraps the Preact Snackbar component into a Stimulus controller
|
|
export default class SnackbarController extends Controller {
|
|
static targets = ['snackZone'];
|
|
|
|
async connect() {
|
|
const [{ h, render }, { Snackbar }] = await Promise.all([
|
|
import('preact'),
|
|
// eslint-disable-next-line import/no-unresolved
|
|
import('Snackbar'),
|
|
]);
|
|
|
|
render(<Snackbar lifespan="3" />, this.snackZoneTarget);
|
|
}
|
|
|
|
async disconnect() {
|
|
const { render } = await import('preact');
|
|
render(null, this.snackZoneTarget);
|
|
}
|
|
|
|
// Any Stimulus controller can add an item to the Snackbar by dispatching a custom event
|
|
// data-action="snackbar:add@document->snackbar#addItem"
|
|
async addItem(event) {
|
|
const { message, addCloseButton = false } = event.detail;
|
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
const { addSnackbarItem } = await import('Snackbar');
|
|
addSnackbarItem({ message, addCloseButton });
|
|
}
|
|
}
|