-
Notifications
You must be signed in to change notification settings - Fork 89
feat(alert): add 'queue' property to prioritize the ordering of alerts when opened #10029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
042e866
12009f5
a6e416d
4479751
ea1f450
82669cc
78ab672
1ea9c1c
207e7cf
3ad4857
24e1a28
3020339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||||
| import { E2EElement, E2EPage, newE2EPage } from "@stencil/core/testing"; | ||||||||||
| import { html } from "../../../support/formatting"; | ||||||||||
| import { accessible, defaults, hidden, HYDRATED_ATTR, renders, t9n } from "../../tests/commonTests"; | ||||||||||
| import { getElementXY } from "../../tests/utils"; | ||||||||||
| import { accessible, defaults, hidden, HYDRATED_ATTR, reflects, renders, t9n } from "../../tests/commonTests"; | ||||||||||
| import { getElementXY, skipAnimations } from "../../tests/utils"; | ||||||||||
| import { openClose } from "../../tests/commonTests"; | ||||||||||
| import { CSS, DURATIONS } from "./resources"; | ||||||||||
|
|
||||||||||
|
|
@@ -15,6 +15,19 @@ describe("defaults", () => { | |||||||||
| propertyName: "embedded", | ||||||||||
| defaultValue: false, | ||||||||||
| }, | ||||||||||
| { | ||||||||||
| propertyName: "queue", | ||||||||||
| defaultValue: "last", | ||||||||||
| }, | ||||||||||
| ]); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| describe("reflects", () => { | ||||||||||
| reflects("calcite-alert", [ | ||||||||||
| { | ||||||||||
| propertyName: "queue", | ||||||||||
| value: "last", | ||||||||||
| }, | ||||||||||
| ]); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
|
|
@@ -189,6 +202,85 @@ describe("calcite-alert", () => { | |||||||||
| expect(await alert3.isVisible()).toBe(true); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it("should queue alerts", async () => { | ||||||||||
| const page = await newE2EPage(); | ||||||||||
| await skipAnimations(page); | ||||||||||
| await page.setContent(html` | ||||||||||
| <calcite-alert id="alert-1"> ${alertContent} </calcite-alert> | ||||||||||
| <calcite-alert id="alert-2"> ${alertContent} </calcite-alert> | ||||||||||
| <calcite-alert id="alert-3"> ${alertContent} </calcite-alert> | ||||||||||
| `); | ||||||||||
|
|
||||||||||
| const alert1 = await page.find("#alert-1"); | ||||||||||
| const alert2 = await page.find("#alert-2"); | ||||||||||
| const alert3 = await page.find("#alert-3"); | ||||||||||
|
|
||||||||||
| expect(await alert1.isVisible()).toBe(false); | ||||||||||
| expect(await alert2.isVisible()).toBe(false); | ||||||||||
| expect(await alert3.isVisible()).toBe(false); | ||||||||||
|
|
||||||||||
| alert1.setProperty("open", true); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| alert2.setProperty("open", true); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| alert3.setProperty("queue", "immediate"); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| alert3.setProperty("open", true); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check if this is needed? #9958 fixed some issues that prevented alert (among other components) from honoring
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is still needed because the queue uses a setTimeout to wait for the animation to end. calcite-design-system/packages/calcite-components/src/components/alert/alert.tsx Lines 528 to 531 in 089cecf
I think that above would need to change to pull from the CSS var Maybe a good follow up issue?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up issue sounds good. Thanks for checking!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
|
|
||||||||||
| expect(await alert1.isVisible()).toBe(true); | ||||||||||
| expect(await alert2.isVisible()).toBe(true); | ||||||||||
| expect(await alert3.isVisible()).toBe(true); | ||||||||||
|
|
||||||||||
| const alert1Container = await page.find(`#alert-1 >>> .${CSS.container}`); | ||||||||||
| const alert2Container = await page.find(`#alert-2 >>> .${CSS.container}`); | ||||||||||
| const alert3Container = await page.find(`#alert-3 >>> .${CSS.container}`); | ||||||||||
|
|
||||||||||
| expect(await alert1Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert2Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert3Container.isVisible()).toBe(true); | ||||||||||
|
|
||||||||||
| alert3.setProperty("queue", "immediate"); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| alert2.setProperty("queue", "immediate"); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
|
||||||||||
| expect(await alert1Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert2Container.isVisible()).toBe(true); | ||||||||||
| expect(await alert3Container.isVisible()).toBe(false); | ||||||||||
|
|
||||||||||
| alert1.setProperty("queue", "next"); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
|
||||||||||
| alert2.setProperty("open", false); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
|
||||||||||
| expect(await alert1Container.isVisible()).toBe(true); | ||||||||||
| expect(await alert2Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert3Container.isVisible()).toBe(false); | ||||||||||
|
|
||||||||||
| alert2.setProperty("queue", "next"); | ||||||||||
| alert2.setProperty("open", true); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
|
||||||||||
| expect(await alert1Container.isVisible()).toBe(true); | ||||||||||
| expect(await alert2Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert3Container.isVisible()).toBe(false); | ||||||||||
|
|
||||||||||
| alert1.setProperty("open", false); | ||||||||||
| await page.waitForChanges(); | ||||||||||
| await page.waitForTimeout(animationDurationInMs); | ||||||||||
|
|
||||||||||
| expect(await alert1Container.isVisible()).toBe(false); | ||||||||||
| expect(await alert2Container.isVisible()).toBe(true); | ||||||||||
| expect(await alert3Container.isVisible()).toBe(false); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it("correctly assigns a default placement class", async () => { | ||||||||||
| const page = await newE2EPage(); | ||||||||||
| await page.setContent(` | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,72 @@ | ||
| import { iconNames } from "../../../.storybook/helpers"; | ||
| import { modesDarkDefault } from "../../../.storybook/utils"; | ||
| import { boolean, modesDarkDefault } from "../../../.storybook/utils"; | ||
| import { html } from "../../../support/formatting"; | ||
| import { ATTRIBUTES } from "../../../.storybook/resources"; | ||
| import { menuPlacements } from "../../utils/floating-ui"; | ||
| import { Alert } from "./Alert"; | ||
| const { scale, duration, kind, numberingSystem, queue } = ATTRIBUTES; | ||
|
|
||
| interface AlertStoryArgs | ||
| extends Pick< | ||
| Alert, | ||
| | "autoClose" | ||
| | "autoCloseDuration" | ||
| | "icon" | ||
| | "iconFlipRtl" | ||
| | "kind" | ||
| | "label" | ||
| | "numberingSystem" | ||
| | "open" | ||
| | "placement" | ||
| | "scale" | ||
| | "queue" | ||
| > {} | ||
|
|
||
| export default { | ||
| title: "Components/Alert", | ||
| args: { | ||
| autoClose: false, | ||
| autoCloseDuration: duration.defaultValue, | ||
| icon: "", | ||
| iconFlipRtl: false, | ||
| kind: kind.defaultValue, | ||
| label: "Alert", | ||
| numberingSystem: numberingSystem[2], | ||
| open: true, | ||
| placement: menuPlacements[4], | ||
| scale: "m", | ||
| queue: "last", | ||
| }, | ||
| argTypes: { | ||
| autoCloseDuration: { | ||
| options: duration.values, | ||
| control: { type: "select" }, | ||
| }, | ||
| icon: { | ||
| options: iconNames, | ||
| control: { type: "select" }, | ||
| }, | ||
| kind: { | ||
| options: kind.values.filter((option) => option !== "inverse" && option !== "neutral"), | ||
| control: { type: "select" }, | ||
| }, | ||
| numberingSystem: { | ||
| options: numberingSystem, | ||
| control: { type: "select" }, | ||
| }, | ||
| placement: { | ||
| options: menuPlacements, | ||
| control: { type: "select" }, | ||
| }, | ||
| queue: { | ||
| options: queue.values, | ||
| control: { type: "select" }, | ||
| }, | ||
| scale: { | ||
| options: scale.values, | ||
| control: { type: "select" }, | ||
| }, | ||
| }, | ||
| parameters: { | ||
| chromatic: { | ||
| delay: 500, | ||
|
|
@@ -23,6 +86,29 @@ const wrapperStyles = html` | |
| </style> | ||
| `; | ||
|
|
||
| export const simple = (args: AlertStoryArgs): string => html` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨🏆✨ |
||
| ${wrapperStyles} | ||
| <div class="wrapper"> | ||
| <calcite-alert | ||
| ${boolean("auto-close", args.autoClose)} | ||
| ${boolean("open", args.open)} | ||
| ${boolean("icon-flip-rtl", args.iconFlipRtl)} | ||
| queue="${args.queue}" | ||
| auto-close-duration="${args.autoCloseDuration}" | ||
| scale="${args.scale}" | ||
| kind="${args.kind}" | ||
| icon="${args.icon}" | ||
| label="${args.label}" | ||
| numbering-system="${args.numberingSystem}" | ||
| placement="${args.placement}" | ||
| > | ||
| <div slot="title">Here's a general bit of information</div> | ||
| <div slot="message">Some kind of contextually relevant content</div> | ||
| <calcite-link slot="link" title="my action">Take action</calcite-link> | ||
| </calcite-alert> | ||
| </div> | ||
| `; | ||
|
|
||
| export const titleMessageLink = (): string => html` | ||
| ${wrapperStyles} | ||
| <div class="wrapper"> | ||
|
|
@@ -178,7 +264,7 @@ export const actionsEndQueued_TestOnly = (): string => html` | |
| <script> | ||
| setTimeout(() => { | ||
| document.querySelector("#two").open = true; | ||
| }, "1000"); | ||
| }, 250); | ||
| </script> | ||
| </div> | ||
| `; | ||
|
|
@@ -200,3 +286,29 @@ export const textAlignDoesNotAffectComponentAlignment_TestOnly = (): string => h | |
| </calcite-alert> | ||
| </div> | ||
| `; | ||
|
|
||
| export const withQueue = (): string => html` | ||
| ${wrapperStyles} | ||
| <div class="wrapper"> | ||
| <calcite-alert id="one" kind="brand" open> | ||
| <div slot="title">Open by default</div> | ||
| <div slot="message">We thought you might want to take a look</div> | ||
| </calcite-alert> | ||
| <calcite-alert id="two" queue="immediate" kind="danger"> | ||
| <div slot="title">Immediate Alert</div> | ||
| <div slot="message">We thought you might want to take a look</div> | ||
| </calcite-alert> | ||
| <calcite-alert id="three" kind="success"> | ||
| <div slot="title">Third Alert</div> | ||
| <div slot="message">We thought you might want to take a look</div> | ||
| </calcite-alert> | ||
| <script> | ||
| setTimeout(() => { | ||
| document.querySelector("#two").open = true; | ||
| }, 100); | ||
| setTimeout(() => { | ||
| document.querySelector("#three").open = true; | ||
| }, 250); | ||
| </script> | ||
| </div> | ||
| `; | ||
Uh oh!
There was an error while loading. Please reload this page.