Skip to content

Commit 8ef96b3

Browse files
authored
(chore) Adding support for Chromatic dark snapshots (#8011)
1 parent 4be1367 commit 8ef96b3

5 files changed

Lines changed: 51 additions & 23 deletions

File tree

.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const storybookConfig: StorybookConfig = {
4949
});
5050
},
5151

52-
addons: [getAbsolutePath("@storybook/addon-a11y")],
52+
addons: [getAbsolutePath("@storybook/addon-a11y"), getAbsolutePath("@storybook/addon-themes")],
5353
};
5454

5555
// eslint-disable-next-line import/no-default-export

.storybook/modes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* !
2+
* (c) Copyright 2026 Palantir Technologies Inc. All rights reserved.
3+
*/
4+
5+
import { Colors } from "@blueprintjs/core";
6+
7+
export const modes = {
8+
dark: {
9+
backgrounds: { value: Colors.BLACK },
10+
theme: "dark",
11+
},
12+
light: {
13+
backgrounds: { value: Colors.WHITE },
14+
theme: "light",
15+
},
16+
} as const;

.storybook/preview.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
* (c) Copyright 2026 Palantir Technologies Inc. All rights reserved.
33
*/
44

5+
import { withThemeByClassName } from "@storybook/addon-themes";
56
import type { Preview } from "@storybook/react-vite";
67

78
import { BlueprintProvider, Classes, Colors, FocusStyleManager } from "@blueprintjs/core";
89

910
import { Icons } from "../packages/icons/src/iconLoader";
1011

12+
import { modes } from "./modes";
13+
1114
FocusStyleManager.onlyShowFocusOnTabs();
1215

1316
Icons.setLoaderOptions({ loader: "all" });
@@ -24,17 +27,11 @@ import "@blueprintjs/table/lib/css/table.css";
2427

2528
const preview: Preview = {
2629
parameters: {
27-
backgrounds: {
28-
options: {
29-
light: {
30-
name: "light",
31-
value: "#ffffff",
32-
},
33-
34-
dark: {
35-
name: "dark",
36-
value: Colors.BLACK,
37-
},
30+
backgrounds: { disable: true },
31+
chromatic: {
32+
modes: {
33+
dark: modes.dark,
34+
light: modes.light,
3835
},
3936
},
4037
controls: {
@@ -46,16 +43,19 @@ const preview: Preview = {
4643
},
4744

4845
decorators: [
46+
withThemeByClassName({
47+
defaultTheme: "light",
48+
parentSelector: "body",
49+
themes: {
50+
dark: Classes.DARK,
51+
light: "",
52+
},
53+
}),
4954
(Story, context) => {
50-
// Toggle Blueprint dark mode via the Backgrounds toolbar (light / dark).
51-
const bg = context.globals?.backgrounds;
52-
const isDark = bg?.value === Colors.BLACK || bg?.value === "dark" || bg?.name === "dark";
55+
const isDark = context.globals?.theme === "dark";
5356
if (typeof document !== "undefined" && document.body) {
54-
if (isDark) {
55-
document.body.classList.add(Classes.DARK);
56-
} else {
57-
document.body.classList.remove(Classes.DARK);
58-
}
57+
// Setting dark background based on class
58+
document.body.style.backgroundColor = isDark ? Colors.BLACK : Colors.WHITE;
5959
}
6060
return (
6161
<BlueprintProvider>
@@ -66,9 +66,7 @@ const preview: Preview = {
6666
],
6767

6868
initialGlobals: {
69-
backgrounds: {
70-
value: "light",
71-
},
69+
theme: "light",
7270
},
7371
};
7472

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"license": "Apache-2.0",
9595
"devDependencies": {
9696
"@storybook/addon-a11y": "^10.2.14",
97+
"@storybook/addon-themes": "^10.2.14",
9798
"@storybook/icons": "^2.0.1",
9899
"@storybook/react-dom-shim": "^10.2.14",
99100
"@storybook/react-vite": "^10.2.14",

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)