22 * (c) Copyright 2026 Palantir Technologies Inc. All rights reserved.
33 */
44
5+ import { withThemeByClassName } from "@storybook/addon-themes" ;
56import type { Preview } from "@storybook/react-vite" ;
67
78import { BlueprintProvider , Classes , Colors , FocusStyleManager } from "@blueprintjs/core" ;
89
910import { Icons } from "../packages/icons/src/iconLoader" ;
1011
12+ import { modes } from "./modes" ;
13+
1114FocusStyleManager . onlyShowFocusOnTabs ( ) ;
1215
1316Icons . setLoaderOptions ( { loader : "all" } ) ;
@@ -24,17 +27,11 @@ import "@blueprintjs/table/lib/css/table.css";
2427
2528const 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
0 commit comments