@vueless/storybook 1.1.3-beta.5 → 1.1.3-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/manager.js +8 -3
- package/.storybook/preview.js +1 -4
- package/bin/index.js +1 -1
- package/decorators/storyDarkModeDecorator.js +21 -33
- package/package.json +1 -1
package/.storybook/manager.js
CHANGED
|
@@ -5,11 +5,12 @@ import "./themes/manager.css";
|
|
|
5
5
|
import themeDark from "./themes/themeDark.js";
|
|
6
6
|
import themeLight from "./themes/themeLight.js";
|
|
7
7
|
|
|
8
|
+
/* Set Storybook manager theme when system color mode changed. */
|
|
8
9
|
const prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
9
10
|
|
|
10
|
-
function setSystemTheme(
|
|
11
|
+
function setSystemTheme(colorMode) {
|
|
11
12
|
addons.setConfig({
|
|
12
|
-
theme:
|
|
13
|
+
theme: colorMode === "dark" ? themeDark : themeLight,
|
|
13
14
|
panelPosition: "right",
|
|
14
15
|
});
|
|
15
16
|
}
|
|
@@ -17,5 +18,9 @@ function setSystemTheme(theme) {
|
|
|
17
18
|
setSystemTheme(prefersColorSchemeDark.matches);
|
|
18
19
|
|
|
19
20
|
prefersColorSchemeDark.addEventListener("change", (event) => {
|
|
20
|
-
|
|
21
|
+
const sbAddonThemesConfig = localStorage.getItem("sb-addon-themes-3") || "{}";
|
|
22
|
+
const storybookColorMode = JSON.parse(sbAddonThemesConfig).current || "light";
|
|
23
|
+
const systemColorMode = event.matches ? "dark" : "light";
|
|
24
|
+
|
|
25
|
+
setSystemTheme(storybookColorMode || systemColorMode);
|
|
21
26
|
});
|
package/.storybook/preview.js
CHANGED
|
@@ -8,9 +8,6 @@ import themeDark from "./themes/themeDark.js";
|
|
|
8
8
|
import themeLight from "./themes/themeLight.js";
|
|
9
9
|
import themeLightPreview from "./themes/themeLightPreview.js";
|
|
10
10
|
|
|
11
|
-
/* Tailwind styles */
|
|
12
|
-
import "./index.css";
|
|
13
|
-
|
|
14
11
|
/* Vue plugins */
|
|
15
12
|
import { createVueless } from "vueless";
|
|
16
13
|
import { createRouter, createWebHistory } from "vue-router";
|
|
@@ -29,7 +26,7 @@ setup((app) => {
|
|
|
29
26
|
});
|
|
30
27
|
|
|
31
28
|
/* Set storybook decorators */
|
|
32
|
-
export const decorators = [vue3SourceDecorator, storyDarkModeDecorator
|
|
29
|
+
export const decorators = [vue3SourceDecorator, storyDarkModeDecorator];
|
|
33
30
|
|
|
34
31
|
/* Set storybook tags */
|
|
35
32
|
export const tags = ["autodocs"];
|
package/bin/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { styleText } from "node:util";
|
|
|
7
7
|
import fs, { promises } from "node:fs";
|
|
8
8
|
|
|
9
9
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
10
|
-
const source = path.join(__dirname, ".storybook");
|
|
10
|
+
const source = path.join(__dirname, "..", ".storybook");
|
|
11
11
|
const target = path.join(cwd(), ".storybook");
|
|
12
12
|
|
|
13
13
|
copyStorybookPreset(source, target);
|
|
@@ -1,49 +1,37 @@
|
|
|
1
1
|
import { DecoratorHelpers } from "@storybook/addon-themes";
|
|
2
|
+
import { makeDecorator } from "storybook/preview-api";
|
|
2
3
|
import { setTheme } from "vueless";
|
|
3
|
-
import { COLOR_MODE_KEY } from "vueless/constants.js";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/* Cache preview color mode. */
|
|
6
|
+
let previewColorMode = "";
|
|
6
7
|
|
|
8
|
+
/* Set Storybook color mode when system color mode changed. */
|
|
7
9
|
const prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
8
10
|
|
|
9
11
|
prefersColorSchemeDark.addEventListener("change", (event) => {
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const storyDarkModeDecorator = () => {
|
|
14
|
-
/* Set theme className to html tag before initialization (fix white blink issue). */
|
|
15
|
-
const sbAddonThemesConfig = localStorage.getItem("sb-addon-themes-3") || "{}";
|
|
16
|
-
const storybookTheme = JSON.parse(sbAddonThemesConfig).current || "light";
|
|
17
|
-
|
|
18
|
-
// this fixing first load
|
|
19
|
-
document.body.classList.add(storybookTheme);
|
|
12
|
+
const systemColorMode = event.matches ? "dark" : "light";
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
document.documentElement.classList.add(storybookTheme);
|
|
24
|
-
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
document.documentElement.classList.remove("light", "dark");
|
|
27
|
-
}, 4000);
|
|
28
|
-
}
|
|
14
|
+
setTheme({ colorMode: previewColorMode || systemColorMode });
|
|
15
|
+
});
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
/* Define color mode decorator. */
|
|
18
|
+
export const storyDarkModeDecorator = makeDecorator({
|
|
19
|
+
name: "storyDarkModeDecorator",
|
|
20
|
+
wrapper: (storyFn, context) => {
|
|
21
|
+
const sbAddonThemesConfig = localStorage.getItem("sb-addon-themes-3") || "{}";
|
|
22
|
+
const storybookColorMode = JSON.parse(sbAddonThemesConfig).current || "light";
|
|
23
|
+
const systemColorMode = prefersColorSchemeDark.matches ? "dark" : "light";
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
DecoratorHelpers.initializeThemeState(["light", "dark"], storybookColorMode || systemColorMode);
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
const theme = pluckThemeFromContext(context);
|
|
27
|
+
previewColorMode = DecoratorHelpers.pluckThemeFromContext(context);
|
|
38
28
|
|
|
39
|
-
setTheme({ colorMode:
|
|
29
|
+
setTheme({ colorMode: previewColorMode || systemColorMode });
|
|
40
30
|
|
|
41
31
|
return {
|
|
42
|
-
components: {
|
|
43
|
-
setup() {
|
|
44
|
-
return { theme };
|
|
45
|
-
},
|
|
32
|
+
components: { storyFn },
|
|
33
|
+
setup: () => ({ theme: previewColorMode }),
|
|
46
34
|
template: `<story />`,
|
|
47
35
|
};
|
|
48
|
-
}
|
|
49
|
-
};
|
|
36
|
+
},
|
|
37
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueless/storybook",
|
|
3
|
-
"version": "1.1.3-beta.
|
|
3
|
+
"version": "1.1.3-beta.6",
|
|
4
4
|
"description": "Simplifies Storybook configuration for Vueless UI library.",
|
|
5
5
|
"author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
|
|
6
6
|
"homepage": "https://vueless.com",
|