diff --git a/packages/dialog/src/DialogBase.ts b/packages/dialog/src/DialogBase.ts index 81eb5396a8..2a2d9cb25c 100644 --- a/packages/dialog/src/DialogBase.ts +++ b/packages/dialog/src/DialogBase.ts @@ -28,13 +28,14 @@ import '@spectrum-web-components/dialog/sp-dialog.js'; import modalWrapperStyles from '@spectrum-web-components/modal/src/modal-wrapper.css.js'; import modalStyles from '@spectrum-web-components/modal/src/modal.css.js'; import { Dialog } from './Dialog.js'; +import { AlertDialog } from '@spectrum-web-components/alert-dialog'; import { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared'; import { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js'; /** * @element sp-dialog-base * - * @slot - A Dialog element to display. + * @slot - A Dialog or AlertDialog element to display. * @fires close - Announces that the dialog has been closed. */ export class DialogBase extends FocusVisiblePolyfillMixin(SpectrumElement) { @@ -66,10 +67,10 @@ export class DialogBase extends FocusVisiblePolyfillMixin(SpectrumElement) { @property({ type: Boolean }) public underlay = false; - protected get dialog(): Dialog { + protected get dialog(): Dialog | AlertDialog { const dialog = ( this.shadowRoot.querySelector('slot') as HTMLSlotElement - ).assignedElements()[0] as Dialog; + ).assignedElements()[0] as Dialog | AlertDialog; if (window.__swc.DEBUG) { if (!dialog) { window.__swc.warn( diff --git a/packages/dialog/src/DialogWrapper.ts b/packages/dialog/src/DialogWrapper.ts index ea4a48a26d..fa53760304 100644 --- a/packages/dialog/src/DialogWrapper.ts +++ b/packages/dialog/src/DialogWrapper.ts @@ -24,8 +24,10 @@ import '@spectrum-web-components/button/sp-button.js'; // Leveraged in build systems that use aliasing to prevent multiple registrations: https://github.com/adobe/spectrum-web-components/pull/3225 import '@spectrum-web-components/dialog/sp-dialog.js'; +import '@spectrum-web-components/alert-dialog/sp-alert-dialog.js'; import { DialogBase } from './DialogBase.js'; import { Dialog } from './Dialog.js'; +import { AlertDialog } from '@spectrum-web-components/alert-dialog'; /** * @element sp-dialog-wrapper @@ -41,9 +43,6 @@ export class DialogWrapper extends DialogBase { return [...super.styles]; } - /** - * @deprecated Use the Alert Dialog component with `variant="error"` instead. - */ @property({ type: Boolean, reflect: true }) public error = false; @@ -80,8 +79,10 @@ export class DialogWrapper extends DialogBase { @property({ type: String, attribute: 'headline-visibility' }) public headlineVisibility: 'none' | undefined; - protected override get dialog(): Dialog { - return this.shadowRoot.querySelector('sp-dialog') as Dialog; + protected override get dialog(): Dialog | AlertDialog { + return this.error + ? (this.shadowRoot.querySelector('sp-alert-dialog') as AlertDialog) + : (this.shadowRoot.querySelector('sp-dialog') as Dialog); } private clickSecondary(): void { @@ -108,6 +109,46 @@ export class DialogWrapper extends DialogBase { ); } + protected renderButtons(): TemplateResult { + return html` + ${this.cancelLabel + ? html` + + ${this.cancelLabel} + + ` + : nothing} + ${this.secondaryLabel + ? html` + + ${this.secondaryLabel} + + ` + : nothing} + ${this.confirmLabel + ? html` + + ${this.confirmLabel} + + ` + : nothing} + `; + } + protected override renderDialog(): TemplateResult { const hideDivider = this.noDivider || @@ -127,12 +168,30 @@ export class DialogWrapper extends DialogBase { } } + if (this.error) { + return html` + + ${this.headline + ? html` +

+ ${this.headline} +

+ ` + : nothing} + + ${this.renderButtons()} +
+ `; + } + return html` @@ -166,41 +225,7 @@ export class DialogWrapper extends DialogBase {
${this.footer}
` : nothing} - ${this.cancelLabel - ? html` - - ${this.cancelLabel} - - ` - : nothing} - ${this.secondaryLabel - ? html` - - ${this.secondaryLabel} - - ` - : nothing} - ${this.confirmLabel - ? html` - - ${this.confirmLabel} - - ` - : nothing} + ${this.renderButtons()}
`; } diff --git a/packages/dialog/stories/dialog-wrapper.stories.ts b/packages/dialog/stories/dialog-wrapper.stories.ts index d22ee964e5..7c4545bf44 100644 --- a/packages/dialog/stories/dialog-wrapper.stories.ts +++ b/packages/dialog/stories/dialog-wrapper.stories.ts @@ -406,7 +406,6 @@ export const longHeading = ( longHeading.decorators = [isOverlayOpen]; export const wrapperDismissableUnderlayError = ( - args: StoryArgs = {}, context: { viewMode?: string } = {} ): TemplateResult => { const open = context.viewMode === 'docs' ? false : true; @@ -414,15 +413,15 @@ export const wrapperDismissableUnderlayError = (
- Content of the dialog + An error occured while sharing your project. Please verify the + email address and try again. -
${content}
+ +
${content}
+
`;