1.0.1 • Published 4 years ago

@miraidesigns/dialog v1.0.1

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

Dialogs

Dialogs inform users about a task or action they need to take.


HTML

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

<div class="mdf-dialog-container" aria-hidden="true">
	<div class="mdf-dialog" role="dialog" aria-labelledby="dialog-title" aria-describedby="dialog-desc">
		<div class="mdf-dialog__header">
			<h2 id="dialog-title" class="mdf-dialog__title">Dialog title</h2>

			<button class="mdf-dialog__close" aria-label="Close dialog">
				<svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
					<use href="icons.svg#clear"></use>
				</svg>
			</button>
		</div>

		<div class="mdf-dialog__content">
			<p id="dialog-desc">Dialog description further explaining the actions.</p>
		</div>

		<div class="mdf-dialog__actions">
			<button class="mdf-button" data-dialog-action="cancel">Cancel</button>
			<button class="mdf-button" data-dialog-action="confirm">Confirm</button>
		</div>
	</div>

	<div class="mdf-dialog-backdrop"></div>
</div>

Sass

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

@include dialog.styles();

TypeScript

import { MDFDialog } from '@miraidesigns/dialog';

const dialog = new MDFDialog(document.querySelector('.mdf-dialog'));
dialog.openDialog();

Implementation

Attributes

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

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

Classes

NameTypeDescription
mdf-dialog-containerParentContains the dialog element. Creates the backdrop and centers the dialog
mdf-dialog--activeModifier1. Prepares the dialog to be visible
mdf-dialog--fade-inModifier2. Fades-in the dialog and allows for interaction
mdf-dialogParent / ChildContains the dialog elements. Child to .mdf-dialog-container
mdf-dialog__headerParent / ChildContains the dialog title. Child to .mdf-dialog
mdf-dialog__closeChildCloses the dialog. Child to .mdf-dialog__header
mdf-dialog__titleChildTitle element. Child to .mdf-dialog__header
mdf-dialog__contentParent / ChildContains the text description or other kinds of content. Child to .mdf-dialog
mdf-dialog__actionsParent / ChildContains the user actions. Child to .mdf-dialog
mdf-dialog-backdropChildDialog backdrop. Child to .mdf-dialog-container

Events

NameDataDescription
MDFDialog:openednullFires when the dialog opens
MDFDialog:closednullFires when the dialog closes

Properties

NameTypeDescription
.container(): HTMLElementReturns the dialog container element
.dialog(): HTMLElementReturns the dialog element
.content(): HTMLElementReturns the content element
.text(): HTMLParagraphElementReturns the text element
.openDialog(message?, setFocus?)(string, boolean): voidOpen the dialog window (set displayed message, set focus on first item)
.closeDialog(confirmed?)(boolean): voidClose the dialog window (run confirm or cancel callback)

Options

NameTypeDefaultDescription
onOpen() => voidnullFunction will run when the dialog is opened
onConfirm() => voidnullFunction will run when the dialog window is confirmed
onCancel() => voidnullFunction will run when the dialog window is closed or cancelled
hideOnClickbooleantrueDialog will be hidden when clicked outside of it's content