From fdcde3a4a76774ab5910e149ef0ac06428c7ad08 Mon Sep 17 00:00:00 2001 From: ariellalgilmore Date: Thu, 14 Dec 2023 10:13:26 -0800 Subject: [PATCH] feat(modal): with slug --- .../src/components/modal/modal-footer.ts | 17 +++--- .../src/components/modal/modal-header.ts | 42 ++++++++++++++- .../src/components/modal/modal.scss | 23 ++++++++ .../src/components/slug/slug-example-story.ts | 53 +++++++++++++++++++ 4 files changed, 126 insertions(+), 9 deletions(-) diff --git a/packages/carbon-web-components/src/components/modal/modal-footer.ts b/packages/carbon-web-components/src/components/modal/modal-footer.ts index 62686b973b7..8af9a24c48a 100644 --- a/packages/carbon-web-components/src/components/modal/modal-footer.ts +++ b/packages/carbon-web-components/src/components/modal/modal-footer.ts @@ -31,14 +31,15 @@ class CDSModalFooter extends LitElement { */ private _handleSlotChange(event: Event) { const { selectorButtons } = this.constructor as typeof CDSModalFooter; - this.hasThreeButtons = - (event.target as HTMLSlotElement) - .assignedNodes() - .filter( - (node) => - node.nodeType === Node.ELEMENT_NODE && - (node as Element).matches(selectorButtons) - ).length > 2; + const length = (event.target as HTMLSlotElement) + .assignedNodes() + .filter( + (node) => + node.nodeType === Node.ELEMENT_NODE && + (node as Element).matches(selectorButtons) + ).length; + this.hasThreeButtons = length > 2; + length === 2 ? this.parentElement.setAttribute('has-two-buttons', '') : this.parentElement.removeAttribute('has-two-buttons') this.requestUpdate(); } diff --git a/packages/carbon-web-components/src/components/modal/modal-header.ts b/packages/carbon-web-components/src/components/modal/modal-header.ts index cc33a873158..4f214609656 100644 --- a/packages/carbon-web-components/src/components/modal/modal-header.ts +++ b/packages/carbon-web-components/src/components/modal/modal-header.ts @@ -19,8 +19,48 @@ import { carbonElement as customElement } from '../../globals/decorators/carbon- */ @customElement(`${prefix}-modal-header`) class CDSModalHeader extends LitElement { + /** + * `true` if there is a slug. + */ + protected _hasSlug = false; + + /** + * Handles `slotchange` event. + */ + protected _handleSlotChange({ target }: Event) { + const hasContent = (target as HTMLSlotElement) + .assignedNodes() + .filter((elem) => + (elem as HTMLElement).matches !== undefined + ? (elem as HTMLElement).matches( + (this.constructor as typeof CDSModalHeader).slugItem + ) + : false + ); + if (hasContent.length > 0) { + this._hasSlug = Boolean(hasContent); + (hasContent[0] as HTMLElement).setAttribute('size', 'lg'); + } + this.requestUpdate(); + } + + updated(){ + if (this._hasSlug) { + this.parentElement.setAttribute('slug', ''); + } else { + this.parentElement!.removeAttribute('slug'); + } + } + render() { - return html` `; + return html` `; + } + + /** + * A selector that will return the slug item. + */ + static get slugItem() { + return `${prefix}-slug`; } static styles = styles; // `styles` here is a `CSSResult` generated by custom WebPack loader diff --git a/packages/carbon-web-components/src/components/modal/modal.scss b/packages/carbon-web-components/src/components/modal/modal.scss index c29443fedbd..bae49f4a922 100644 --- a/packages/carbon-web-components/src/components/modal/modal.scss +++ b/packages/carbon-web-components/src/components/modal/modal.scss @@ -13,6 +13,7 @@ @use '@carbon/styles/scss/layer' as *; @use '@carbon/styles/scss/type' as *; @use '@carbon/styles/scss/utilities/convert' as *; +@use '@carbon/styles/scss/utilities/ai-gradient' as *; @use '@carbon/styles/scss/components/modal' as *; @use '@carbon/styles/scss/components/button' as *; @@ -135,3 +136,25 @@ height: $spacing-10; margin: 0; } + +// Slug + +:host(#{$prefix}-modal) .#{$prefix}--modal-container { + @include callout-gradient('default'); + + background-color: $layer; +} + +:host(#{$prefix}-modal[has-two-buttons]) .#{$prefix}--modal-container { + // @include callout-gradient('default', 64px); + + background-color: $layer; +} + + +:host(#{$prefix}-modal-header) ::slotted(#{$prefix}-slug){ + position: absolute; + inset-block-start: 0; + inset-inline-end: 3rem; +} + diff --git a/packages/carbon-web-components/src/components/slug/slug-example-story.ts b/packages/carbon-web-components/src/components/slug/slug-example-story.ts index c196e0196eb..7086925d123 100644 --- a/packages/carbon-web-components/src/components/slug/slug-example-story.ts +++ b/packages/carbon-web-components/src/components/slug/slug-example-story.ts @@ -220,6 +220,59 @@ export const _Dropdown = () => { `; }; +export const _Modal = () => { + return html` + + + + ${content}${actions} + + + Account resources + Add a custom domain + + + + Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. + + + + + + + + + US South + US East + + + + + One + Two + + + + Option 1 + Option 2 + + + + Cancel + Add + + + ` +} + export const _Multiselect = () => { return html`