Skip to content

Commit 8657dfb

Browse files
committed
feat(alertbanner): spectrum 2 spacing and mod name cleanup
Adjust some spacings to match the Spectrum 2 spec spacing. And renames some mods so they are more consistent with current naming conventions, and their purpose is more clear. === Update spacing to match the Spectrum 2 spec === One issue with the S1 version was that there was too much space between the text and the button, when the button wrapped to the next line. And there was a different token defined for the space from the bottom edge to the text, and vertically between the button and the text. This helps resolve this by moving some of the spacing to padding on the AlertBanner-body, and subtracting this value from some of the other custom properties. Along with using both column-gap and row-gap properties.
1 parent 6a97001 commit 8657dfb

File tree

4 files changed

+144
-70
lines changed

4 files changed

+144
-70
lines changed

components/alertbanner/index.css

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,41 @@ governing permissions and limitations under the License.
1111

1212
.spectrum-AlertBanner {
1313
--spectrum-alert-banner-min-height: var(--spectrum-alert-banner-minimum-height);
14-
--spectrum-alert-banner-size: var(--spectrum-alert-banner-width);
14+
--spectrum-alert-banner-inline-size: var(--spectrum-alert-banner-width);
1515
--spectrum-alert-banner-font-size: var(--spectrum-font-size-100);
16+
17+
/* @todo replace with font-size specific line-height token when one is available.
18+
Results in a line-height of 18px with font-size-100. */
19+
--spectrum-alert-banner-line-height: 1.28571428; /* stylelint-disable number-max-precision */
1620
--spectrum-alert-banner-icon-size: var(--spectrum-workflow-icon-size-100);
1721

1822
/* spacing */
1923
--spectrum-alert-banner-icon-to-text: var(--spectrum-text-to-visual-300);
20-
--spectrum-alert-banner-start-edge: var(--spectrum-spacing-300);
24+
--spectrum-alert-banner-inline-start-to-content: var(--spectrum-spacing-300);
2125
--spectrum-alert-banner-text-to-button-horizontal: var(--spectrum-spacing-300);
22-
/* stylelint-disable-next-line spectrum-tools/no-unused-custom-properties -- internal reference below; todo solve for this edge case in the plugin */
23-
--spectrum-alert-banner-text-to-divider: var(--spectrum-spacing-300);
24-
--spectrum-alert-banner-top-icon: var(--spectrum-alert-banner-top-to-workflow-icon);
25-
--spectrum-alert-banner-top-text: var(--spectrum-alert-banner-top-to-text);
26-
--spectrum-alert-banner-bottom-text: var(--spectrum-alert-banner-bottom-to-text);
26+
--spectrum-alert-banner-block-edge-to-button: var(--spectrum-spacing-200);
27+
--spectrum-alert-banner-close-button-to-content: var(--spectrum-spacing-300);
28+
--spectrum-alert-banner-close-button-to-inline-end: var(--spectrum-alert-banner-close-button-spacing);
29+
30+
/* Top and bottom margins for AlertBanner-text. Subtracts the vertical spacing that is already included in the
31+
padding-block of its parent AlertBanner-body element. */
32+
--spectrum-alert-banner-text-margin-block-start: max(0px,
33+
var(--mod-alert-banner-top-to-text, var(--spectrum-alert-banner-top-to-text)) -
34+
var(--mod-alert-banner-block-edge-to-button, var(--spectrum-alert-banner-block-edge-to-button))
35+
);
36+
--spectrum-alert-banner-text-margin-block-end: max(0px,
37+
var(--mod-alert-banner-bottom-to-text, var(--spectrum-alert-banner-bottom-to-text)) -
38+
var(--mod-alert-banner-block-edge-to-button, var(--spectrum-alert-banner-block-edge-to-button))
39+
);
2740

2841
/* colors */
2942
--spectrum-alert-banner-background: var(--mod-alert-banner-neutral-background, var(--spectrum-neutral-subdued-background-color-default));
3043
--spectrum-alert-banner-font-color: var(--spectrum-white);
3144

32-
/* settings for nested Divider */
33-
--mod-divider-vertical-margin: var(--mod-alert-banner-edge-to-divider, var(--spectrum-alert-banner-edge-to-divider));
34-
--mod-divider-vertical-height: auto;
35-
--mod-divider-vertical-align: stretch;
36-
37-
/* settings for nested Button */
38-
--mod-button-margin-block: var(--mod-alert-banner-edge-to-button, var(--spectrum-alert-banner-edge-to-button));
39-
--mod-button-margin-right: var(--mod-alert-banner-text-to-divider, var(--spectrum-alert-banner-text-to-divider));
40-
--mod-button-margin-left: auto;
41-
42-
/* settings for nested CloseButton */
43-
--mod-closebutton-margin-inline: var(--mod-alert-banner-close-button-spacing, var(--spectrum-alert-banner-close-button-spacing));
44-
--mod-closebutton-margin-top: var(--mod-alert-banner-close-button-spacing, var(--spectrum-alert-banner-close-button-spacing));
45+
/* settings for nested Close button */
46+
--mod-closebutton-margin-inline: var(--mod-alert-banner-close-button-to-content, var(--spectrum-alert-banner-close-button-to-content))
47+
var(--mod-alert-banner-close-button-to-inline-end, var(--spectrum-alert-banner-close-button-to-inline-end));
48+
--mod-closebutton-margin-top: var(--mod-alert-banner-top-to-close-button, var(--spectrum-alert-banner-block-edge-to-button));
4549
--mod-closebutton-align-self: flex-start;
4650
}
4751

