Skip to content

Commit 9eca7bd

Browse files
jawinnpfulton
authored andcommitted
feat: add example gradients for static black and white (#2637)
* feat: add example gradients for static black and white Add new gradient backgrounds, displayed for static black and static white variants. These are used for examples only. This adds CSS custom properties available globally within Storybook and sets them on the existing decorator. * docs(fieldlabel): support static colors decorator in storybook Change Field label stories that show static black and static white, so they work with the recently added decorator that changes the main Storybook background. * docs(button): adjust static colors template Adjust static colors template to better handle the static color decorator and gradients. * chore(fieldlabel): apply eslint indentation changes to stories
1 parent 43e47f6 commit 9eca7bd

File tree

5 files changed

+35
-63
lines changed

5 files changed

+35
-63
lines changed

.storybook/assets/base.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ body {
2222
}
2323

2424
.spectrum {
25+
/* ---- Storybook only custom properties ---- */
26+
/* Gradient that changes with the color theme. */
27+
--spectrum-examples-gradient: linear-gradient(45deg, var(--spectrum-magenta-1500), var(--spectrum-blue-1500));
28+
/* Gradients that do not change with the color theme, for use in static color backgrounds. */
29+
--spectrum-examples-gradient-static-black: linear-gradient(45deg, rgb(255, 241, 246), rgb(238, 245, 255));
30+
--spectrum-examples-gradient-static-white: linear-gradient(45deg, rgb(64, 0, 22), rgb(14, 24, 67));
31+
2532
background-color: var(--spectrum-background-layer-1-color);
2633

2734
/* @todo: add back the text color and update VRTs */

.storybook/decorators/contextsWrapper.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const withContextWrapper = makeDecorator({
88
name: "withContextWrapper",
99
parameterName: "context",
1010
wrapper: (StoryFn, context) => {
11-
const { args, argTypes, id, viewMode } = context;
11+
const { args, argTypes, viewMode, id } = context;
1212

1313
const getDefaultValue = (type) => {
1414
if (!type) return null;
@@ -32,14 +32,6 @@ export const withContextWrapper = makeDecorator({
3232

3333
useEffect(() => {
3434
let containers = [document.body];
35-
const container =
36-
viewMode === "docs" &&
37-
!window.isChromatic() &&
38-
!id.includes("foundation")
39-
? document.querySelector("#root-inner") ?? document.body
40-
: document.body;
41-
42-
container.classList.toggle("spectrum", true);
4335

4436
const roots = [
4537
...document.querySelectorAll(`#story--${id}`),
@@ -62,16 +54,15 @@ export const withContextWrapper = makeDecorator({
6254
container.classList.toggle(`spectrum--${s}`, s === scale);
6355
}
6456

65-
66-
container.style.removeProperty("background");
67-
const hasStaticElement = container.querySelector(`.${args.rootClass}--staticWhite, .${args.rootClass}--staticBlack, .${args.rootClass}--overBackground`);
68-
if (hasStaticElement) {
69-
if (container.querySelector(`.${args.rootClass}--staticBlack`)) {
70-
container.style.background = "rgb(181, 209, 211)";
71-
}
72-
else if (container.querySelector(`.${args.rootClass}--staticWhite, .${args.rootClass}--overBackground`)) {
73-
container.style.background = "rgb(15, 121, 125)";
74-
}
57+
// Change background color when demonstrating static color options.
58+
if (args.staticColor === "black") {
59+
container.style.background = "var(--spectrum-examples-gradient-static-black)";
60+
}
61+
else if (args.staticColor === "white") {
62+
container.style.background = "var(--spectrum-examples-gradient-static-white)";
63+
}
64+
else {
65+
container.style.removeProperty("background");
7566
}
7667
}
7768
}, [color, scale, isExpress, args.staticColor]);

components/closebutton/stories/closebutton.stories.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,25 @@ export default {
5757
},
5858
};
5959

60-
const CloseButton = ({
61-
staticColor,
62-
...args
63-
}) => {
60+
const CloseButton = (args) => {
6461
return html`
6562
<div
6663
style=${ifDefined(styleMap({
6764
padding: "1rem",
68-
backgroundColor: staticColor === "white" ? "rgb(15, 121, 125)" : staticColor === "black" ? "rgb(181, 209, 211)" : undefined,
6965
}))}
7066
>
71-
${Template({...args, staticColor})}
67+
${Template(args)}
7268
${when(window.isChromatic(), () =>
7369
html`
7470
${Template({
75-
...args,
76-
isDisabled: true,
77-
})}
71+
...args,
72+
isDisabled: true,
73+
})}
7874
${html`
7975
<div
8076
style=${ifDefined(styleMap({
8177
padding: "1rem",
82-
backgroundColor: "rgb(15, 121, 125)"
78+
background: "var(--spectrum-examples-gradient-static-white)"
8379
}))}
8480
>
8581
${Template({
@@ -97,7 +93,7 @@ const CloseButton = ({
9793
<div
9894
style=${ifDefined(styleMap({
9995
padding: "1rem",
100-
backgroundColor: "rgb(181, 209, 211)"
96+
background: "var(--spectrum-examples-gradient-static-black)"
10197
}))}
10298
>
10399
${Template({

components/fieldlabel/stories/fieldlabel.stories.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { html } from "lit";
21
import { Template } from "./template";
32

43
/**
@@ -112,21 +111,14 @@ WrappingAndRequired.args = {
112111
customStyles: { width: "200px" },
113112
};
114113

115-
export const StaticColors = (args) => html`
116-
${Template({
117-
...args,
118-
label: "The black static color class used on a label marked as required",
119-
staticColor: "black",
120-
})}
121-
${Template({
122-
...args,
123-
label: "The white static color class used on a label marked as required",
124-
staticColor: "white",
125-
})}
126-
`;
127-
128-
StaticColors.storyName = "Static colors";
129-
StaticColors.args = {
130-
alignment: "left",
131-
isRequired: true,
114+
export const StaticWhite = Template.bind({});
115+
StaticWhite.args = {
116+
label: "The static white class used on a label marked as required",
117+
staticColor: "white",
132118
};
119+
120+
export const StaticBlack = Template.bind({});
121+
StaticBlack.args = {
122+
label: "The static black class used on a label marked as required",
123+
staticColor: "black",
124+
};

components/fieldlabel/stories/template.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const Template = ({
4444
iconName = "Asterisk100";
4545
}
4646

47-
const labelMarkup = html`
47+
return html`
4848
<label
4949
class=${classMap({
5050
[rootClass]: true,
@@ -67,18 +67,4 @@ export const Template = ({
6767
}))}
6868
</label>
6969
`;
70-
71-
// When using the static color variants, wrap the label in an example element with a background color.
72-
return !staticColor
73-
? labelMarkup
74-
: html`
75-
<div
76-
style=${styleMap({
77-
padding: "1rem",
78-
backgroundColor: staticColor === "white" ? "rgb(15, 121, 125)" : staticColor === "black" ? "rgb(181, 209, 211)" : undefined,
79-
})}
80-
</div>
81-
${labelMarkup}
82-
</div>
83-
`;
8470
};

0 commit comments

Comments
 (0)