Skip to content

Commit 6a97001

Browse files
committed
feat(alertbanner): migrate to spectrum two
Migrates the component to spectrum two. - Theme files are removed, and their custom properties integrated into the main index.css. - Renames misspelled mod custom property (noted in docs) - Simplifies background color styles by changing a single custom property per variant, as done on other components.
1 parent 4d9e185 commit 6a97001

File tree

7 files changed

+70
-118
lines changed

7 files changed

+70
-118
lines changed

components/alertbanner/index.css

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ OF ANY KIND, either express or implied. See the License for the specific languag
99
governing permissions and limitations under the License.
1010
*/
1111

12-
@import "./themes/express.css";
13-
1412
.spectrum-AlertBanner {
1513
--spectrum-alert-banner-min-height: var(--spectrum-alert-banner-minimum-height);
1614
--spectrum-alert-banner-size: var(--spectrum-alert-banner-width);
@@ -28,8 +26,7 @@ governing permissions and limitations under the License.
2826
--spectrum-alert-banner-bottom-text: var(--spectrum-alert-banner-bottom-to-text);
2927

3028
/* colors */
31-
--spectrum-alert-banner-informative-background: var(--spectrum-informative-background-color-default);
32-
--spectrum-alert-banner-negative-background: var(--spectrum-negative-background-color-default);
29+
--spectrum-alert-banner-background: var(--mod-alert-banner-neutral-background, var(--spectrum-neutral-subdued-background-color-default));
3330
--spectrum-alert-banner-font-color: var(--spectrum-white);
3431

3532
/* settings for nested Divider */
@@ -48,29 +45,29 @@ governing permissions and limitations under the License.
4845
--mod-closebutton-align-self: flex-start;
4946
}
5047

48+
.spectrum-AlertBanner--info {
49+
--spectrum-alert-banner-background: var(--mod-alert-banner-informative-background, var(--spectrum-informative-background-color-default));
50+
}
51+
52+
.spectrum-AlertBanner--negative {
53+
--spectrum-alert-banner-background: var(--mod-alert-banner-negative-background, var(--spectrum-negative-background-color-default));
54+
}
55+
5156
.spectrum-AlertBanner {
5257
display: none;
5358
justify-content: space-between;
5459
inline-size: var(--mod-alert-banner-size, var(--spectrum-alert-banner-size));
5560
min-block-size: var(--mod-alert-banner-min-height, var(--spectrum-alert-banner-min-height));
5661
font-size: var(--mod-alert-banner-font-size, var(--spectrum-alert-banner-font-size));
5762
color: var(--mod-alert-banner-font-color, var(--spectrum-alert-banner-font-color));
58-
background-color: var(--mod-alert-banner-netural-background, var(--spectrum-alert-banner-netural-background));
63+
background-color: var(--mod-alert-banner-background, var(--spectrum-alert-banner-background));
5964
border: var(--highcontrast-alert-banner-border-width, 0) solid var(--highcontrast-alert-banner-border-color, transparent);
6065

6166
&.is-open {
6267
display: flex;
6368
}
6469
}
6570

