Skip to content

Commit 33c2033

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 91a4cb4 commit 33c2033

File tree

5 files changed

+30
-48
lines changed

5 files changed

+30
-48
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ export const withContextWrapper = makeDecorator({
5050
container.classList.toggle(`spectrum--${s}`, s === scale);
5151
}
5252

53+
// Change background color when demonstrating static color options.
5354
if (args.staticColor === "black") {
54-
container.style.backgroundColor = "rgb(181, 209, 211)";
55+
container.style.background = "var(--spectrum-examples-gradient-static-black)";
5556
} else if (args.staticColor === "white") {
56-
container.style.backgroundColor = "rgb(15, 121, 125)";
57+
container.style.background = "var(--spectrum-examples-gradient-static-white)";
5758
} else {
58-
container.style.removeProperty("background-color");
59+
container.style.removeProperty("background");
5960
}
6061
}, [color, scale, isExpress, args.staticColor]);
6162

components/closebutton/stories/closebutton.stories.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,25 @@ export default {
5555
},
5656
};
5757

58-
const CloseButton = ({
59-
staticColor,
60-
...args
61-
}) => {
58+
const CloseButton = (args) => {
6259
return html`
6360
<div
6461
style=${ifDefined(styleMap({
6562
padding: "1rem",
66-
backgroundColor: staticColor === "white" ? "rgb(15, 121, 125)" : staticColor === "black" ? "rgb(181, 209, 211)" : undefined,
6763
}))}
6864
>
69-
${Template({...args, staticColor})}
65+
${Template(args)}
7066
${when(window.isChromatic(), () =>
7167
html`
7268
${Template({
73-
...args,
74-
isDisabled: true,
75-
})}
69+
...args,
70+
isDisabled: true,
71+
})}
7672
${html`
7773
<div
7874
style=${ifDefined(styleMap({
7975
padding: "1rem",
80-
backgroundColor: "rgb(15, 121, 125)"
76+
background: "var(--spectrum-examples-gradient-static-white)"
8177
}))}
8278
>
8379
${Template({
@@ -95,7 +91,7 @@ const CloseButton = ({
9591
<div
9692
style=${ifDefined(styleMap({
9793
padding: "1rem",
98-
backgroundColor: "rgb(181, 209, 211)"
94+
background: "var(--spectrum-examples-gradient-static-black)"
9995
}))}
10096
>
10197
${Template({
@@ -113,7 +109,7 @@ const CloseButton = ({
113109
)}
114110
</div>
115111
`;
116-
}
112+
};
117113

118114
export const Default = CloseButton.bind({});
119115
Default.args = {};

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
export default {
@@ -111,21 +110,14 @@ WrappingAndRequired.args = {
111110
style: { width: "200px" },
112111
};
113112

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

components/fieldlabel/stories/template.js

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

45-
const labelMarkup = html`
45+
return html`
4646
<label
4747
class=${classMap({
4848
[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)