sp-dialog

Examples API

Attributes and Properties #

Property Attribute Type Default Description
dir dir 'ltr' | 'rtl' 'ltr'
dismissable dismissable boolean false
error error boolean false
mode mode 'fullscreen' | 'fullscreenTakeover' | undefined
noDivider no-divider boolean false
size size 's' | 'm' | 'l' | undefined

Slots #

Name Description
button Button elements addressed to this slot may be placed below the content when not delivered in a fullscreen mode
footer Content addressed to the `footer` will be placed below the main content and to the side of any `[slot='button']` content
heading Acts as the heading of the dialog. This should be an actual heading tag ``
hero Accepts a hero image to display at the top of the dialog
default slot Content not addressed to a specific slot will be interpreted as the main content of the dialog

Events #

Name Type Description
close Event Announces that the dialog has been closed.

CSS Custom Properties #

Name Default
--spectrum-dialog-confirm-border-radius var(--spectrum-global-dimension-size-50)
--spectrum-dialog-confirm-description-text-color var(--spectrum-global-color-gray-800)
--spectrum-dialog-confirm-description-text-font-weight var(--spectrum-global-font-weight-regular)
--spectrum-dialog-confirm-description-text-line-height var(--spectrum-alias-component-text-line-height)
--spectrum-dialog-confirm-description-text-size undefined
--spectrum-dialog-confirm-divider-height var(--spectrum-global-dimension-size-25)
--spectrum-dialog-confirm-divider-margin-bottom var(--spectrum-global-dimension-static-size-200)
--spectrum-dialog-confirm-divider-margin-top var(--spectrum-global-dimension-static-size-150)
--spectrum-dialog-confirm-icon-color var(--spectrum-global-color-gray-900)
--spectrum-dialog-confirm-min-width var(--spectrum-global-dimension-static-size-3600)
--spectrum-dialog-confirm-padding undefined
--spectrum-dialog-confirm-title-text-color var(--spectrum-global-color-gray-900)
--spectrum-dialog-confirm-title-text-font-weight var(--spectrum-global-font-weight-bold)
--spectrum-dialog-confirm-title-text-line-height var(--spectrum-alias-heading-text-line-height)
--spectrum-dialog-confirm-title-text-size undefined
--spectrum-dialog-error-icon-color var(--spectrum-semantic-negative-icon-color)
--spectrum-dialog-error-width 90%

Description #

sp-dialog displays important information that users need to acknowledge. They appear over the interface and block further interactions. When used directly the sp-dialog element surfaces a slot based API for deep customization of the content to be included in the overlay.

Usage #

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/dialog

Import the side effectful registration of <sp-dialog> via:

import '@spectrum-web-components/dialog/sp-dialog.js';

When looking to leverage the Dialog base class as a type and/or for extension purposes, do so via:

import { Dialog } from '@spectrum-web-components/dialog';

Sizes #

Small
<sp-dialog size="s">
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>
Medium
<sp-dialog size="m">
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>
Large
<sp-dialog size="l">
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>

Variants #

Dismissable #

When supplied with the dissmissable attribute an <sp-dialog> element will surface a "close" button afordance that will dispatch a DOM event with the name of close when pressed.

Note: the dissmissable attribute will not be followed when mode="fullscreen" or mode="fullscreenTakeover" are applies in accordance with the Spectrum specification.

<sp-dialog size="m" dismissable>
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>

No Divider #

<sp-dialog size="m" dismissable no-divider>
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>

Hero #

<sp-dialog size="medium" dismissable no-divider>
<div
slot="hero"
style="background-image: url(https://place.dog/500/280)"
>
</div>
<h2 slot="heading">Disclaimer</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
dignissim cras lobortis.
</sp-dialog>