@vueless/storybook 0.0.75-beta.8 → 1.0.0
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/addons/storybook-dark-mode/Tool.tsx +270 -0
- package/.storybook/addons/storybook-dark-mode/constants.ts +2 -0
- package/.storybook/addons/storybook-dark-mode/index.tsx +20 -0
- package/.storybook/addons/storybook-dark-mode/preset/manager.tsx +26 -0
- package/.storybook/decorators/vue3SourceDecorator.js +28 -12
- package/.storybook/index.css +7 -0
- package/.storybook/main.js +6 -4
- package/.storybook/manager-head.html +177 -177
- package/.storybook/manager.js +1 -1
- package/.storybook/preview.js +1 -1
- package/.storybook/themes/themeDark.js +1 -1
- package/.storybook/themes/themeLight.js +1 -1
- package/.storybook/themes/themeLightDocs.js +1 -1
- package/.storybook/vite.config.js +4 -4
- package/package.json +22 -20
- package/webTypes/index.js +2 -2
- package/webTypes/lib/build.js +3 -2
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { global } from "@storybook/global";
|
|
3
|
+
import { themes, ThemeVars } from "storybook/theming";
|
|
4
|
+
import { IconButton } from "storybook/internal/components";
|
|
5
|
+
import { MoonIcon, SunIcon } from "@storybook/icons";
|
|
6
|
+
import {
|
|
7
|
+
STORY_CHANGED,
|
|
8
|
+
SET_STORIES,
|
|
9
|
+
DOCS_RENDERED,
|
|
10
|
+
} from "storybook/internal/core-events";
|
|
11
|
+
import { API, useParameter } from "storybook/manager-api";
|
|
12
|
+
import equal from "fast-deep-equal";
|
|
13
|
+
import { DARK_MODE_EVENT_NAME, UPDATE_DARK_MODE_EVENT_NAME } from "./constants";
|
|
14
|
+
|
|
15
|
+
const { document, window } = global as { document: Document; window: Window };
|
|
16
|
+
const modes = ["light", "dark"] as const;
|
|
17
|
+
type Mode = (typeof modes)[number];
|
|
18
|
+
|
|
19
|
+
interface DarkModeStore {
|
|
20
|
+
/** The class target in the preview iframe */
|
|
21
|
+
classTarget: string;
|
|
22
|
+
/** The current mode the storybook is set to */
|
|
23
|
+
current: Mode;
|
|
24
|
+
/** The dark theme for storybook */
|
|
25
|
+
dark: ThemeVars;
|
|
26
|
+
/** The dark class name for the preview iframe */
|
|
27
|
+
darkClass: string | string[];
|
|
28
|
+
/** The light theme for storybook */
|
|
29
|
+
light: ThemeVars;
|
|
30
|
+
/** The light class name for the preview iframe */
|
|
31
|
+
lightClass: string | string[];
|
|
32
|
+
/** Apply mode to iframe */
|
|
33
|
+
stylePreview: boolean;
|
|
34
|
+
/** Persist if the user has set the theme */
|
|
35
|
+
userHasExplicitlySetTheTheme: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const STORAGE_KEY = "sb-addon-themes-3";
|
|
39
|
+
export const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
40
|
+
|
|
41
|
+
const defaultParams: Required<Omit<DarkModeStore, "current">> = {
|
|
42
|
+
classTarget: "body",
|
|
43
|
+
dark: themes.dark,
|
|
44
|
+
darkClass: ["dark"],
|
|
45
|
+
light: themes.light,
|
|
46
|
+
lightClass: ["light"],
|
|
47
|
+
stylePreview: false,
|
|
48
|
+
userHasExplicitlySetTheTheme: false,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Persist the dark mode settings in localStorage */
|
|
52
|
+
export const updateStore = (newStore: DarkModeStore) => {
|
|
53
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(newStore));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Add the light/dark class to an element */
|
|
57
|
+
const toggleDarkClass = (
|
|
58
|
+
el: Element,
|
|
59
|
+
{
|
|
60
|
+
current,
|
|
61
|
+
darkClass = defaultParams.darkClass,
|
|
62
|
+
lightClass = defaultParams.lightClass,
|
|
63
|
+
}: DarkModeStore,
|
|
64
|
+
) => {
|
|
65
|
+
if (current === "dark") {
|
|
66
|
+
el.classList.remove(...arrayify(lightClass));
|
|
67
|
+
el.classList.add(...arrayify(darkClass));
|
|
68
|
+
} else {
|
|
69
|
+
el.classList.remove(...arrayify(darkClass));
|
|
70
|
+
el.classList.add(...arrayify(lightClass));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** Coerce a string to a single item array, or return an array as-is */
|
|
75
|
+
const arrayify = (classes: string | string[]): string[] => {
|
|
76
|
+
const arr: string[] = [];
|
|
77
|
+
return arr.concat(classes).map((item) => item);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Update the preview iframe class */
|
|
81
|
+
const updatePreview = (store: DarkModeStore) => {
|
|
82
|
+
const iframe = document.getElementById(
|
|
83
|
+
"storybook-preview-iframe",
|
|
84
|
+
) as HTMLIFrameElement;
|
|
85
|
+
|
|
86
|
+
if (!iframe) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const iframeDocument =
|
|
91
|
+
iframe.contentDocument || iframe.contentWindow?.document;
|
|
92
|
+
const target = iframeDocument?.querySelector<HTMLElement>(store.classTarget);
|
|
93
|
+
|
|
94
|
+
if (!target) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
toggleDarkClass(target, store);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Update the manager iframe class */
|
|
102
|
+
const updateManager = (store: DarkModeStore) => {
|
|
103
|
+
const manager = document.querySelector(store.classTarget);
|
|
104
|
+
|
|
105
|
+
if (!manager) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
toggleDarkClass(manager, store);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Update changed dark mode settings and persist to localStorage */
|
|
113
|
+
export const store = (
|
|
114
|
+
userTheme: Partial<DarkModeStore> = {},
|
|
115
|
+
): DarkModeStore => {
|
|
116
|
+
const storedItem = window.localStorage.getItem(STORAGE_KEY);
|
|
117
|
+
|
|
118
|
+
if (typeof storedItem === "string") {
|
|
119
|
+
const stored = JSON.parse(storedItem) as DarkModeStore;
|
|
120
|
+
|
|
121
|
+
if (userTheme) {
|
|
122
|
+
if (userTheme.dark && !equal(stored.dark, userTheme.dark)) {
|
|
123
|
+
stored.dark = userTheme.dark;
|
|
124
|
+
updateStore(stored);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (userTheme.light && !equal(stored.light, userTheme.light)) {
|
|
128
|
+
stored.light = userTheme.light;
|
|
129
|
+
updateStore(stored);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return stored;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return { ...defaultParams, ...userTheme } as DarkModeStore;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// On initial load, set the dark mode class on the manager
|
|
140
|
+
// This is needed if you're using mostly CSS overrides to styles the storybook
|
|
141
|
+
// Otherwise the default theme is set in src/preset/manager.tsx
|
|
142
|
+
updateManager(store());
|
|
143
|
+
|
|
144
|
+
interface DarkModeProps {
|
|
145
|
+
/** The storybook API */
|
|
146
|
+
api: API;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** A toolbar icon to toggle between dark and light themes in storybook */
|
|
150
|
+
export function DarkMode({ api }: DarkModeProps) {
|
|
151
|
+
const [isDark, setDark] = React.useState(prefersDark.matches);
|
|
152
|
+
const darkModeParams = useParameter<Partial<DarkModeStore>>("darkMode", {});
|
|
153
|
+
const { current: defaultMode, stylePreview, ...params } = darkModeParams;
|
|
154
|
+
const channel = api.getChannel();
|
|
155
|
+
// Save custom themes on init
|
|
156
|
+
const userHasExplicitlySetTheTheme = React.useMemo(
|
|
157
|
+
() => store(params).userHasExplicitlySetTheTheme,
|
|
158
|
+
[params],
|
|
159
|
+
);
|
|
160
|
+
/** Set the theme in storybook, update the local state, and emit an event */
|
|
161
|
+
const setMode = React.useCallback(
|
|
162
|
+
(mode: Mode) => {
|
|
163
|
+
const currentStore = store();
|
|
164
|
+
api.setOptions({ theme: currentStore[mode] });
|
|
165
|
+
setDark(mode === "dark");
|
|
166
|
+
api.getChannel().emit(DARK_MODE_EVENT_NAME, mode === "dark");
|
|
167
|
+
updateManager(currentStore);
|
|
168
|
+
if (stylePreview) {
|
|
169
|
+
updatePreview(currentStore);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
[api, stylePreview],
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
/** Update the theme settings in localStorage, react, and storybook */
|
|
176
|
+
const updateMode = React.useCallback(
|
|
177
|
+
(mode?: Mode) => {
|
|
178
|
+
const currentStore = store();
|
|
179
|
+
const current =
|
|
180
|
+
mode || (currentStore.current === "dark" ? "light" : "dark");
|
|
181
|
+
updateStore({ ...currentStore, current });
|
|
182
|
+
setMode(current);
|
|
183
|
+
},
|
|
184
|
+
[setMode],
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
/** Update the theme based on the color preference */
|
|
188
|
+
function prefersDarkUpdate(event: MediaQueryListEvent) {
|
|
189
|
+
if (userHasExplicitlySetTheTheme || defaultMode) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
updateMode(event.matches ? "dark" : "light");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Render the current theme */
|
|
197
|
+
const renderTheme = React.useCallback(() => {
|
|
198
|
+
const { current = "light" } = store();
|
|
199
|
+
setMode(current);
|
|
200
|
+
}, [setMode]);
|
|
201
|
+
|
|
202
|
+
/** Handle the user event and side effects */
|
|
203
|
+
const handleIconClick = () => {
|
|
204
|
+
updateMode();
|
|
205
|
+
const currentStore = store();
|
|
206
|
+
updateStore({ ...currentStore, userHasExplicitlySetTheTheme: true });
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** When storybook params change update the stored themes */
|
|
210
|
+
React.useEffect(() => {
|
|
211
|
+
const currentStore = store();
|
|
212
|
+
// Ensure we use the stores `current` value first to persist
|
|
213
|
+
// themeing between page loads and story changes.
|
|
214
|
+
updateStore({
|
|
215
|
+
...currentStore,
|
|
216
|
+
...darkModeParams,
|
|
217
|
+
current: currentStore.current || darkModeParams.current,
|
|
218
|
+
});
|
|
219
|
+
renderTheme();
|
|
220
|
+
}, [darkModeParams, renderTheme]);
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
channel.on(STORY_CHANGED, renderTheme);
|
|
223
|
+
channel.on(SET_STORIES, renderTheme);
|
|
224
|
+
channel.on(DOCS_RENDERED, renderTheme);
|
|
225
|
+
prefersDark.addListener(prefersDarkUpdate);
|
|
226
|
+
return () => {
|
|
227
|
+
channel.removeListener(STORY_CHANGED, renderTheme);
|
|
228
|
+
channel.removeListener(SET_STORIES, renderTheme);
|
|
229
|
+
channel.removeListener(DOCS_RENDERED, renderTheme);
|
|
230
|
+
prefersDark.removeListener(prefersDarkUpdate);
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
React.useEffect(() => {
|
|
234
|
+
channel.on(UPDATE_DARK_MODE_EVENT_NAME, updateMode);
|
|
235
|
+
return () => {
|
|
236
|
+
channel.removeListener(UPDATE_DARK_MODE_EVENT_NAME, updateMode);
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
// Storybook's first render doesn't have the global user params loaded so we
|
|
240
|
+
// need the effect to run whenever defaultMode is updated
|
|
241
|
+
React.useEffect(() => {
|
|
242
|
+
// If a users has set the mode this is respected
|
|
243
|
+
if (userHasExplicitlySetTheTheme) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (defaultMode) {
|
|
248
|
+
updateMode(defaultMode);
|
|
249
|
+
} else if (prefersDark.matches) {
|
|
250
|
+
updateMode("dark");
|
|
251
|
+
}
|
|
252
|
+
}, [defaultMode, updateMode, userHasExplicitlySetTheTheme]);
|
|
253
|
+
return (
|
|
254
|
+
<IconButton
|
|
255
|
+
key="dark-mode"
|
|
256
|
+
title={
|
|
257
|
+
isDark ? "Change theme to light mode" : "Change theme to dark mode"
|
|
258
|
+
}
|
|
259
|
+
onClick={handleIconClick}
|
|
260
|
+
>
|
|
261
|
+
{isDark ? (
|
|
262
|
+
<SunIcon aria-hidden="true" />
|
|
263
|
+
) : (
|
|
264
|
+
<MoonIcon aria-hidden="true" />
|
|
265
|
+
)}
|
|
266
|
+
</IconButton>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export default DarkMode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { addons, useState, useEffect } from "storybook/preview-api";
|
|
2
|
+
import { DARK_MODE_EVENT_NAME } from "./constants";
|
|
3
|
+
import { store } from "./Tool";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current state of storybook's dark-mode
|
|
7
|
+
*/
|
|
8
|
+
export function useDarkMode(): boolean {
|
|
9
|
+
const [isDark, setIsDark] = useState(store().current === "dark");
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const chan = addons.getChannel();
|
|
13
|
+
chan.on(DARK_MODE_EVENT_NAME, setIsDark);
|
|
14
|
+
return () => chan.off(DARK_MODE_EVENT_NAME, setIsDark);
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
return isDark;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export * from "./constants";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { addons } from "storybook/manager-api";
|
|
2
|
+
import { Addon_TypesEnum } from "storybook/internal/types";
|
|
3
|
+
import { themes } from "storybook/theming";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import Tool, { prefersDark, store } from "../Tool";
|
|
7
|
+
|
|
8
|
+
const currentStore = store();
|
|
9
|
+
const currentTheme =
|
|
10
|
+
currentStore.current || (prefersDark.matches && "dark") || "light";
|
|
11
|
+
|
|
12
|
+
addons.setConfig({
|
|
13
|
+
theme: {
|
|
14
|
+
...themes[currentTheme],
|
|
15
|
+
...currentStore[currentTheme],
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
addons.register("storybook/dark-mode", (api) => {
|
|
20
|
+
addons.add("storybook/dark-mode", {
|
|
21
|
+
title: "dark mode",
|
|
22
|
+
type: Addon_TypesEnum.TOOL,
|
|
23
|
+
match: ({ viewMode }) => viewMode === "story" || viewMode === "docs",
|
|
24
|
+
render: () => <Tool api={api} />,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { addons, makeDecorator, useArgs } from "
|
|
1
|
+
import { addons, makeDecorator, useArgs } from "storybook/preview-api";
|
|
2
|
+
import { SNIPPET_RENDERED } from "storybook/internal/docs-tools";
|
|
2
3
|
import { h, onMounted, watch } from "vue";
|
|
3
4
|
|
|
4
5
|
const params = new URLSearchParams(window.location.search);
|
|
5
6
|
let previousStoryId = null;
|
|
7
|
+
let previousArgs = {};
|
|
6
8
|
|
|
7
9
|
function getArgsFromUrl(storyId) {
|
|
8
10
|
const isInIframe = params.toString().includes("globals=");
|
|
@@ -23,6 +25,7 @@ export const vue3SourceDecorator = makeDecorator({
|
|
|
23
25
|
const story = storyFn(context);
|
|
24
26
|
const [, updateArgs] = useArgs();
|
|
25
27
|
const urlArgs = getArgsFromUrl(context.id);
|
|
28
|
+
const channel = addons.getChannel();
|
|
26
29
|
|
|
27
30
|
previousStoryId = context.id;
|
|
28
31
|
|
|
@@ -35,13 +38,25 @@ export const vue3SourceDecorator = makeDecorator({
|
|
|
35
38
|
onMounted(async () => {
|
|
36
39
|
updateArgs({ ...context.args, ...urlArgs });
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
/* override default code snippet by optimized ones */
|
|
42
|
+
setTimeout(setSourceCode, 500);
|
|
43
|
+
|
|
44
|
+
/* rerender code snippet by optimized ones */
|
|
45
|
+
channel.on(SNIPPET_RENDERED, async (payload) => {
|
|
46
|
+
if (payload.source.includes(`<script lang="ts" setup>`)) {
|
|
47
|
+
await setSourceCode();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
39
50
|
});
|
|
40
51
|
|
|
41
52
|
watch(
|
|
42
53
|
context.args,
|
|
43
|
-
async () => {
|
|
54
|
+
async (newArgs) => {
|
|
55
|
+
if (JSON.stringify(previousArgs) === JSON.stringify(newArgs)) return;
|
|
56
|
+
|
|
57
|
+
previousArgs = { ...newArgs };
|
|
44
58
|
updateArgs({ ...context.args });
|
|
59
|
+
|
|
45
60
|
await setSourceCode();
|
|
46
61
|
},
|
|
47
62
|
{ deep: true },
|
|
@@ -52,8 +67,6 @@ export const vue3SourceDecorator = makeDecorator({
|
|
|
52
67
|
const src = context.originalStoryFn(context.args, context.argTypes).template;
|
|
53
68
|
const code = preFormat(src, context.args, context.argTypes);
|
|
54
69
|
|
|
55
|
-
const channel = addons.getChannel();
|
|
56
|
-
|
|
57
70
|
const emitFormattedTemplate = async () => {
|
|
58
71
|
const prettier = await import("prettier2");
|
|
59
72
|
const prettierHtml = await import("prettier2/parser-html");
|
|
@@ -64,8 +77,8 @@ export const vue3SourceDecorator = makeDecorator({
|
|
|
64
77
|
htmlWhitespaceSensitivity: "ignore",
|
|
65
78
|
});
|
|
66
79
|
|
|
67
|
-
// emits an event when the transformation is completed
|
|
68
|
-
channel.emit(
|
|
80
|
+
// emits an event when the transformation is completed and content rendered
|
|
81
|
+
channel.emit(SNIPPET_RENDERED, {
|
|
69
82
|
id: context.id,
|
|
70
83
|
args: context.args,
|
|
71
84
|
source: postFormat(formattedCode),
|
|
@@ -124,7 +137,9 @@ function preFormat(templateSource, args, argTypes) {
|
|
|
124
137
|
// eslint-disable-next-line vue/max-len
|
|
125
138
|
`</template><template v-else-if="slot === 'default' && args['defaultSlot']">{{ args['defaultSlot'] }}</template><template v-else-if="args[slot + 'Slot']">{{ args[slot + 'Slot'] }}</template></template>`;
|
|
126
139
|
|
|
127
|
-
const modelValue =
|
|
140
|
+
const modelValue = isPrimitive(args["modelValue"])
|
|
141
|
+
? JSON.stringify(args["modelValue"])?.replaceAll('"', "")
|
|
142
|
+
: JSON.stringify(args["modelValue"])?.replaceAll('"', "'");
|
|
128
143
|
|
|
129
144
|
templateSource = templateSource
|
|
130
145
|
.replace(/>[\s]+</g, "><")
|
|
@@ -259,16 +274,17 @@ function generateEnumAttributes(args, option) {
|
|
|
259
274
|
|
|
260
275
|
return enumKeys
|
|
261
276
|
.map((key) => {
|
|
262
|
-
|
|
263
|
-
Object.keys(args[key] || {}).length || (Array.isArray(args[key]) && args[key].length);
|
|
264
|
-
|
|
265
|
-
return key in args && isNotPrimitive
|
|
277
|
+
return key in args && !isPrimitive(args[key])
|
|
266
278
|
? `${key}="${JSON.stringify(args[key]).replaceAll('"', "'").replaceAll("{enumValue}", option)}"`
|
|
267
279
|
: `${key}="${option}"`;
|
|
268
280
|
})
|
|
269
281
|
.join(" ");
|
|
270
282
|
}
|
|
271
283
|
|
|
284
|
+
function isPrimitive(value) {
|
|
285
|
+
return !(value && (typeof value === "object" || Array.isArray(value)));
|
|
286
|
+
}
|
|
287
|
+
|
|
272
288
|
function propToSource(key, val, argType) {
|
|
273
289
|
const defaultValue = argType.table?.defaultValue?.summary;
|
|
274
290
|
const type = typeof val;
|
package/.storybook/index.css
CHANGED
|
@@ -265,12 +265,19 @@ body {
|
|
|
265
265
|
margin-top: 0.5rem; /* mt-2 */
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
.sb-anchor > p {
|
|
269
|
+
margin-top: -0.5rem; /* mt-2 */
|
|
270
|
+
margin-bottom: -0.5rem; /* -mt-2 */
|
|
271
|
+
}
|
|
272
|
+
|
|
268
273
|
.dark .sb-anchor > p > a {
|
|
269
274
|
color: #4ade80; /* text-green-400 */
|
|
275
|
+
text-decoration: underline dashed #4ade80;
|
|
270
276
|
}
|
|
271
277
|
|
|
272
278
|
.light .sb-anchor > p > a {
|
|
273
279
|
color: #16a34a; /* text-green-600 */
|
|
280
|
+
text-decoration: underline dashed #16a34a;
|
|
274
281
|
}
|
|
275
282
|
|
|
276
283
|
.sb-bar,
|
package/.storybook/main.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
|
|
1
3
|
/** @type { import('@storybook/vue3-vite').StorybookConfig } */
|
|
2
4
|
export default {
|
|
3
5
|
stories: [
|
|
@@ -5,12 +7,12 @@ export default {
|
|
|
5
7
|
"../node_modules/vueless/**/docs.mdx",
|
|
6
8
|
/* Define a path to your own component stories. */
|
|
7
9
|
// "../src/**/stories.{js,jsx,ts,tsx}",
|
|
8
|
-
// "../src/**/docs.mdx"
|
|
10
|
+
// "../src/**/docs.mdx",
|
|
11
|
+
],
|
|
9
12
|
addons: [
|
|
13
|
+
"@storybook/addon-docs",
|
|
10
14
|
"@storybook/addon-links",
|
|
11
|
-
"
|
|
12
|
-
"@storybook/addon-interactions",
|
|
13
|
-
"storybook-dark-mode",
|
|
15
|
+
resolve(__dirname, "./addons/storybook-dark-mode/preset/manager.tsx"),
|
|
14
16
|
"@storybook/addon-themes",
|
|
15
17
|
],
|
|
16
18
|
framework: {
|
|
@@ -23,183 +23,183 @@ Custom dark mode related vueless loader.
|
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
25
|
<style>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
26
|
+
/* -------------------- Prevent showing users default storybook theme styles -------------------- */
|
|
27
|
+
|
|
28
|
+
html.dark {
|
|
29
|
+
background: #111827;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#root {
|
|
33
|
+
visibility: hidden;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#sb-vueless-loader {
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
position: fixed;
|
|
43
|
+
background: inherit;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 100%;
|
|
46
|
+
z-index: 999;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.light #sb-vueless-loader {
|
|
50
|
+
background: #f1f5f9;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.dark #sb-vueless-loader {
|
|
54
|
+
background: #111827;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sb-vueless-loader-img-dark,
|
|
58
|
+
.sb-vueless-loader-img-light {
|
|
59
|
+
display: none;
|
|
60
|
+
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.light .sb-vueless-loader-img-light {
|
|
64
|
+
display: block;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.dark .sb-vueless-loader-img-dark {
|
|
68
|
+
display: block;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@keyframes pulse {
|
|
72
|
+
0%, 100% {
|
|
73
|
+
opacity: 1;
|
|
74
|
+
}
|
|
75
|
+
50% {
|
|
76
|
+
opacity: .5;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* -------------------- Storybook config tooltip -------------------- */
|
|
81
|
+
|
|
82
|
+
div[data-testid="tooltip"] {
|
|
83
|
+
border-radius: 8px;
|
|
84
|
+
overflow: hidden;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
div[data-testid="tooltip"] a[id]:hover,
|
|
88
|
+
div[data-testid="tooltip"] button[id]:hover {
|
|
89
|
+
background-color: rgb(17 24 39 / 5%) !important;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.dark div[data-testid="tooltip"] a[id]:hover,
|
|
93
|
+
.dark div[data-testid="tooltip"] button[id]:hover {
|
|
94
|
+
background-color: rgb(255 255 255 / 5%) !important;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* -------------------- Storybook sidebar -------------------- */
|
|
98
|
+
|
|
99
|
+
.dark .sidebar-container {
|
|
100
|
+
background: #020713;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.sidebar-header img {
|
|
104
|
+
width: 150px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.sidebar-header a:focus {
|
|
108
|
+
border: 1px solid transparent;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.sidebar-item {
|
|
112
|
+
border-radius: 6px !important;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.dark .sidebar-item:hover {
|
|
116
|
+
background: #101828 !important;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.dark .sidebar-item[data-selected="true"],
|
|
120
|
+
.dark .sidebar-item[data-selected="true"]:hover {
|
|
121
|
+
background: #1f2937 !important;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.search-field,
|
|
125
|
+
.search-result-item {
|
|
126
|
+
border-radius: 8px !important;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.sidebar-item,
|
|
130
|
+
.search-result-item {
|
|
131
|
+
text-transform: capitalize;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.light .sidebar-item svg[type="component"],
|
|
135
|
+
.light .search-result-item svg[type="component"],
|
|
136
|
+
.dark .search-result-item mark {
|
|
137
|
+
color: #10b981;
|
|
138
|
+
font-weight: 600;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.dark .sidebar-item svg[type="component"],
|
|
142
|
+
.dark .search-result-item svg[type="component"],
|
|
143
|
+
.light .search-result-item mark {
|
|
144
|
+
color: #059669;
|
|
145
|
+
font-weight: 600;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.light .sidebar-item svg[type="document"],
|
|
149
|
+
.light .sidebar-item svg[type="story"],
|
|
150
|
+
.light .search-result-item svg[type="document"],
|
|
151
|
+
.light .search-result-item svg[type="story"] {
|
|
152
|
+
color: #9ca3af;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.dark .sidebar-item svg[type="document"],
|
|
156
|
+
.dark .sidebar-item svg[type="story"],
|
|
157
|
+
.dark .search-result-item svg[type="document"],
|
|
158
|
+
.dark .search-result-item svg[type="story"] {
|
|
159
|
+
color: #4b5563;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.light .search-result-item--label {
|
|
163
|
+
color: #6b7280; /* text-gray-600 */
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.dark .search-result-item--label {
|
|
167
|
+
color: #a8abb0; /* text-gray-400 */
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#sidebar-bottom-wrapper {
|
|
171
|
+
display: none;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* -------------------- Storybook args -------------------- */
|
|
175
|
+
|
|
176
|
+
.dark,
|
|
177
|
+
.dark #panel-tab-content div,
|
|
178
|
+
.dark .docblock-argstable-body > tr > td {
|
|
179
|
+
background: #030712 !important;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.light,
|
|
183
|
+
.light #panel-tab-content div,
|
|
184
|
+
.light .docblock-argstable-body > tr > td {
|
|
185
|
+
background: #f9fafb !important;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.dark .docblock-argstable-head > tr {
|
|
189
|
+
background: #1e293b !important;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.dark .docblock-argstable-body tr > td textarea,
|
|
193
|
+
.dark .docblock-argstable-body tr > td select,
|
|
194
|
+
.dark .docblock-argstable-body tr > td:last-child button:not([tabindex="-1"]) {
|
|
195
|
+
background: #111827;
|
|
196
|
+
border: solid 1px #1f2937;
|
|
197
|
+
box-shadow: none;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.light .docblock-argstable-body tr > td:last-child button:not([tabindex="-1"]) {
|
|
201
|
+
background: white;
|
|
202
|
+
}
|
|
203
203
|
</style>
|
|
204
204
|
|
|
205
205
|
<script>
|
package/.storybook/manager.js
CHANGED
package/.storybook/preview.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Vueless, TailwindCSS } from "vueless/plugin-vite";
|
|
|
6
6
|
import { STORYBOOK_ENV } from "vueless/constants.js";
|
|
7
7
|
|
|
8
8
|
export default defineConfig({
|
|
9
|
-
plugins: [Vue(), TailwindCSS(), Vueless({ env: STORYBOOK_ENV
|
|
9
|
+
plugins: [Vue(), TailwindCSS(), Vueless({ env: STORYBOOK_ENV })],
|
|
10
10
|
optimizeDeps: {
|
|
11
11
|
include: [
|
|
12
12
|
"cva",
|
|
@@ -14,10 +14,10 @@ export default defineConfig({
|
|
|
14
14
|
"@tailwindcss/forms",
|
|
15
15
|
"prettier2",
|
|
16
16
|
"prettier2/parser-html",
|
|
17
|
-
"@storybook/blocks",
|
|
18
|
-
"
|
|
17
|
+
"@storybook/addon-docs/blocks",
|
|
18
|
+
"storybook/theming/create",
|
|
19
19
|
"@storybook/addon-themes",
|
|
20
|
-
"@storybook/
|
|
20
|
+
"@storybook/vue3-vite",
|
|
21
21
|
],
|
|
22
22
|
},
|
|
23
23
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueless/storybook",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Simplifies Storybook configuration for Vueless UI library.",
|
|
5
5
|
"homepage": "https://vueless.com",
|
|
6
6
|
"author": "Johnny Grid",
|
|
@@ -26,37 +26,39 @@
|
|
|
26
26
|
"release:major": "release-it major --ci --npm.publish --git.tag --github.release"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@storybook/addon-
|
|
30
|
-
"@storybook/addon-
|
|
31
|
-
"@storybook/addon-
|
|
32
|
-
"@storybook/
|
|
33
|
-
"@storybook
|
|
34
|
-
"@storybook/manager-api": "^8.6.10",
|
|
35
|
-
"@storybook/test": "^8.6.10",
|
|
36
|
-
"@storybook/theming": "^8.6.10",
|
|
37
|
-
"@storybook/vue3": "^8.6.10",
|
|
38
|
-
"@storybook/vue3-vite": "^8.6.10",
|
|
29
|
+
"@storybook/addon-docs": "9.0.4",
|
|
30
|
+
"@storybook/addon-links": "9.0.4",
|
|
31
|
+
"@storybook/addon-themes": "9.0.4",
|
|
32
|
+
"@storybook/vue3-vite": "9.0.4",
|
|
33
|
+
"@vueless/storybook-dark-mode": "^9.0.2",
|
|
39
34
|
"chokidar": "^4.0.3",
|
|
40
|
-
"esbuild": "^0.
|
|
41
|
-
"globby": "^14.0
|
|
35
|
+
"esbuild": "^0.25.5",
|
|
36
|
+
"globby": "^14.1.0",
|
|
42
37
|
"mkdirp": "^3.0.1",
|
|
43
38
|
"prettier2": "npm:prettier@2.8.8",
|
|
44
|
-
"storybook": "
|
|
45
|
-
"storybook-dark-mode": "^4.0.2",
|
|
39
|
+
"storybook": "9.0.4",
|
|
46
40
|
"vue-docgen-api": "^4.79.2"
|
|
47
41
|
},
|
|
48
42
|
"devDependencies": {
|
|
49
|
-
"@release-it/bumper": "^
|
|
43
|
+
"@release-it/bumper": "^7.0.5",
|
|
50
44
|
"eslint": "^8.57.0",
|
|
51
45
|
"eslint-config-prettier": "^9.1.0",
|
|
52
46
|
"eslint-plugin-node": "^11.1.0",
|
|
53
47
|
"eslint-plugin-prettier": "^5.1.3",
|
|
54
48
|
"prettier": "^3.2.5",
|
|
55
49
|
"prettier-eslint": "^16.3.0",
|
|
56
|
-
"release-it": "^
|
|
57
|
-
"tailwindcss": "^4.
|
|
58
|
-
"vue
|
|
59
|
-
"
|
|
50
|
+
"release-it": "^19.0.2",
|
|
51
|
+
"tailwindcss": "^4.1.7",
|
|
52
|
+
"vue": "^3.5.16",
|
|
53
|
+
"vue-router": "^4.5.1",
|
|
54
|
+
"vueless": "^1.0.0"
|
|
55
|
+
},
|
|
56
|
+
"overrides": {
|
|
57
|
+
"vue-docgen-api": {
|
|
58
|
+
"vue": "latest",
|
|
59
|
+
"vue-template-compiler": "latest"
|
|
60
|
+
},
|
|
61
|
+
"storybook": "$storybook"
|
|
60
62
|
},
|
|
61
63
|
"resolutions": {
|
|
62
64
|
"jackspeak": "2.3.6"
|
package/webTypes/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { extractConfig } from "./lib/config.js";
|
|
3
3
|
import build from "./lib/build.js";
|
|
4
4
|
|
|
5
|
-
export default async function buildWebTypes(vuelessConfig) {
|
|
5
|
+
export default async function buildWebTypes(vuelessConfig, srcDir) {
|
|
6
6
|
const config = await extractConfig();
|
|
7
7
|
|
|
8
|
-
build(config, vuelessConfig);
|
|
8
|
+
build(config, vuelessConfig, srcDir);
|
|
9
9
|
}
|
package/webTypes/lib/build.js
CHANGED
|
@@ -7,8 +7,9 @@ import { globbySync } from "globby";
|
|
|
7
7
|
import { parse } from "vue-docgen-api";
|
|
8
8
|
import _ from "lodash-es";
|
|
9
9
|
|
|
10
|
-
export default async function build(config, vuelessConfig) {
|
|
10
|
+
export default async function build(config, vuelessConfig, srcDir) {
|
|
11
11
|
config.outFile = path.resolve(config.cwd, config.outFile);
|
|
12
|
+
config.srcDir = srcDir;
|
|
12
13
|
|
|
13
14
|
const { watcher, componentFiles } = getSources(config.components, config.cwd);
|
|
14
15
|
|
|
@@ -137,7 +138,7 @@ function getType(prop) {
|
|
|
137
138
|
async function extractInformation(absolutePath, config, vuelessConfig) {
|
|
138
139
|
const doc = await parse(config.cwd + "/" + absolutePath, {
|
|
139
140
|
/* Allow to parse vueless components from node_modules. */
|
|
140
|
-
validExtends: (filePath) => filePath.includes(
|
|
141
|
+
validExtends: (filePath) => filePath.includes(config.srcDir),
|
|
141
142
|
...config.apiOptions,
|
|
142
143
|
});
|
|
143
144
|
const name = doc.name || doc.displayName;
|