Dialogs
High priority overlay notification utilizing a dynamic queue system.
Examples
Dialog Component
Add the following to your app's root layout so that the component stays in scope for whenever you might trigger it
import { Dialog } from '@brainandbones/skeleton';
<Dialog backdrop="bg-primary-500/50" blur="backdrop-blur-sm" card="bg-primary-500" duration={250} />
Properties
Prop | Type | Default | Description |
---|---|---|---|
backdrop | string | bg-surface-400/70 dark:bg-surface-900/70 | Provide classes to set the backdrop background color. |
blur | string | backdrop-blur-none | Provide classes to add a backdrop blur. |
card | string | bg-surface-50 dark:bg-surface-700 | Provide classes to set the modal card element. |
width | string | max-w-[640px] | Provide classes to set max modal width. |
duration | number | 100 | The animation in/out durations. Set to zero (0) for none. |
Methods
To begin using dialogs, import the dialog store. This allows you to manipulate the dialog queue using the following methods.
import { dialogStore } from '@brainandbones/skeleton';
Trigger
The following method allows you to insert a new dialog into the dialog queue.
dialogStore.trigger(d); // see Dialog Variants below
Close
Allows you to close the current dialog by pruning the visible dialog from the top of the queue.
dialogStore.close();
Clear
Allows you to flush the entire dialog queue, returning it to an empty state.
dialogStore.clear();
Dialog Variants
import type { DialogAlert, DialogConfirm, DialogPrompt } from '@brainandbones/skeleton';
Alert
The simplest dialog option. Note the title and body can accept HTML.
const d: DialogAlert = {
title: 'Welcome to <strong>Skeleton</strong>.',
body: 'This is a standard alert dialog.',
};
Confirm
Displays an additional "confirm" button and returns a boolean response of false
for cancel and true
for confirm.
const d: DialogConfirm = {
type: 'confirm',
title: 'Please Confirm',
body: 'Are you sure you wish to proceed?',
result: (r: boolean) => { console.log(r); }
};
Prompt
Provides and additional input to prompt a value from the user. Returns a string value when the user taps submit.
const d: DialogPrompt = {
type: 'prompt',
title: 'Enter Name',
body: 'Provide your first name in the field below.',
value: valuePrompt,
result: (r: string) => { if (r) { console.log(r); }; }
};
Embeds
You may optionally extend any dialog with the following features.
Image
Allows you to insert an image within content of the dialog.
const d: DialogAlert = {
title: 'Image Example',
body: 'See the embedded image below.',
image: 'https://source.unsplash.com/random/480x320?skeleton'
};
HTML
Allows you to insert HTML markup within the content of the dialog.
const d: DialogAlert = {
title: 'HTML Example',
body: 'See the embedded HTML content below.',
html: `<div class="bg-green-500 p-4">Hello, Skeleton</div>`
};
Component
Allows you to insert a dynamically-generated Svelte component within the content of the dialog. Note that only default slot content is supported at this time.
import { Card } from '@brainandbones/skeleton';
const d: DialogAlert = {
title: 'Component Example',
body: 'See the embedded Svelte component below.',
component: {
element: Card,
props: {background: 'bg-orange-500'},
slot: '<p class="text-center">Hello, Skeleton!</p>'
}
};
Debugging
Log the Queue
Use the following to monitor the queue in your console as it updates. Note that Svelte store contents are only visible for the current logged line.
dialogStore.subscribe(() => { console.log($dialogStore); });
Visualize the Queue
Use the following to display the queue in your UI. Note some properties may not display, such as response.
<pre>queue: {JSON.stringify($dialogStore, null, 2)}</pre>
Accessibility
Meets all dialog requirements for the ARIA Guidelines.