Skip to content

Snackbar

The snackbar component for brief notifications of processes that have been or will be performed.

Importing

To use the snackbar component, first you need to register the component inside the page. You can register the component manually by importing the register function:

ts
import { register } from "@tapsioss/web-components/snackbar";

register(); // Now the snackbar component is ready to use!
ts
import { registerSnackbar } from "@tapsioss/web-components";

registerSnackbar(); // Now the snackbar component is ready to use!

Also you can automatically register the component by importing it with the following approach:

ts
import "@tapsioss/web-components/snackbar/element";

TIP

If you want to use all the component in your app, you can call registerAll at the root of your project.

ts
import { registerAll } from "@tapsioss/web-components";

registerAll(); // All the components are now available

In the React package, you can easily add the component using the following code:

ts
import { Snackbar } from "@tapsioss/react-components";

Component Usage

html
<tapsi-snackbar></tapsi-snackbar>
tsx
<Snackbar />

Properties

NameAttribute NameDescriptionTypeDefault Value
texttextSets the text of the snackbar.string""
openopenDetermines whether the snackbar is open or not.booleanfalse
colorcolorThe color of the snackbar, indicating the type of message.| "success"
| "error"
| "info"
| "warning"
| "inverse"
"inverse"
dismissibledismissibleIndicates whether the snackbar can be dismissed.booleanfalse
durationdurationThe time before the snackbar automatically closes (in milliseconds).number-1

Methods

NameDescriptionParameters
showOpens the snackbar if it is not already open.
Dispatches a cancelable ShowEvent ("show").
hideCloses the snackbar if it is currently open.
Dispatches a cancelable HideEvent ("hide").

Slots

NameValueDescription
ICONiconThe slot for icon when color is inverse.

TIP

The value of slots are available for developer as JavaScript Variables:

ts
// Option 1
import { SnackbarSlots } from "@tapsioss/web-components";

// Option 2
import { Slots } from "@tapsioss/web-components/snackbar";
ts
// Option 1
import { SnackbarSlots } from "@tapsioss/react-components";

// Option 2
import { Slots } from "@tapsioss/react-components/Snackbar";

Events

NameDescriptionTypeBubblesCancelable
showFires when the snackbar should be visible.ShowEvent
hideFires when the snackbar should be hidden.HideEvent

TIP

Event details are available as JavaScript variables:

ts
// Option 1
import {
 ShowEvent,
 HideEvent
} from "@tapsioss/web-components/snackbar";

// Option 2
import {
 SnackbarShowEvent,
 SnackbarHideEvent
} from "@tapsioss/web-components";

You can have access to the event name using the type property:

ts
// Option 1
element.addEventListener(ShowEvent.type, handleShow);
element.addEventListener(HideEvent.type, handleHide);

// Option 2
element.addEventListener(SnackbarShowEvent.type, handleShow);
element.addEventListener(SnackbarHideEvent.type, handleHide);

Created with 🧡