1.0.0 • Published 4 years ago

@miraidesigns/alert v1.0.0

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

Alerts

Alerts display an important message to the user fixed to the top of the screen.


HTML

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

<div id="alert" class="mdf-alert" role="alert">
    <div class="mdf-alert__content">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#error"></use>
        </svg>

        <span class="mdf-alert__text">This is an alert message</span>
    </div>

    <div class="mdf-alert__actions">
        <button class="mdf-button" data-alert-action="cancel">Dismiss</button>
        <button class="mdf-button" data-alert-action="confirm">Confirm</button>
    </div>
</div>

Sass

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

@include alert.styles();

TypeScript

import { MDFAlert } from '@miraidesigns/alert';

const alert = new MDFAlert(document.querySelector('.mdf-alert'));
alert.showAlert();

Implementation

Attributes

NameElementDescription
data-alert-action="cancel"<button>Will execute the onCancel function when this button is clicked
data-alert-action="confirm"<button>Will execute the onConfirm function when this button is clicked

Classes

NameTypeDescription
mdf-alertParentAlert element
mdf-alert--activeModifier1. Prepares the alert to be visible
mdf-alert--move-inModifier2. Moves the alert on screen and allows for interaction
mdf-alert--filledModifierFills the alert's background with the set brand color
mdf-alert--warningModifierFills the alert's background with the set warning color
mdf-alert--errorModifierFills the alert's background with the set error color
mdf-alert__contentParent / ChildContains the alert text and actions. Child to .mdf-alert
mdf-alert__textChildAlert text. Child to .mdf-alert__content
mdf-alert__actionsChildAlert action buttons. Child to .mdf-alert__content

Events

NameDataDescription
MDFAlert:openednullFires once the alert has been opened
MDFAlert:closednullFires once the alert has been closed

Properties

NameTypeDescription
.alertHTMLElementReturns the alert element
.messagestringGet or set the alert's text message
.showAlert(delay?)(number): voidShow the alert, optionally with a delay

Options

NameTypeDefaultDescription
onOpen() => voidnullFunction will run when the alert is opened
onConfirm() => voidnullFunction will run when the alert is confirmed
onCancel() => voidnullFunction will run when the alert is dismissed