Skip to content
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

feat(alert): add component tokens #10218

Merged
merged 18 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions packages/calcite-components/src/components/alert/alert.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { E2EElement, E2EPage, newE2EPage } from "@stencil/core/testing";
import { html } from "../../../support/formatting";
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";
import { openClose, themed } from "../../tests/commonTests";
import { CSS, DURATIONS, SLOTS } from "./resources";
import { alertQueueTimeoutMs } from "./AlertManager";

describe("defaults", () => {
Expand Down Expand Up @@ -351,8 +351,8 @@ describe("calcite-alert", () => {
await page.setContent(alertSnippet);
progressBarStyles = await page.evaluate(() => {
const alert = document.querySelector("calcite-alert");
alert.style.setProperty("--calcite-alert-dismiss-progress-background", "white");
return window.getComputedStyle(alert).getPropertyValue("--calcite-alert-dismiss-progress-background");
alert.style.setProperty("--calcite-internal-alert-dismiss-progress-background", "white");
return window.getComputedStyle(alert).getPropertyValue("--calcite-internal-alert-dismiss-progress-background");
});
expect(progressBarStyles).toEqual("white");
});
Expand Down Expand Up @@ -594,4 +594,37 @@ describe("calcite-alert", () => {
describe("translation support", () => {
t9n("calcite-alert");
});

describe("theme", () => {
themed(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break this into a "default" alert test followed by additional tests to cover tokens only effected by certain props. I.E. Slotted content styles

html`
<calcite-alert label="this is a default alert" scale="s">
<div slot="${SLOTS.title}">Test title</div>
<div slot="${SLOTS.message}">Test message</div>
</calcite-alert>
`,
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out why the commented-out tokens were failing:

diff --git i/packages/calcite-components/src/components/alert/alert.e2e.ts w/packages/calcite-components/src/components/alert/alert.e2e.ts
index b2ea33cbb..674b7ad02 100644
--- i/packages/calcite-components/src/components/alert/alert.e2e.ts
+++ w/packages/calcite-components/src/components/alert/alert.e2e.ts
@@ -605,39 +605,39 @@ describe("calcite-alert", () => {
       `,
       {
         /*"--calcite-alert-width": {
-        shadowSelector: `.${CSS.container}`,
-        targetProp: "inlineSize",
-      },*/
+          shadowSelector: `.${CSS.container}`, // 🕵 sizing styles depend on alert being open
+          targetProp: "inlineSize",
+        },*/
         "--calcite-alert-background-color": {
           shadowSelector: `.${CSS.container}`,
           targetProp: "backgroundColor",
         },
         /*"--calcite-alert-title-text-color": {
-          shadowSelector: `.${CSS.textContainer}`,
+          shadowSelector: `.${CSS.textContainer}`, // 🕵️ text color is applied to the slotted content, this targets the slot parent
           targetProp: "color",
         },*/
         /*"--calcite-alert-message-text-color": {
-        shadowSelector: `.${CSS.textContainer}`,
-        targetProp: "color",
-      },*/
+          shadowSelector: `.${CSS.textContainer}`, // 🕵️ text color is applied to the slotted content, this targets the slot parent
+          targetProp: "color",
+        },*/
         "--calcite-alert-corner-radius": {
           shadowSelector: `.${CSS.container}`,
           targetProp: "borderRadius",
         },
         /*"--calcite-alert-close-background-color-hover": {
-        shadowSelector: `.${CSS.close}`,
-        targetProp: "backgroundColor",
-        state: "hover",
-      },*/
+          shadowSelector: `.${CSS.close}`,
+          targetProp: "backgroundColor",
+          state: "hover",  // 🕵 stateful interactions depend on alert being open
+        },*/
         /*"--calcite-alert-close-background-color-pressed": {
-        shadowSelector: `.${CSS.close}`,
-        targetProp: "backgroundColor",
-        state: { press: { attribute: "class", value: CSS.close } },
-      },*/
+          shadowSelector: `.${CSS.close}`,
+          targetProp: "backgroundColor",
+          state: { press: { attribute: "class", value: CSS.close } }, // 🕵 stateful interactions depend on alert being open
+        },*/
         /*"--calcite-alert-dismiss-progress-background-color": {
-        shadowSelector: `.${CSS.dismissProgress}`,
-        targetProp: "backgroundColor",
-      },*/
+          shadowSelector: `.${CSS.dismissProgress}`,  // 🕵 the dismiss progress background color needs a different configuration (i.e., auto-close)
+          targetProp: "backgroundColor",
+        },*/
       },
     );
   });

Some changes will require separate, different test HTML (see example).

/*"--calcite-alert-width": {
shadowSelector: `.${CSS.container}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you search for --calcite-alert-width in the SCSS you will see it only applies to :host so you can remove the shadowSelector here. Either explicitly set selector: "calcite-alert" or take it off completely.

targetProp: "inlineSize",
},*/
"--calcite-alert-background-color": {
shadowSelector: `.${CSS.container}`,
targetProp: "backgroundColor",
},
/*"--calcite-alert-title-text-color": {
shadowSelector: `.${CSS.textContainer}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your selector should target the slot="title"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this test but it's still throwing an error.

"--calcite-alert-title-text-color": { selector: [slot="${SLOTS.title}"], targetProp: "color", },

targetProp: "color",
},*/
/*"--calcite-alert-message-text-color": {
shadowSelector: `.${CSS.textContainer}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as title this should target selector: [slot="message"]

targetProp: "color",
},*/
"--calcite-alert-corner-radius": {
shadowSelector: `.${CSS.container}`,
targetProp: "borderRadius",
},
},
);
});
});
103 changes: 61 additions & 42 deletions packages/calcite-components/src/components/alert/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-alert-width: Specifies the width of the component.
* @prop --calcite-alert-background-color: Specifies the component's background color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these tokens applied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--calcite-alert-width is being applied in .container:
inline-size: var(--calcite-alert-width, auto);

and in scales:
inline-size: var(--calcite-alert-width, 40rem);

--calcite-alert-background-color is being applied in .container:
background-color: var(--calcite-alert-background-color, var(--calcite-color-foreground-1));

* @prop --calcite-alert-title-text-color: Specifies the component's title text color.
* @prop --calcite-alert-message-text-color: Specifies the component's message text color.
* @prop --calcite-alert-corner-radius: Specifies the component's border radius.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user I might want to override the icon color rendered via prop, or the component's shadow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alisonailea @jcfranco Should we add tokens for these use cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss customizing the icon and progress color separately. The design spec has both sharing the color defined by kind. cc @alisonailea @SkyeSeitz @ashetland

*/

$border-style: 1px solid var(--calcite-color-border-3);

:host {
--calcite-alert-edge-distance: theme("spacing.8");
--calcite-alert-dismiss-progress-background: var(--calcite-color-transparent-tint);
--calcite-internal-alert-edge-distance: theme("spacing.8");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be alert-size not edge-distance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alert-size might not be accurate. This represents the distance used to place the alert along the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to --calcite-internal-alert-edge-distance

@apply block;
}

.container {
@apply bg-foreground-1
box-border
@apply box-border
fixed
flex
items-center
Expand All @@ -31,12 +33,13 @@ $border-style: 1px solid var(--calcite-color-border-3);
w-full
z-toast;

border-radius: var(--calcite-border-radius);
background-color: var(--calcite-alert-background-color, var(--calcite-color-foreground-1));
border-radius: var(--calcite-alert-corner-radius, var(--calcite-border-radius));
border-block-start: 0 solid transparent;
border-inline: $border-style;
border-block-end: $border-style;
inline-size: var(--calcite-alert-width);
max-inline-size: calc(100% - (var(--calcite-alert-edge-distance) * 2));
inline-size: var(--calcite-alert-width, auto);
max-inline-size: calc(100% - (var(--calcite-internal-alert-edge-distance) * 2));
transition:
opacity var(--calcite-internal-animation-timing-slow) $easing-function,
all var(--calcite-animation-timing) ease-in-out;
Expand All @@ -47,19 +50,19 @@ $border-style: 1px solid var(--calcite-color-border-3);
inset-inline-start: 0;
}
&[class*="bottom"] {
transform: translate3d(0, var(--calcite-alert-edge-distance), 0);
inset-block-end: var(--calcite-alert-edge-distance);
transform: translate3d(0, var(--calcite-internal-alert-edge-distance), 0);
inset-block-end: var(--calcite-internal-alert-edge-distance);
}
&[class*="top"] {
transform: translate3d(0, calc(-1 * var(--calcite-alert-edge-distance)), 0);
inset-block-start: var(--calcite-alert-edge-distance);
transform: translate3d(0, calc(-1 * var(--calcite-internal-alert-edge-distance)), 0);
inset-block-start: var(--calcite-internal-alert-edge-distance);
}
&[class*="start"] {
inset-inline-start: var(--calcite-alert-edge-distance);
inset-inline-start: var(--calcite-internal-alert-edge-distance);
inset-inline-end: auto;
}
&[class*="end"] {
inset-inline-end: var(--calcite-alert-edge-distance);
inset-inline-end: var(--calcite-internal-alert-edge-distance);
inset-inline-start: auto;
}
}
Expand All @@ -68,13 +71,11 @@ $border-style: 1px solid var(--calcite-color-border-3);
@apply flex flex-col items-center justify-center p-0;
margin-block: auto;
margin-inline-end: auto;
padding-inline-start: var(--calcite-alert-spacing-token-large);
}

