Skip to content

Commit 5ba517c

Browse files
authored
feat(panel, flow-item): add alerts slot (#9778)
**Related Issue:** #9772 ## Summary - add `alerts` slot to `panel` and `flow-item` - rename existing internal property `slottedInShell` to `embedded` for greater use beyond just shell - add e2e test - add screenshot tests
1 parent 797d48e commit 5ba517c

File tree

21 files changed

+165
-73
lines changed

21 files changed

+165
-73
lines changed

packages/calcite-components/src/components.d.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ export namespace Components {
509509
* Specifies the duration before the component automatically closes - only use with `autoClose`.
510510
*/
511511
"autoCloseDuration": AlertDuration;
512+
/**
513+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
514+
*/
515+
"embedded": boolean;
512516
/**
513517
* When `true`, shows a default recommended icon. Alternatively, pass a Calcite UI Icon name to display a specific icon.
514518
*/
@@ -556,10 +560,6 @@ export namespace Components {
556560
* Sets focus on the component's "close" button, the first focusable item.
557561
*/
558562
"setFocus": () => Promise<void>;
559-
/**
560-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
561-
*/
562-
"slottedInShell": boolean;
563563
}
564564
interface CalciteAvatar {
565565
/**
@@ -3388,6 +3388,10 @@ export namespace Components {
33883388
* When `true`, prevents the component from expanding to the entire screen on mobile devices.
33893389
*/
33903390
"docked": boolean;
3391+
/**
3392+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
3393+
*/
3394+
"embedded": boolean;
33913395
/**
33923396
* When `true`, disables the default close on escape behavior.
33933397
*/
@@ -3438,10 +3442,6 @@ export namespace Components {
34383442
* Sets focus on the component's "close" button (the first focusable item).
34393443
*/
34403444
"setFocus": () => Promise<void>;
3441-
/**
3442-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
3443-
*/
3444-
"slottedInShell": boolean;
34453445
/**
34463446
* Updates the element(s) that are used within the focus-trap of the component.
34473447
*/
@@ -4331,6 +4331,10 @@ export namespace Components {
43314331
* Specifies the display mode - `"float"` (content is separated detached), or `"overlay"` (displays on top of center content).
43324332
*/
43334333
"displayMode": DisplayMode;
4334+
/**
4335+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
4336+
*/
4337+
"embedded": boolean;
43344338
/**
43354339
* When `true`, disables the default close on escape behavior.
43364340
*/
@@ -4367,10 +4371,6 @@ export namespace Components {
43674371
* Sets focus on the component's "close" button - the first focusable item.
43684372
*/
43694373
"setFocus": () => Promise<void>;
4370-
/**
4371-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
4372-
*/
4373-
"slottedInShell": boolean;
43744374
/**
43754375
* Updates the element(s) that are used within the focus-trap of the component.
43764376
*/
@@ -8273,6 +8273,10 @@ declare namespace LocalJSX {
82738273
* Specifies the duration before the component automatically closes - only use with `autoClose`.
82748274
*/
82758275
"autoCloseDuration"?: AlertDuration;
8276+
/**
8277+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
8278+
*/
8279+
"embedded"?: boolean;
82768280
/**
82778281
* When `true`, shows a default recommended icon. Alternatively, pass a Calcite UI Icon name to display a specific icon.
82788282
*/
@@ -8340,10 +8344,6 @@ declare namespace LocalJSX {
83408344
* Specifies the size of the component.
83418345
*/
83428346
"scale"?: Scale;
8343-
/**
8344-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
8345-
*/
8346-
"slottedInShell"?: boolean;
83478347
}
83488348
interface CalciteAvatar {
83498349
/**
@@ -11359,6 +11359,10 @@ declare namespace LocalJSX {
1135911359
* When `true`, prevents the component from expanding to the entire screen on mobile devices.
1136011360
*/
1136111361
"docked"?: boolean;
11362+
/**
11363+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
11364+
*/
11365+
"embedded"?: boolean;
1136211366
/**
1136311367
* When `true`, disables the default close on escape behavior.
1136411368
*/
@@ -11415,10 +11419,6 @@ declare namespace LocalJSX {
1141511419
* Specifies the size of the component.
1141611420
*/
1141711421
"scale"?: Scale;
11418-
/**
11419-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
11420-
*/
11421-
"slottedInShell"?: boolean;
1142211422
/**
1142311423
* Specifies the width of the component.
1142411424
*/
@@ -12330,6 +12330,10 @@ declare namespace LocalJSX {
1233012330
* Specifies the display mode - `"float"` (content is separated detached), or `"overlay"` (displays on top of center content).
1233112331
*/
1233212332
"displayMode"?: DisplayMode;
12333+
/**
12334+
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
12335+
*/
12336+
"embedded"?: boolean;
1233312337
/**
1233412338
* When `true`, disables the default close on escape behavior.
1233512339
*/
@@ -12378,10 +12382,6 @@ declare namespace LocalJSX {
1237812382
* Determines where the component will be positioned.
1237912383
*/
1238012384
"position"?: LogicalFlowPosition;
12381-
/**
12382-
* This internal property, managed by a containing calcite-shell, is used to inform the component if special configuration or styles are needed
12383-
*/
12384-
"slottedInShell"?: boolean;
1238512385
/**
1238612386
* When `position` is `"inline-start"` or `"inline-end"`, specifies the width of the component.
1238712387
*/

packages/calcite-components/src/components/alert/alert.e2e.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ describe("defaults", () => {
1111
propertyName: "autoCloseDuration",
1212
defaultValue: "medium",
1313
},
14+
{
15+
propertyName: "embedded",
16+
defaultValue: false,
17+
},
1418
]);
1519
});
1620

packages/calcite-components/src/components/alert/alert.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ $alertDurations:
315315
/**
316316
* Conditional styles for when Alert is slotted in Shell
317317
*/
318-
.container--slotted-in-shell {
318+
.container--embedded {
319319
@apply absolute;
320320
}
321321

packages/calcite-components/src/components/alert/alert.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
9393
/** Specifies the duration before the component automatically closes - only use with `autoClose`. */
9494
@Prop({ reflect: true }) autoCloseDuration: AlertDuration = "medium";
9595

96+
/**
97+
* This internal property, managed by a containing calcite-shell, is used
98+
* to inform the component if special configuration or styles are needed
99+
*
100+
* @internal
101+
*/
102+
@Prop({ mutable: true }) embedded = false;
103+
96104
/** Specifies the kind of the component, which will apply to top border and icon. */
97105
@Prop({ reflect: true }) kind: Extract<
98106
"brand" | "danger" | "info" | "success" | "warning",
@@ -141,14 +149,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
141149
/* wired up by t9n util */
142150
}
143151

144-
/**
145-
* This internal property, managed by a containing calcite-shell, is used
146-
* to inform the component if special configuration or styles are needed
147-
*
148-
* @internal
149-
*/
150-
@Prop({ mutable: true }) slottedInShell: boolean;
151-
152152
@Watch("autoCloseDuration")
153153
updateDuration(): void {
154154
if (this.autoClose && this.autoCloseTimeoutId) {
@@ -205,7 +205,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
205205
window.clearTimeout(this.queueTimeout);
206206
disconnectLocalized(this);
207207
disconnectMessages(this);
208-
this.slottedInShell = false;
208+
this.embedded = false;
209209
}
210210

211211
render(): VNode {
@@ -227,7 +227,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
227227
[CSS.container]: true,
228228
[CSS.containerQueued]: queued,
229229
[`${CSS.container}--${placement}`]: true,
230-
[CSS.containerSlottedInShell]: this.slottedInShell,
230+
[CSS.containerEmbedded]: this.embedded,
231231
[CSS.focused]: this.keyBoardFocus,
232232
}}
233233
onPointerEnter={this.autoClose && this.autoCloseTimeoutId ? this.handleMouseOver : null}

packages/calcite-components/src/components/alert/resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const CSS = {
2727
dismissProgress: "dismiss-progress",
2828
footer: "footer",
2929
icon: "icon",
30-
containerSlottedInShell: "container--slotted-in-shell",
30+
containerEmbedded: "container--embedded",
3131
queueCount: "queue-count",
3232
queueCountActive: "queue-count--active",
3333
textContainer: "text-container",

packages/calcite-components/src/components/flow-item/flow-item.e2e.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import {
1212
t9n,
1313
} from "../../tests/commonTests";
1414
import { html } from "../../../support/formatting";
15+
import { GlobalTestProps } from "../../tests/utils";
1516
import { CSS, SLOTS } from "./resources";
1617

18+
type TestWindow = GlobalTestProps<{
19+
beforeClose: () => Promise<void>;
20+
}>;
21+
1722
describe("calcite-flow-item", () => {
1823
describe("renders", () => {
1924
renders("calcite-flow-item", { display: "flex" });
@@ -210,8 +215,7 @@ describe("calcite-flow-item", () => {
210215

211216
await page.$eval(
212217
"calcite-flow-item",
213-
(el: HTMLCalciteFlowItemElement) =>
214-
(el.beforeClose = (window as typeof window & Pick<typeof el, "beforeClose">).beforeClose),
218+
(el: HTMLCalciteFlowItemElement) => (el.beforeClose = (window as TestWindow).beforeClose),
215219
);
216220

217221
await page.waitForChanges();
@@ -327,4 +331,21 @@ describe("calcite-flow-item", () => {
327331
expect(toggleSpy).toHaveReceivedEventTimes(1);
328332
expect(await panel.getProperty("closed")).toBe(true);
329333
});
334+
335+
it("should set embedded on slotted alerts", async () => {
336+
const page = await newE2EPage({
337+
html: html`<calcite-flow-item closable>
338+
test
339+
<calcite-alert slot="alerts" open label="this is a default alert">
340+
<div slot="title">Hello there!</div>
341+
<div slot="message">This is an alert with a general piece of information. Cool, innit?</div>
342+
</calcite-alert>
343+
</calcite-flow-item>`,
344+
});
345+
await page.waitForChanges();
346+
347+
const alert = await page.find("calcite-alert");
348+
349+
expect(await alert.getProperty("embedded")).toBe(true);
350+
});
330351
});

packages/calcite-components/src/components/flow-item/flow-item.stories.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { collapseDirection, scale } = ATTRIBUTES;
88
interface FlowItemStoryArgs
99
extends Pick<
1010
FlowItem,
11-
"closed" | "disabled" | "closable" | "collapsible" | "collapsed" | "collapseDirection" | "loading"
11+
"closed" | "disabled" | "closable" | "collapsible" | "collapsed" | "collapseDirection" | "loading" | "scale"
1212
> {
1313
heightScale: string;
1414
}
@@ -263,3 +263,13 @@ export const withNoHeaderBorderBlockEnd_TestOnly = (): string =>
263263
html`<calcite-flow-item style="--calcite-flow-item-header-border-block-end:none;" height-scale="s" heading="My Panel"
264264
>Slotted content!</calcite-flow-item
265265
>`;
266+
267+
export const withAlertsSlot = (): string => html`
268+
<calcite-flow-item height-scale="s" heading="My Panel" style="width: 500px; height:200px">
269+
Slotted content!
270+
<calcite-alert slot="alerts" open label="this is a default alert" scale="s">
271+
<div slot="title">Hello there!</div>
272+
<div slot="message">This is an alert with a general piece of information. Cool, innit?</div>
273+
</calcite-alert>
274+
</calcite-flow-item>
275+
`;

packages/calcite-components/src/components/flow-item/flow-item.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { CSS, ICONS, SLOTS } from "./resources";
4444
/**
4545
* @slot - A slot for adding custom content.
4646
* @slot action-bar - A slot for adding a `calcite-action-bar` to the component.
47+
* @slot alerts - A slot for adding `calcite-alert`s to the component.
4748
* @slot content-top - A slot for adding content above the unnamed (default) slot and below the action-bar slot (if populated).
4849
* @slot content-bottom - A slot for adding content below the unnamed (default) slot and above the footer slot (if populated)
4950
* @slot header-actions-start - A slot for adding `calcite-action`s or content to the start side of the component's header.
@@ -396,6 +397,7 @@ export class FlowItem
396397
>
397398
{this.renderBackButton()}
398399
<slot name={SLOTS.actionBar} slot={PANEL_SLOTS.actionBar} />
400+
<slot name={SLOTS.alerts} slot={PANEL_SLOTS.alerts} />
399401
<slot name={SLOTS.headerActionsStart} slot={PANEL_SLOTS.headerActionsStart} />
400402
<slot name={SLOTS.headerActionsEnd} slot={PANEL_SLOTS.headerActionsEnd} />
401403
<slot name={SLOTS.headerContent} slot={PANEL_SLOTS.headerContent} />

packages/calcite-components/src/components/flow-item/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const ICONS = {
99

1010
export const SLOTS = {
1111
actionBar: "action-bar",
12+
alerts: "alerts",
1213
contentTop: "content-top",
1314
contentBottom: "content-bottom",
1415
headerActionsStart: "header-actions-start",

packages/calcite-components/src/components/modal/modal.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ slot[name="primary"] {
411411
* Conditional styles for when Modal is slotted in Shell
412412
*/
413413

414-
.container.slotted-in-shell {
414+
.container--embedded {
415415
position: absolute;
416416
pointer-events: auto;
417417
calcite-scrim {

packages/calcite-components/src/components/modal/modal.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ export class Modal
122122
/** When `true`, prevents the component from expanding to the entire screen on mobile devices. */
123123
@Prop({ reflect: true }) docked: boolean;
124124

125+
/**
126+
* This internal property, managed by a containing calcite-shell, is used
127+
* to inform the component if special configuration or styles are needed
128+
*
129+
* @internal
130+
*/
131+
@Prop({ mutable: true }) embedded = false;
132+
125133
/** When `true`, disables the default close on escape behavior. */
126134
@Prop({ reflect: true }) escapeDisabled = false;
127135

@@ -156,14 +164,6 @@ export class Modal
156164
/* wired up by t9n util */
157165
}
158166

159-
/**
160-
* This internal property, managed by a containing calcite-shell, is used
161-
* to inform the component if special configuration or styles are needed
162-
*
163-
* @internal
164-
*/
165-
@Prop({ mutable: true }) slottedInShell: boolean;
166-
167167
//--------------------------------------------------------------------------
168168
//
169169
// Lifecycle
@@ -202,7 +202,7 @@ export class Modal
202202
deactivateFocusTrap(this);
203203
disconnectLocalized(this);
204204
disconnectMessages(this);
205-
this.slottedInShell = false;
205+
this.embedded = false;
206206
}
207207

208208
render(): VNode {
@@ -217,7 +217,7 @@ export class Modal
217217
class={{
218218
[CSS.container]: true,
219219
[CSS.containerOpen]: this.opened,
220-
[CSS.slottedInShell]: this.slottedInShell,
220+
[CSS.containerEmbedded]: this.embedded,
221221
}}
222222
>
223223
<calcite-scrim class={CSS.scrim} onClick={this.handleOutsideClose} />
@@ -534,7 +534,7 @@ export class Modal
534534
this.titleId = ensureId(titleEl);
535535
this.contentId = ensureId(contentEl);
536536

537-
if (!this.slottedInShell) {
537+
if (!this.embedded) {
538538
if (totalOpenModals === 0) {
539539
initialDocumentOverflowStyle = document.documentElement.style.overflow;
540540
}

packages/calcite-components/src/components/modal/resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export const CSS = {
1010
primary: "primary",
1111
container: "container",
1212
containerOpen: "container--open",
13+
containerEmbedded: "container--embedded",
1314
content: "content",
1415
contentNoFooter: "content--no-footer",
1516
contentBottom: "content-bottom",
1617
contentTop: "content-top",
17-
slottedInShell: "slotted-in-shell",
1818

1919
// these classes help apply the animation in phases to only set transform on open/close
2020
// this helps avoid a positioning issue for any floating-ui-owning children

0 commit comments

Comments
 (0)