Skip to content

Commit 70a0385

Browse files
committed
docs(combobox): merging changes from main
2 parents c757fea + 812e824 commit 70a0385

File tree

29 files changed

+398
-477
lines changed

29 files changed

+398
-477
lines changed

.storybook/assets/base.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ svg:has(symbol):not(:has(use)) {
4040

4141
/* --- DOCS STYLES --- */
4242
.docs-story > *:first-child {
43-
background-color: var(--spectrum-background-layer-1-color);
4443
overflow: hidden;
4544
}
4645

.storybook/decorators/context.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const withContextWrapper = makeDecorator({
2020
color = "light",
2121
context = "legacy",
2222
scale = "medium",
23+
testingPreview = false,
2324
} = {},
2425
id,
2526
viewMode,
@@ -36,36 +37,53 @@ export const withContextWrapper = makeDecorator({
3637
},
3738
};
3839

40+
const original = {
41+
color,
42+
context,
43+
scale,
44+
};
45+
3946
useEffect(() => {
47+
const isDocs = viewMode === "docs";
48+
const isTesting = testingPreview;
4049
const isRaw = Boolean(context === "raw");
4150
const isModern = Boolean(context === "spectrum");
4251
const isExpress = Boolean(context === "express");
4352

44-
// viewMode is either "docs" or "story"
45-
if (viewMode === "docs" && !isRaw) {
53+
// Start by attaching the appropriate tokens to the container
54+
toggleStyles(document.body, "tokens", tokens, !isRaw);
55+
56+
if (!isRaw) {
4657
// add the default classes to the body to ensure labels, headings, and borders are styled correctly
4758
document.body.classList.add("spectrum", "spectrum--light", "spectrum--medium");
4859
}
4960

50-
for (const container of fetchContainers(id, viewMode === "docs")) {
51-
// Start by attaching the appropriate tokens to the container
52-
toggleStyles(container, "tokens", tokens, !isRaw);
61+
for (const container of fetchContainers(id, isDocs, isTesting)) {
62+
// Reset the context to the original values
63+
color = original.color;
64+
context = original.context;
65+
scale = original.scale;
5366

5467
// Check if the container has a static color element
55-
const hasStaticElement = container.matches(`:has(.${rootClass}--staticWhite, .${rootClass}--staticBlack, .${rootClass}--overBackground)`);
68+
let hasStaticElement = container.matches(`:has([data-html-preview])`) ? container.matches(`:has([data-html-preview] .${rootClass}--staticWhite, [data-html-preview] .${rootClass}--staticBlack)`) : container.matches(`:has(.${rootClass}--staticWhite, .${rootClass}--staticBlack)`);
69+
5670
let staticKey = staticColor;
5771
if (!staticKey && hasStaticElement) {
5872
staticKey = (
5973
container.querySelector(`.${rootClass}--staticWhite`) && "white" ||
60-
container.querySelector(`.${rootClass}--staticBlack, .${rootClass}--overBackground`) && "black"
74+
container.querySelector(`.${rootClass}--staticBlack`) && "black"
6175
);
6276
}
6377

78+
// If we can't determine the static key, we can't use the static color
79+
if (!staticKey) hasStaticElement = false;
80+
6481
// Every container gets the spectrum class
6582
container.classList.toggle("spectrum", !isRaw);
6683

6784
// S1 and S1 Express get the legacy class
6885
container.classList.toggle("spectrum--legacy", !isModern && !isRaw);
86+
6987
// Express only gets the express class
7088
container.classList.toggle("spectrum--express", isExpress && !isRaw);
7189

@@ -76,16 +94,23 @@ export const withContextWrapper = makeDecorator({
7694
color = "dark";
7795
}
7896

79-
for (let c of ["light", "dark", "darkest"]) {
80-
// Force light or dark mode if the static color is set
81-
const isColor = staticKey && c === staticColorSettings[staticKey]?.color || !staticKey && c === color;
97+
// Let the static color override the color if it's set
98+
if (hasStaticElement && staticColorSettings[staticKey]?.color) {
99+
color = staticColorSettings[staticKey].color;
100+
}
101+
102+
// Force a light theme for the body wrapper in testing preview mode
103+
// because the individual containers will bring in the correct theme
104+
if (isTesting && container.matches("body:has([data-testing-preview]")) {
105+
color = "light";
106+
}
82107

83-
container.classList.toggle(`spectrum--${c}`, isColor && !isRaw);
108+
for (let c of ["light", "dark", "darkest"]) {
109+
container.classList.toggle(`spectrum--${c}`, c === color && !isRaw);
84110
}
85111

86112
for (const s of ["medium", "large"]) {
87-
const isScale = s === scale;
88-
container.classList.toggle(`spectrum--${s}`, isScale && !isRaw);
113+
container.classList.toggle(`spectrum--${s}`, s === scale && !isRaw);
89114
}
90115

91116
// Start by removing the background color from the container and then add it back if needed
@@ -94,7 +119,8 @@ export const withContextWrapper = makeDecorator({
94119
container.style.background = staticColorSettings[staticKey].background;
95120
}
96121
}
97-
}, [color, context, staticColor, scale, viewMode, rootClass, tokens, staticColorSettings]);
122+
123+
}, [context, viewMode, original, staticColor, color, scale, rootClass, tokens, staticColorSettings, testingPreview]);
98124

99125
return StoryFn(data);
100126
},

.storybook/decorators/helpers.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,28 @@ export function fetchStyleContainer(id, container) {
5050
* @type (id: string, isDocs: boolean = false) => HTMLElement[]
5151
* @description Fetches the style container for the given ID or creates a new one
5252
**/
53-
export function fetchContainers(id, isDocs = false) {
54-
if (!id) return [];
55-
const { document } = global;
53+
export function fetchContainers(id, isDocs = false, isTesting = false) {
54+
if (!id) return [];
55+
const { document } = global;
56+
57+
let containers = [];
5658

57-
let containers = [document.body];
59+
// Storybook IDs used to target the container element for the docs pages
60+
const roots = [
61+
...document.querySelectorAll(`#story--${id}`),
62+
...document.querySelectorAll(`#story--${id}--primary`)
63+
];
5864

59-
// Storybook IDs used to target the container element for the docs pages
60-
const roots = [
61-
...document.querySelectorAll(`#story--${id}`),
62-
...document.querySelectorAll(`#story--${id}--primary`)
63-
];
65+
// viewMode is either "docs" or "story"
66+
if (isDocs && roots.length > 0) {
67+
containers = roots.map(root => root.closest(".docs-story") ?? root);
68+
}
69+
else if (isTesting) {
70+
// Only capture the top-level container for testing previews
71+
containers.push(...document.querySelectorAll("[data-inner-container]"));
72+
}
6473

65-
// viewMode is either "docs" or "story"
66-
if (isDocs && roots.length > 0) {
67-
containers = roots.map(root => root.closest(".docs-story") ?? root);
68-
}
74+
if (containers.length === 0) containers = [document.body];
6975

70-
return containers;
76+
return containers;
7177
}

.storybook/decorators/utilities.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ export const ArgGrid = ({
209209
withWrapperBorder = true,
210210
...args
211211
} = {}, context = {}) => {
212+
const isDocs = context.viewMode === "docs";
213+
212214
if (typeof argKey === "undefined") {
213215
console.warn("ArgGrid: argKey is required to render the grid.");
214216
return nothing;
@@ -230,6 +232,11 @@ export const ArgGrid = ({
230232
return nothing;
231233
}
232234

235+
// If no heading and this is a docs view, skip the border
236+
if (!heading && isDocs) {
237+
withWrapperBorder = false;
238+
}
239+
233240
return Container({
234241
heading,
235242
direction,
@@ -323,17 +330,26 @@ export const Variants = ({
323330
TestTemplate = Template;
324331
}
325332

333+
const staticColor = {
334+
black: "var(--spectrum-docs-static-black-background-color)",
335+
white: "var(--spectrum-docs-static-white-background-color)",
336+
};
337+
326338
return (args, context) => {
327339
// Fetch any docs configurations from the context to use for VRT
328-
const { parameters = {} } = context;
340+
const { argTypes = {}, parameters = {} } = context;
329341

330342
const height = parameters?.docs?.story?.height;
331343
const width = parameters?.docs?.story?.width;
332344

345+
// Check if the staticColor property exists in this story
346+
const hasStaticColor = Object.keys(argTypes).includes("staticColor");
347+
333348
return html`
334349
<!-- Simple, clean template preview for non-testing grid views -->
335350
<div
336351
style=${styleMap({
352+
backgroundColor: hasStaticColor && staticColor[args.staticColor],
337353
"padding": "12px",
338354
"min-block-size": typeof height === "number" ? `${height}px` : height,
339355
"min-inline-size": typeof width === "number" ? `${width}px` : width,
@@ -347,6 +363,7 @@ export const Variants = ({
347363
348364
<!-- Start testing grid markup -->
349365
<div
366+
data-testing-preview
350367
style=${styleMap({
351368
"padding": "24px",
352369
"display": window.isChromatic() ? "flex" : "none",
@@ -391,7 +408,14 @@ export const Variants = ({
391408
testHeading = "Default";
392409
}
393410
411+
// Check if the staticColor property is being used in this story
412+
let backgroundColor;
413+
if (hasStaticColor && data.staticColor) {
414+
backgroundColor = staticColor[data.staticColor];
415+
}
416+
394417
const combinedStyles = {
418+
backgroundColor,
395419
...wrapperStyles,
396420
...testWrapperStyles,
397421
};
@@ -405,7 +429,7 @@ export const Variants = ({
405429
...containerStyles,
406430
},
407431
// if the test has multiple states, pass the wrapper styles to that container, otherwise use it here
408-
wrapperStyles: withStates ? {} : combinedStyles,
432+
wrapperStyles: withStates ? { backgroundColor } : combinedStyles,
409433
content: html`
410434
${when(withStates, () =>
411435
States({

components/actionbutton/stories/actionbutton.stories.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,6 @@ Sizing.parameters = {
237237

238238

239239
// ********* VRT ONLY ********* //
240-
export const StaticBlack = ActionButtonGroup.bind({});
241-
StaticBlack.tags = ["!autodocs", "!dev"];
242-
StaticBlack.args = {
243-
...Default.args,
244-
staticColor: "black",
245-
};
246-
StaticBlack.parameters = {
247-
chromatic: {
248-
modes: disableDefaultModes
249-
},
250-
};
251-
252-
export const StaticWhite = ActionButtonGroup.bind({});
253-
StaticWhite.tags = ["!autodocs", "!dev"];
254-
StaticWhite.args = {
255-
...Default.args,
256-
staticColor: "white",
257-
};
258-
StaticWhite.parameters = {
259-
chromatic: {
260-
modes: disableDefaultModes
261-
},
262-
};
263-
264240
export const WithForcedColors = ActionButtonGroup.bind({});
265241
WithForcedColors.args = Default.args;
266242
WithForcedColors.tags = ["!autodocs", "!dev"];

components/actionbutton/stories/actionbutton.test.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ import { Template } from "./template.js";
44

55
export const ActionButtons = (args, context) => {
66
return html`
7-
${Template(args, context)}
8-
${Template({
9-
...args,
10-
}, context)}
11-
${Template({
12-
...args,
13-
hideLabel: true,
14-
}, context)}
15-
${Template({
16-
...args,
17-
hasPopup: "true",
18-
hideLabel: true,
19-
}, context)}
20-
${Template({
21-
...args,
22-
iconName: undefined,
23-
hasPopup: "true",
24-
}, context)}
7+
<div style="display: flex; column-gap: 13px; row-gap: 24px;">
8+
${Template(args, context)}
9+
${Template({
10+
...args,
11+
iconName: undefined,
12+
}, context)}
13+
${Template({
14+
...args,
15+
hideLabel: true,
16+
}, context)}
17+
${Template({
18+
...args,
19+
hasPopup: "true",
20+
hideLabel: true,
21+
}, context)}
22+
${Template({
23+
...args,
24+
iconName: undefined,
25+
hasPopup: "true",
26+
}, context)}
27+
</div>
2528
`;
2629
};
2730

@@ -64,6 +67,14 @@ export const ActionButtonGroup = Variants({
6467
},
6568
withStates: false,
6669
},
70+
{
71+
testHeading: "Static black",
72+
staticColor: "black",
73+
},
74+
{
75+
testHeading: "Static white",
76+
staticColor: "white",
77+
},
6778
],
6879
stateData: [{
6980
testHeading: "Disabled",
@@ -85,4 +96,4 @@ export const ActionButtonGroup = Variants({
8596
isDisabled: true,
8697
isSelected: true,
8798
}],
88-
});
99+
});

0 commit comments

Comments
 (0)