.close {
@apply bg-transparent border-none cursor-pointer flex items-center justify-end outline-none self-stretch text-color-3;
-webkit-appearance: none;
padding: var(--calcite-alert-spacing-token-large);

@apply focus-base;
&:focus {
Expand All @@ -83,11 +84,12 @@ $border-style: 1px solid var(--calcite-color-border-3);

&:hover,
&:focus {
@apply bg-foreground-2 text-color-1;
@apply text-color-1;
background-color: var(--calcite-color-foreground-2);
}

&:active {
@apply bg-foreground-3;
background-color: var(--calcite-color-foreground-3);
}
}

Expand Down Expand Up @@ -129,7 +131,7 @@ $border-style: 1px solid var(--calcite-color-border-3);
block;
block-size: 2px;
content: "";
background-color: var(--calcite-alert-dismiss-progress-background);
background-color: var(--calcite-color-transparent-tint);
inset-inline-end: 0;
}
}
Expand All @@ -140,8 +142,6 @@ $border-style: 1px solid var(--calcite-color-border-3);

.text-container {
@apply box-border flex flex-auto min-w-0 flex-col break-words;
padding-block: var(--calcite-alert-spacing-token-small);
padding-inline: var(--calcite-alert-spacing-token-large) var(--calcite-alert-spacing-token-small);
}

