Shopware Design

useSnackbar

Usage

useSnackbar publishes Snackbar notifications from anywhere in your application. It uses a global store, so mount a single mt-snackbar host near your app shell and then call addSnackbar wherever the action happens; the host renders the shared stack.

import { useSnackbar } from "@shopware-ag/meteor-component-library";

const { addSnackbar } = useSnackbar();

addSnackbar({ message: "Changes saved", variant: "success" });

API

useSnackbar() returns:

MemberTypeDescription
snackbarsReadonly<Ref<Snackbar[]>>The reactive, read-only list of active snackbars that the mt-snackbar host renders.
addSnackbar(snackbar: Omit<Snackbar, "id">) => SnackbarAdds a snackbar to the stack and returns it with a generated id. Defaults duration to 5000.
removeSnackbar(id: string) => voidRemoves the snackbar with the given id.
clearSnackbars() => voidRemoves all snackbars.

Snackbar

The shape passed to addSnackbar (without id):

PropertyTypeDescription
messagestringThe text shown in the snackbar. Required.
variant"success" | "error" | "warning" | "progress"Visual style and semantics.
iconstringOptional leading icon name.
link{ text: string; url: string }Optional single follow-up link.
durationnumberAuto-dismiss delay in milliseconds. Defaults to 5000. Set it to 0 to disable auto-dismiss and remove the snackbar yourself with removeSnackbar.
progressPercentagenumberCurrent progress from 0 to 100, for progress snackbars.
uploadState"success" | "error"Terminal state that resolves a progress snackbar.
successMessagestringMessage shown when a progress snackbar resolves successfully.
errorMessagestringMessage shown when a progress snackbar resolves with an error.
  • Snackbar: the component that renders the notifications this composable publishes.