66-
.spectrum-AlertBanner--info {
67-
background-color: var(--mod-alert-banner-informative-background, var(--spectrum-alert-banner-informative-background));
68-
}
69-
70-
.spectrum-AlertBanner--negative {
71-
background-color: var(--mod-alert-banner-negative-background, var(--spectrum-alert-banner-negative-background));
72-
}
73-
7471
.spectrum-AlertBanner-body {
7572
inline-size: 100%;
7673
display: flex;

components/alertbanner/metadata/alertbanner.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
name: Alert banner
22
description: Alert banners show pressing and high-signal messages, such as system alerts. They're meant to be noticed and prompt users to take action.
3+
SpectrumSiteSlug: https://spectrum.adobe.com/page/alert-banner/
4+
sections:
5+
- name: Custom Properties API
6+
description: |
7+
This component can be modified via its `--mod-*` prefixed custom properties. A list of those prefixed custom properties can be found <a class="spectrum-Link" href="https://github.com/adobe/spectrum-css/tree/main/components/alertbanner/metadata/mods.md">here</a>.
8+
- name: Migration Guide
9+
description: |
10+
### Version 2.0.0
11+
#### Spectrum 2 release
12+
Alert banner now uses Spectrum 2 tokens and specifications. In this new design, the divider has been removed. A few other notable changes and additions:
13+
- The mod custom property `--mod-alert-banner-netural-background` was misspelled and has been renamed to `--mod-alert-banner-neutral-background`. The
14+
mod `--mod-alert-banner-background` was also added, which will take precendence over the variant background mods.
315
examples:
416
- id: alertbanner
517
name: Neutral
@@ -12,7 +24,6 @@ examples:
1224
</div>
1325
</div>
1426
<div class="spectrum-AlertBanner-end">
15-
<div class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--vertical spectrum-Divider--staticWhite"></div>
1627
<button class="spectrum-CloseButton spectrum-CloseButton--sizeM spectrum-CloseButton--staticWhite" aria-label="close">
1728
<svg class="spectrum-CloseButton-UIIcon spectrum-Icon spectrum-UIIcon-Cross200" focusable="false" aria-hidden="true">
1829
<use xlink:href="#spectrum-css-icon-Cross200" />
@@ -32,7 +43,6 @@ examples:
3243
</button>
3344
</div>
3445
<div class="spectrum-AlertBanner-end">
35-
<div class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--vertical spectrum-Divider--staticWhite"></div>
3646
<button class="spectrum-CloseButton spectrum-CloseButton--sizeM spectrum-CloseButton--staticWhite" aria-label="close">
3747
<svg class="spectrum-CloseButton-UIIcon spectrum-Icon spectrum-UIIcon-Cross200" focusable="false" aria-hidden="true">
3848
<use xlink:href="#spectrum-css-icon-Cross200" />
@@ -52,7 +62,6 @@ examples:
5262
</button>
5363
</div>
5464
<div class="spectrum-AlertBanner-end">
55-
<div class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--vertical spectrum-Divider--staticWhite"></div>
5665
<button class="spectrum-CloseButton spectrum-CloseButton--sizeM spectrum-CloseButton--staticWhite" aria-label="close">
5766
<svg class="spectrum-CloseButton-UIIcon spectrum-Icon spectrum-UIIcon-Cross200" focusable="false" aria-hidden="true">
5867
<use xlink:href="#spectrum-css-icon-Cross200" />
@@ -77,7 +86,6 @@ examples:
7786
</button>
7887
</div>
7988
<div class="spectrum-AlertBanner-end">
80-
<div class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--vertical spectrum-Divider--staticWhite"></div>
8189
<button class="spectrum-CloseButton spectrum-CloseButton--sizeM spectrum-CloseButton--staticWhite" aria-label="close" >
8290
<svg class="spectrum-CloseButton-UIIcon spectrum-Icon spectrum-UIIcon-Cross200" focusable="false" aria-hidden="true">
8391
<use xlink:href="#spectrum-css-icon-Cross200" />
@@ -102,7 +110,6 @@ examples:
102110
</button>
103111
</div>
104112
<div class="spectrum-AlertBanner-end">
105-
<div class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--vertical spectrum-Divider--staticWhite"></div>
106113
<button class="spectrum-CloseButton spectrum-CloseButton--sizeM spectrum-CloseButton--staticWhite" aria-label="close">
107114
<svg class="spectrum-CloseButton-UIIcon spectrum-Icon spectrum-UIIcon-Cross200" focusable="false" aria-hidden="true">
108115
<use xlink:href="#spectrum-css-icon-Cross200" />

components/alertbanner/metadata/mods.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| Modifiable custom properties |
22
| ---------------------------------------------- |
3+
| `--mod-alert-banner-background` |
34
| `--mod-alert-banner-bottom-text` |
45
| `--mod-alert-banner-close-button-spacing` |
56
| `--mod-alert-banner-edge-to-button` |
@@ -11,7 +12,7 @@
1112
| `--mod-alert-banner-informative-background` |
1213
| `--mod-alert-banner-min-height` |
1314
| `--mod-alert-banner-negative-background` |
14-
| `--mod-alert-banner-netural-background` |
15+
| `--mod-alert-banner-neutral-background` |
1516
| `--mod-alert-banner-size` |
1617
| `--mod-alert-banner-start-edge` |
1718
| `--mod-alert-banner-text-to-button-horizontal` |
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { html } from "lit";
2+
import { when } from "lit/directives/when.js";
23
import { Template } from "./template";
34

45
export default {
56
title: "Components/Alert banner",
67
description:
78
"The Alert banner show pressing and high-signal messages, such as system alerts. They’re meant to be noticed and prompt users to take action.",
89
component: "AlertBanner",
10+
subtitle: "Testing",
911
argTypes: {
1012
isOpen: {
1113
name: "Open",
14+
description: "Determines whether the banner is visible or hidden.",
1215
type: { name: "boolean" },
1316
table: {
1417
type: { summary: "boolean" },
@@ -18,39 +21,42 @@ export default {
1821
},
1922
text: {
2023
name: "Text",
24+
description: "Text of the message displayed within the alert banner.",
2125
type: { name: "string", required: true },
2226
table: {
2327
type: { summary: "string" },
2428
disable: false,
25-
category: "Component",
29+
category: "Content",
2630
},
2731
control: { type: "text" },
2832
},
2933
variant: {
30-
name: "Background color variants",
34+
name: "Semantic variants",
3135
type: { name: "string" },
3236
table: {
3337
type: { summary: "string" },
3438
category: "Component",
39+
defaultValue: { summary: "neutral" },
3540
},
3641
options: ["neutral", "info", "negative"],
3742
control: "radio",
3843
},
39-
hasActionButton: {
40-
name: "Display action button",
41-
type: { name: "boolean" },
44+
actionButtonText: {
45+
name: "Action button text",
46+
description: "Label text for the optional action button. When empty, the action button does not display.",
47+
type: { name: "string" },
4248
table: {
43-
type: { summary: "boolean" },
44-
category: "State",
49+
type: { summary: "string" },
50+
category: "Content",
4551
},
46-
control: "boolean",
52+
control: "text",
4753
},
4854
},
4955
args: {
5056
rootClass: "spectrum-AlertBanner",
5157
isOpen: true,
5258
variant: "neutral",
53-
hasActionButton: true,
59+
actionButtonText: "Action",
5460
text: "Your trial has expired",
5561
},
5662
parameters: {
@@ -63,33 +69,25 @@ export default {
6369
},
6470
};
6571

66-
const AlertBannerGroup = ({
67-
...args
68-
}) => {
72+
const AlertBannerGroup = (args) => {
6973
return html`
7074
<div style="display: flex; flex-direction: column; gap: 1rem">
71-
${Template({
72-
...args,
73-
})}
74-
${window.isChromatic() ?
75-
Template({
76-
...args,
77-
hasActionButton: true,
78-
variant: "info",
79-
text: "Your trial will expire in 3 days. Once it expires your files will be saved and ready for you to open again once you have purcahsed the software."
80-
}): null }
81-
${window.isChromatic() ?
82-
Template({
83-
...args,
84-
hasActionButton: true,
85-
variant: "negative",
86-
text: "Connection interupted. Check your network to continue."
87-
})
88-
: null }
75+
${Template(args)}
76+
${when(window.isChromatic(), () => html`
77+
${Template({
78+
...args,
79+
variant: "info",
80+
text: "Your trial will expire in 3 days. Once it expires your files will be saved and ready for you to open again once you have purcahsed the software."
81+
})}
82+
${Template({
83+
...args,
84+
variant: "negative",
85+
text: "Connection interupted. Check your network to continue."
86+
})}
87+
`)}
8988
</div>
9089
`;
9190
};
9291

9392
export const Default = AlertBannerGroup.bind({});
94-
Default.args = {
95-
};
93+
Default.args = {};

components/alertbanner/stories/template.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { when } from "lit/directives/when.js";
44

55
import { Template as Button } from "@spectrum-css/button/stories/template.js";
66
import { Template as CloseButton } from "@spectrum-css/closebutton/stories/template.js";
7-
import { Template as Divider } from "@spectrum-css/divider/stories/template.js";
87
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
98

109
import "../index.css";
@@ -14,19 +13,10 @@ export const Template = ({
1413
isOpen = true,
1514
text,
1615
variant,
17-
hasActionButton,
16+
actionButtonText = "Action",
1817
customClasses = [],
1918
...globals
2019
}) => {
21-
const { express } = globals;
22-
23-
try {
24-
if (!express) import(/* webpackPrefetch: true */ "../themes/spectrum.css");
25-
else import(/* webpackPrefetch: true */ "../themes/express.css");
26-
}
27-
catch (e) {
28-
console.warn(e);
29-
}
3020
const iconName =
3121
variant === "negative" ? "Alert" : variant === "info" ? "Info" : "";
3222

@@ -35,36 +25,31 @@ export const Template = ({
3525
class=${classMap({
3626
[rootClass]: true,
3727
"is-open": isOpen,
38-
[`${rootClass}--${variant}`]: typeof variant !== "undefined",
28+
[`${rootClass}--${variant}`]: typeof variant !== "undefined" && variant !== "neutral",
3929
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
4030
})}
4131
>
4232
<div class="${rootClass}-body">
4333
<div class="${rootClass}-content">
44-
${iconName
45-
? Icon({
46-
...globals,
47-
iconName,
48-
customClasses: [`${rootClass}-icon`],
34+
${when(iconName, () =>
35+
Icon({
36+
...globals,
37+
iconName,
38+
customClasses: [`${rootClass}-icon`],
4939
})
50-
: ""}
40+
)}
5141
<p class="${rootClass}-text">${text}</p>
5242
</div>
53-
${when(hasActionButton, () =>
54-
Button({
55-
size: "m",
56-
variant: "staticWhite",
57-
treatment: "outline",
58-
label: "Action",
59-
}))}
43+
${when(actionButtonText, () =>
44+
Button({
45+
size: "m",
46+
variant: "staticWhite",
47+
treatment: "outline",
48+
label: actionButtonText,
49+
})
50+
)}
6051
</div>
6152
<div class="${rootClass}-end">
62-
${Divider({
63-
vertical: true,
64-
size: "s",
65-
tag: "div",
66-
...globals,
67-
})}
6853
${CloseButton({
6954
...globals,
7055
size: "m",

components/alertbanner/themes/express.css

Lines changed: 0 additions & 19 deletions
This file was deleted.

components/alertbanner/themes/spectrum.css

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)