.footer {
Expand All @@ -151,11 +151,7 @@ $border-style: 1px solid var(--calcite-color-border-3);

// scale variables
:host([scale="s"]) {
--calcite-alert-width: 40em;
--calcite-alert-spacing-token-small: theme("spacing.2");
--calcite-alert-spacing-token-large: theme("spacing.3");
--calcite-alert-footer-height: theme("height.8");
--calcite-alert-footer-divider-gap: theme("spacing[0.5]");
inline-size: var(--calcite-alert-width, 40rem);

@include slotted("title", "*") {
@apply text-n1-wrap;
Expand All @@ -170,16 +166,22 @@ $border-style: 1px solid var(--calcite-color-border-3);
@apply mx-2;
}
.container {
--calcite-alert-min-height: 3.5rem;
--calcite-internal-alert-min-height: 3.5rem;
}
.close {
padding: theme("spacing.3");
}
.icon {
padding-inline-start: theme("spacing.3");
}
.text-container {
padding-block: theme("spacing.2");
padding-inline: theme("spacing.3") theme("spacing.2");
}
}

:host([scale="m"]) {
--calcite-alert-width: 50em;
--calcite-alert-spacing-token-small: theme("spacing.3");
--calcite-alert-spacing-token-large: theme("spacing.4");
--calcite-alert-footer-height: theme("height.12");
--calcite-alert-footer-divider-gap: theme("spacing.1");
inline-size: var(--calcite-alert-width, 50rem);

@include slotted("title", "*") {
@apply text-0-wrap;
Expand All @@ -194,16 +196,22 @@ $border-style: 1px solid var(--calcite-color-border-3);
@apply mx-3;
}
.container {
--calcite-alert-min-height: 4.1875rem;
--calcite-internal-alert-min-height: 4.1875rem;
}
.close {
padding: theme("spacing.4");
}
.icon {
padding-inline-start: theme("spacing.4");
}
.text-container {
padding-block: theme("spacing.3");
padding-inline: theme("spacing.4") theme("spacing.3");
}
}

:host([scale="l"]) {
--calcite-alert-width: 60em;
--calcite-alert-spacing-token-small: theme("spacing.4");
--calcite-alert-spacing-token-large: theme("spacing.5");
--calcite-alert-footer-height: theme("height.16");
--calcite-alert-footer-divider-gap: theme("spacing.2");
inline-size: var(--calcite-alert-width, 60rem);

@include slotted("title", "*") {
@apply text-1-wrap mb-1;
Expand All @@ -218,7 +226,17 @@ $border-style: 1px solid var(--calcite-color-border-3);
@apply mx-4;
}
.container {
--calcite-alert-min-height: 5.625rem;
--calcite-internal-alert-min-height: 5.625rem;
}
.close {
padding: theme("spacing.5");
}
.icon {
padding-inline-start: theme("spacing.5");
}
.text-container {
padding-block: theme("spacing.4");
padding-inline: theme("spacing.5") theme("spacing.4");
}
}

Expand All @@ -227,10 +245,10 @@ $border-style: 1px solid var(--calcite-color-border-3);
@apply border-t-2 opacity-100;
pointer-events: initial;
&[class*="bottom"] {
transform: translate3d(0, calc(-1 * var(--calcite-alert-edge-distance)), inherit);
transform: translate3d(0, calc(-1 * var(--calcite-internal-alert-edge-distance)), inherit);
}
&[class*="top"] {
transform: translate3d(0, var(--calcite-alert-edge-distance), inherit);
transform: translate3d(0, var(--calcite-internal-alert-edge-distance), inherit);
}
}
}
Expand All @@ -241,17 +259,18 @@ $border-style: 1px solid var(--calcite-color-border-3);

