1.0.0 • Published 4 years ago

@miraidesigns/snackbar v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Snackbars

Snackbars show a quick message at the bottom of the screen.


HTML

Make sure to put this as high in your <body> element as possible.

<div class="mdf-snackbar" role="status" aria-live="polite">
    <span class="mdf-snackbar__text">This is a preview text message</span>

    <div class="mdf-snackbar__actions">
        <button class="mdf-button" data-snackbar-action="action">Action</button>

        <button class="mdf-snackbar__close" data-snackbar-action="close" aria-label="Dismiss snackbar">
            <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
                <use href="icons.svg#clear"></use>
            </svg>
        </button>
    </div>
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/snackbar/styles';
// Configure appearance
@use '@miraidesigns/snackbar' with (
    $variable: value
);

@include snackbar.styles();

TypeScript

import { MDFSnackbar } from '@miraidesigns/snackbar';

const snackbar = new MDFSnackbar(document.querySelector('.mdf-snackbar'));
snackbar.showSnackbar();

Implementation

Attributes

Please see the WAI-ARIA page for attributes and best practices regarding status messages.

NameElementDescription
data-snackbar-action="action"<button>Will execute the onAction function when this button is clicked
data-snackbar-action="close"<button>Will execute the onClose function when this button is clicked

Classes

NameTypeDescription
mdf-snackbarParentContains the snackbar elements
mdf-snackbar--activeModifierFades-in and moves the snackbar on-screen
mdf-snackbar__textChildHolds the snackbar text message. Child to .mdf-snackbar
mdf-snackbar__actionsParent / ChildHolds the action and close button. Child to .mdf-snackbar
mdf-snackbar__actionChildExecutes the supplied action. Child to .mdf-snackbar__actions
mdf-snackbar__closeChildDismisses the snackbar. Child to .mdf-snackbar__actions

Events

NameDataDescription
MDFSnackbar:openednullFires when the snackbar opens
MDFSnackbar:closednullFires when the snackbar closes

Properties

NameTypeDescription
.messagestringGet or set the snackbar text message
.snackbarHTMLElementReturns the snackbar element
.isActive()(): booleanReturns wether or not the sidebar is active
.snowSnackbar(message?)(string): voidShow the snackbar, optionally with the given message

Options

NameTypeDefaultDescription
delaynumber5000The amount of time that has to pass before the snackbar disappears (in ms)
onOpen() => voidnullFunction will run when the snackbar is opened
onAction() => voidnullFunction will run when the action button is activated
onClose() => voidnullFunction will run when the snackbar is closed by the user
hideOnESCbooleantrueHide the snackbar when the ESC key is pressed