@@ -56,9 +60,10 @@ governing permissions and limitations under the License.
5660
.spectrum-AlertBanner {
5761
display: none;
5862
justify-content: space-between;
59-
inline-size: var(--mod-alert-banner-size, var(--spectrum-alert-banner-size));
63+
inline-size: var(--mod-alert-banner-inline-size, var(--spectrum-alert-banner-inline-size));
6064
min-block-size: var(--mod-alert-banner-min-height, var(--spectrum-alert-banner-min-height));
6165
font-size: var(--mod-alert-banner-font-size, var(--spectrum-alert-banner-font-size));
66+
line-height: var(--mod-alert-banner-line-height, var(--spectrum-alert-banner-line-height));
6267
color: var(--mod-alert-banner-font-color, var(--spectrum-alert-banner-font-color));
6368
background-color: var(--mod-alert-banner-background, var(--spectrum-alert-banner-background));
6469
border: var(--highcontrast-alert-banner-border-width, 0) solid var(--highcontrast-alert-banner-border-color, transparent);
@@ -71,16 +76,26 @@ governing permissions and limitations under the License.
7176
.spectrum-AlertBanner-body {
7277
inline-size: 100%;
7378
display: flex;
74-
75-
/* --mod-* for alert-banner-text-to-button-vertical will only accept values larger than alert-banner-edge-to-bottom, as gap only recognizes positive values */
76-
gap: max(calc(var(--mod-alert-banner-text-to-button-vertical, var(--spectrum-alert-banner-text-to-button-vertical)) - var(--mod-alert-banner-edge-to-button, var(--spectrum-alert-banner-edge-to-button))), 0px);
7779
flex-wrap: wrap;
7880
align-items: center;
79-
margin-inline-start: var(--mod-alert-banner-start-edge, var(--spectrum-alert-banner-start-edge));
81+
justify-content: flex-end;
82+
83+
/* Inline spacing between text and button, only when the button has not wrapped to the next line. */
84+
column-gap: var(--mod-alert-banner-text-to-button-horizontal, var(--spectrum-alert-banner-text-to-button-horizontal));
85+
86+
/* Block spacing between text and button, when the button has wrapped to the next line. Takes into
87+
account the existing margins on the text. */
88+
row-gap: max(var(--mod-alert-banner-text-to-button-vertical, 0px),
89+
var(--spectrum-alert-banner-text-to-button-vertical) - var(--spectrum-alert-banner-text-margin-block-end)
90+
);
91+
92+
padding-block: var(--mod-alert-banner-block-edge-to-button, var(--spectrum-alert-banner-block-edge-to-button));
93+
margin-inline-start: var(--mod-alert-banner-inline-start-to-content, var(--spectrum-alert-banner-inline-start-to-content));
8094
}
8195

8296
.spectrum-AlertBanner-content {
8397
display: flex;
98+
flex-grow: 1;
8499
}
85100

86101
.spectrum-AlertBanner-end {
@@ -89,17 +104,18 @@ governing permissions and limitations under the License.
89104
}
90105

91106
.spectrum-AlertBanner-icon {
92-
inline-size: var(--mod-alert-banner-icon-size, var(--spectrum-alert-banner-icon-size));
93-
block-size: var(--mod-alert-banner-icon-size, var(--spectrum-alert-banner-icon-size));
94-
margin-block-start: var(--mod-alert-banner-top-icon, var(--spectrum-alert-banner-top-icon));
107+
--mod-icon-size: var(--mod-alert-banner-icon-size, var(--spectrum-alert-banner-icon-size));
108+
margin-block-start: calc(
109+
var(--mod-alert-banner-top-to-icon, var(--spectrum-alert-banner-top-to-workflow-icon)) -
110+
var(--mod-alert-banner-block-edge-to-button, var(--spectrum-alert-banner-block-edge-to-button))
111+
);
95112
margin-inline-end: var(--mod-alert-banner-icon-to-text, var(--spectrum-alert-banner-icon-to-text));
96113
flex-shrink: 0;
97114
}
98115

99116
.spectrum-AlertBanner-text {
100-
margin-block-start: var(--mod-alert-banner-top-text, var(--spectrum-alert-banner-top-text));
101-
margin-block-end: var(--mod-alert-banner-bottom-text, var(--spectrum-alert-banner-bottom-text));
102-
margin-inline-end: var(--mod-alert-banner-text-to-button-horizontal, var(--spectrum-alert-banner-text-to-button-horizontal));
117+
margin-block-start: var(--mod-alert-banner-text-margin-block-start, var(--spectrum-alert-banner-text-margin-block-start));
118+
margin-block-end: var(--mod-alert-banner-text-margin-block-end, var(--spectrum-alert-banner-text-margin-block-end));
103119
}
104120

105121
@media (forced-colors: active) {

components/alertbanner/metadata/alertbanner.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ sections:
99
description: |
1010
### Version 2.0.0
1111
#### 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.
12+
Alert banner now uses Spectrum 2 tokens and specifications. In this new design, the divider has been removed.
13+
The following mod custom properties have been changed:
14+
- `--mod-alert-banner-size` was renamed to `--mod-alert-banner-inline-size`
15+
- `--mod-alert-banner-neutral-background` was previously misspelled. The mod `--mod-alert-banner-background` was also added, which will take precendence over the variant background mods.
16+
- `--mod-alert-banner-top-text` was renamed to `--mod-alert-banner-top-to-text`
17+
- `--mod-alert-banner-top-icon` was renamed to `--mod-alert-banner-top-to-icon`
18+
- `--mod-alert-banner-bottom-text` was renamed to `--mod-alert-banner-bottom-to-text`
19+
- `--mod-alert-banner-start-edge` was renamed to `--mod-alert-banner-inline-start-to-content`
20+
- `--mod-alert-banner-edge-to-button` was renamed to `--mod-alert-banner-block-edge-to-button`
21+
- The spacing on either side of the close button is now controlled by two separate mods; `--mod-alert-banner-close-button-to-inline-end` and `--mod-alert-banner-close-button-to-content`. The previous `--mod-alert-banner-close-button-spacing` has been removed.
1522
examples:
1623
- id: alertbanner
1724
name: Neutral
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
| Modifiable custom properties |
2-
| ---------------------------------------------- |
3-
| `--mod-alert-banner-background` |
4-
| `--mod-alert-banner-bottom-text` |
5-
| `--mod-alert-banner-close-button-spacing` |
6-
| `--mod-alert-banner-edge-to-button` |
7-
| `--mod-alert-banner-edge-to-divider` |
8-
| `--mod-alert-banner-font-color` |
9-
| `--mod-alert-banner-font-size` |
10-
| `--mod-alert-banner-icon-size` |
11-
| `--mod-alert-banner-icon-to-text` |
12-
| `--mod-alert-banner-informative-background` |
13-
| `--mod-alert-banner-min-height` |
14-
| `--mod-alert-banner-negative-background` |
15-
| `--mod-alert-banner-neutral-background` |
16-
| `--mod-alert-banner-size` |
17-
| `--mod-alert-banner-start-edge` |
18-
| `--mod-alert-banner-text-to-button-horizontal` |
19-
| `--mod-alert-banner-text-to-button-vertical` |
20-
| `--mod-alert-banner-text-to-divider` |
21-
| `--mod-alert-banner-top-icon` |
22-
| `--mod-alert-banner-top-text` |
1+
| Modifiable custom properties |
2+
| ----------------------------------------------- |
3+
| `--mod-alert-banner-background` |
4+
| `--mod-alert-banner-block-edge-to-button` |
5+
| `--mod-alert-banner-bottom-to-text` |
6+
| `--mod-alert-banner-close-button-to-content` |
7+
| `--mod-alert-banner-close-button-to-inline-end` |
8+
| `--mod-alert-banner-font-color` |
9+
| `--mod-alert-banner-font-size` |
10+
| `--mod-alert-banner-icon-size` |
11+
| `--mod-alert-banner-icon-to-text` |
12+
| `--mod-alert-banner-informative-background` |
13+
| `--mod-alert-banner-inline-size` |
14+
| `--mod-alert-banner-inline-start-to-content` |
15+
| `--mod-alert-banner-line-height` |
16+
| `--mod-alert-banner-min-height` |
17+
| `--mod-alert-banner-negative-background` |
18+
| `--mod-alert-banner-neutral-background` |
19+
| `--mod-alert-banner-text-margin-block-end` |
20+
| `--mod-alert-banner-text-margin-block-start` |
21+
| `--mod-alert-banner-text-to-button-horizontal` |
22+
| `--mod-alert-banner-text-to-button-vertical` |
23+
| `--mod-alert-banner-top-to-close-button` |
24+
| `--mod-alert-banner-top-to-icon` |
25+
| `--mod-alert-banner-top-to-text` |

components/alertbanner/stories/alertbanner.stories.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { html } from "lit";
2-
import { when } from "lit/directives/when.js";
2+
import { styleMap } from "lit/directives/style-map.js";
3+
4+
import { Template as Typography } from "@spectrum-css/typography/stories/template.js";
35
import { Template } from "./template";
46

57
export default {
@@ -72,19 +74,65 @@ export default {
7274
const AlertBannerGroup = (args) => {
7375
return html`
7476
<div style="display: flex; flex-direction: column; gap: 1rem">
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-
`)}
77+
${!window.isChromatic() ? Template(args) : html`
78+
<div class="spectrum-Typography">
79+
${Typography({
80+
semantics: "detail",
81+
size: "l",
82+
content: ["All variants with button, including wrapping"],
83+
})}
84+
<div
85+
style=${styleMap({
86+
display: "flex",
87+
flexDirection: "column",
88+
gap: ".3rem",
89+
})}
90+
>
91+
${Template(args)}
92+
${Template({
93+
...args,
94+
variant: "info",
95+
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 purchased the software.",
96+
})}
97+
${Template({
98+
...args,
99+
variant: "negative",
100+
text: "Connection interupted. Check your network to continue.",
101+
})}
102+
</div>
103+
</div>
104+
<div class="spectrum-Typography">
105+
${Typography({
106+
semantics: "detail",
107+
size: "l",
108+
content: ["All variants without button"],
109+
})}
110+
<div
111+
style=${styleMap({
112+
display: "flex",
113+
flexDirection: "column",
114+
gap: ".3rem",
115+
})}
116+
>
117+
${Template({
118+
...args,
119+
actionButtonText: "",
120+
})}
121+
${Template({
122+
...args,
123+
variant: "info",
124+
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 purchased the software.",
125+
actionButtonText: "",
126+
})}
127+
${Template({
128+
...args,
129+
variant: "negative",
130+
text: "Connection interupted. Check your network to continue.",
131+
actionButtonText: "",
132+
})}
133+
</div>
134+
</div>
135+
`}
88136
</div>
89137
`;
90138
};

0 commit comments

Comments
 (0)