@include slotted("title", "*") {
@apply text-0-wrap
text-color-1
font-medium;

color: var(--calcite-alert-title-text-color, var(--calcite-color-text-1));
}

@include slotted("message", "*") {
@apply text-n1-wrap
text-color-2
m-0
inline
font-normal;
margin-inline-end: theme("margin.2");
color: var(--calcite-alert-message-text-color, var(--calcite-color-text-2));
}

@include slotted("link", "*") {
Expand Down
4 changes: 4 additions & 0 deletions packages/calcite-components/src/custom-theme.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
actionPadTokens,
actionGroupTokens,
} from "./custom-theme/action";
import { alertTokens, alert } from "./custom-theme/alert";
import { accordionItemTokens } from "./custom-theme/accordion-item";
import { accordion, accordionTokens } from "./custom-theme/accordion";
import { buttons } from "./custom-theme/button";
Expand Down Expand Up @@ -112,6 +113,7 @@ const kitchenSink = (args: Record<string, string>, useTestValues = false) =>
${chips} ${pagination} ${slider}
</div>
<div class="demo-column">${datePicker} ${tabs} ${loader} ${calciteSwitch} ${progress} ${handle}</div>
${alert}
</div>
</div>
</div>`;
Expand All @@ -128,6 +130,7 @@ export default {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...alertTokens,
...checkboxTokens,
...handleTokens,
...progressTokens,
Expand All @@ -150,6 +153,7 @@ export const theming_TestOnly = (): string => {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...alertTokens,
...checkboxTokens,
...handleTokens,
...progressTokens,
Expand Down
12 changes: 12 additions & 0 deletions packages/calcite-components/src/custom-theme/alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { html } from "../../support/formatting";
import { SLOTS } from "../components/alert/resources";

export const alertTokens = {
calciteAlertBackgroundColor: "",
calciteAlertCornerRadius: "",
};

export const alert = html`<calcite-alert label="this is a default alert" scale="s" open>
<div slot="${SLOTS.title}">Test title</div>
<div slot="${SLOTS.message}">Test message</div>
</calcite-alert>`;
Loading