diff --git a/packages/alert-dialog/README.md b/packages/alert-dialog/README.md index 6c24a1e9375..d722820f3ad 100644 --- a/packages/alert-dialog/README.md +++ b/packages/alert-dialog/README.md @@ -1,41 +1,47 @@ -## Description +## Overview -`sp-alert-dialog` displays important information that users need to acknowledge. When used directly the `sp-alert-dialog` element surfaces a `slot` based API for deep customization of the content to be included in the overlay. +`` displays important information that users need to acknowledge. When used directly, the `` element surfaces a `slot` based API for deep customization of the content to be included in the overlay. ### Usage [![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/alert-dialog?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/alert-dialog) [![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/alert-dialog?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/alert-dialog) -``` +```bash yarn add @spectrum-web-components/alert-dialog ``` -Import the side effectful registration of `` via: +Import the side effectful registration of `` via: -``` +```javascript import '@spectrum-web-components/alert-dialog/sp-alert-dialog.js'; ``` When looking to leverage the `AlertDialog` base class as a type and/or for extension purposes, do so via: -``` +```javascript import { AlertDialog } from '@spectrum-web-components/alert-dialog'; ``` -## Variants +### Anatomy -### Confirmation +The alert dialog consists of several key parts: -This is the default variant for alert dialogs. Use a confirmation variant for asking a user to confirm a choice. +- **Title:** All alert dialogs must have a title, using `slot="heading"`, that uses a few words to convey the outcome of what will happen if a user continues with an action +- **Content:** Alert dialogs can include a description using the default slot. A description briefly communicates any additional information or context that a user needs to know to continue with an action +- Action buttons, using `slot="button"`, that allow users to respond ```html - -

Disclaimer

- Smart filters are nondestructive and will preserve your original images. + +

Important Notice

+

This action requires your confirmation.

- Enable + Confirm
``` -### Information +#### Buttons -Information alert dialogs communicate important information that a user needs to acknowledge. Before using this kind of alert dialog, make sure it’s the appropriate communication channel for the message instead of a toast or a more lightweight messaging option. +Use `slot="button"` to render your action button(s) that allow users to respond + +- An alert dialog must have one primary action button (with `variant="primary"`) with the option to include a secondary action and/or a cancel action. +- Non-primary action buttons should be `variant="secondary"` and `treatment="outline"`. +- The three buttons should be rendered in the DOM in the following order: + - **Cancel action:** Offers an option to go back and cancel the action. + - **Secondary action:** Offers a secondary action. e.g. "Remind me later" + - **Primary action:** The first (right-most) button communicates what the button will do if selected, or to acknowledge and dismiss the dialog. Check [variants](#variants) for the correct primary button styling. See also the [Alert Dialog design options](https://spectrum.adobe.com/page/alert-dialog/#Options). ```html - -

Connect to wifi

- Please connect to wifi to sync your projects or go to Settings to change - your preferences. + +

Rate this app

+

+ If you enjoy our app, would you mind taking a moment to rate it? +

- Cancel + No, thanks + + + Remind me later - Continue + Rate now
``` -### Warning +### Options -Warning alert dialogs communicate important information to users in relation to an issue that needs to be acknowledged, but does not block the user from moving forward. +#### Variants + +The alert dialog supports `confirmation`, `information`, `warning`, `error`, and `destructive` variants to convey the nature and importance of the message: + + +Confirmation + + +Confirmation is the default variant for alert dialogs. Use a confirmation variant for asking a user to confirm a choice. ```html - -

Unverified format

- This format has not been verified and may not be viewable for some users. Do - you want to continue publishing? + +

Disclaimer

+

+ Smart filters are nondestructive and will preserve your original images. +

- Continue + Enable
``` -### Error +
+Information + -Error alert dialogs communicate critical information about an issue that a user needs to acknowledge. +Information alert dialogs communicate important information that a user needs to acknowledge. Before using this kind of alert dialog, make sure it’s the appropriate communication channel for the message instead of a toast or a more lightweight messaging option. ```html - -

Unable to share

- An error occured while sharing your project. Please verify the email address - and try again. + +

Connect to wifi

+

+ Please connect to wifi to sync your projects or go to Settings to change + your preferences. +

+ + Cancel + ``` -### Destructive +
+Warning + -Destructive alert dialogs are for when a user needs to confirm an action that will impact their data or experience in a potentially negative way, such as deleting files or contacts. +Warning alert dialogs communicate important information to users in relation to an issue that needs to be acknowledged, but does not block the user from moving forward. ```html - -

Delete 3 documents?

- Are you sure you want to delete the 3 selected documents? + +

Unverified format

+

+ This format has not been verified and may not be viewable for some + users. Do you want to continue publishing? +

- Delete + Continue
``` -### Secondary Button +
+Error + -An alert dialog can have a total of 3 buttons if the secondary outline button label is defined. +Error alert dialogs communicate critical information about an issue that a user needs to acknowledge. ```html - -

Rate this app

- If you enjoy our app, would you mind taking a moment to rate it? + +

Unable to share

+

+ An error occurred while sharing your project. Please verify the email + address and try again. +

- No, thanks + Continue +
+``` + +
+Destructive + + +Destructive alert dialogs are for when a user needs to confirm an action that will impact their data or experience in a potentially negative way, such as deleting files or contacts. + +```html + +

Delete 3 documents?

+

+ Are you sure you want to delete the 3 selected documents? +

- Remind me later + Cancel - Rate now + Delete
``` + +
+
+ +### Behaviors + +#### Context + +An alert dialog should be placed inside a modal overaly: + +```html +open modal + + + + + + Cancel + + + Confirm + + + +``` + +### Accessibility + +#### `` Element + +- Use `role="alertdialog"` on the alert dialog +- Make sure the alert dialog has an `aria-labelledby` attribute that references the title's `id`. +- Make sure the alert dialog has an `aria-describedby` attribute that references the content's `id`. + +#### Title + +- Consider the appropriate variant based on the message's importance and urgency +- Use concise, meaningful dialog title that clearly states the purpose +- Use semantic heading elements (`

`) for the dialog title + +#### Content + +- Provide clear, concise content that explains the situation and required actions + +####Buttons + +- Ensure button labels clearly indicate the action they will perform