Skip to content

Commit 9ef5c53

Browse files
Merge pull request #29 from vuelessjs/beta
Beta
2 parents f7da643 + 5cab444 commit 9ef5c53

29 files changed

Lines changed: 598 additions & 1386 deletions

β€Ž.npmrcβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
shamefully-hoist=true
2-
strict-peer-dependencies=false
1+
legacy-peer-deps=true

β€Ž.storybook/main.tsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { defineConfigWithVueless } from "@vueless/storybook";
33

44
export default defineConfigWithVueless({
55
stories: [
6-
/* Define a path to your own component stories. */
7-
// "../src/**/stories.{js,jsx,ts,tsx}",
6+
/* Path to the project component stories. */
7+
// "../src/**/stories.ts",
88
// "../src/**/docs.mdx",
9+
//
10+
/* Path to the custom vueless component stories. */
11+
// "../.vueless/components/**/stories.ts",
12+
// "../.vueless/components/**/docs.mdx",
913
],
1014
});

β€Ž.storybook/manager-head.htmlβ€Ž

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
Overrides content of storybook layout HTML page.
33
-->
44
<link rel="shortcut icon" href="./favicons/favicon.ico">
5-
<link rel="icon" type="image/svg+xml" href="./favicons/favicon.svg" />
65

76
<!--
8-
Custom dark mode related vueless loader.
7+
Custom color mode vueless loader.
98
-->
109
<div id="sb-vueless-loader">
1110
<img
1211
class="sb-vueless-loader-img-dark"
13-
src="./images/vueless-logo-dark.svg"
12+
src="./images/logo-dark.svg"
1413
alt="Vueless UI"
1514
width="250" />
1615

1716
<img
1817
class="sb-vueless-loader-img-light"
19-
src="./images/vueless-logo-light.svg"
18+
src="./images/logo-light.svg"
2019
alt="Vueless UI"
2120
width="250" />
2221
</div>
@@ -78,12 +77,13 @@
7877

7978
<script>
8079
/* This trick prevents showing users the default storybook theme. */
81-
(() => {
82-
window.onload = function() {
83-
setTimeout(() => {
84-
document.getElementById("root").style.visibility = 'visible';
85-
document.getElementById("sb-vueless-loader").style.display = 'none';
86-
}, 1500);
87-
};
88-
})();
80+
window.onload = () => {
81+
setTimeout(() => {
82+
const rootElement = document.getElementById("root");
83+
const vuelessLoader = document.getElementById("sb-vueless-loader");
84+
85+
if (rootElement) rootElement.style.visibility = "visible";
86+
if (vuelessLoader) vuelessLoader.style.display = "none";
87+
}, 1500);
88+
};
8989
</script>

β€Ž.storybook/manager.tsβ€Ž

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { addons } from "storybook/manager-api";
2+
import { getThemeDark, getThemeLight } from "@vueless/storybook/themes";
23

34
/* Theme styles */
4-
import "./themes/manager.css";
5-
import { themeDark } from "./themes/themeDark";
6-
import { themeLight } from "./themes/themeLight";
5+
import "./theme/theme.css";
6+
import "@vueless/storybook/manager.css";
7+
import { theme } from "./theme/theme";
78

89
const DARK_MODE_KEY = "dark";
910
const LIGHT_MODE_KEY = "light";
@@ -24,11 +25,28 @@ prefersColorSchemeDark.addEventListener("change", (event) => {
2425

2526
function setSystemTheme(colorMode: string) {
2627
addons.setConfig({
27-
theme: colorMode === DARK_MODE_KEY ? themeDark : themeLight,
28+
theme: colorMode === DARK_MODE_KEY ? getThemeDark(theme) : getThemeLight(theme),
2829
panelPosition: "right",
2930
});
3031
}
3132

3233
function getSystemColorMode(isDarkMode: boolean) {
3334
return isDarkMode ? DARK_MODE_KEY : LIGHT_MODE_KEY;
3435
}
36+
37+
/* Change the Storybook manager favicon when system color mode changed. */
38+
prefersColorSchemeDark.addEventListener("change", setFavicon);
39+
40+
setFavicon();
41+
42+
function setFavicon() {
43+
const link = document.createElement("link");
44+
45+
link.rel = "icon";
46+
link.type = "image/svg+xml";
47+
link.href = prefersColorSchemeDark.matches
48+
? "/favicons/favicon-dark.svg"
49+
: "/favicons/favicon-light.svg";
50+
51+
document.head.appendChild(link);
52+
}

β€Ž.storybook/preview-head.htmlβ€Ž

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,105 @@
99
<link rel="preconnect" crossorigin="anonymous" href="https://fonts.googleapis.com">
1010
<link rel="preconnect" crossorigin="anonymous" href="https://fonts.gstatic.com">
1111
<link rel="stylesheet" crossorigin="anonymous" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap">
12+
13+
<style>
14+
body {
15+
font-family: Roboto, sans-serif;
16+
}
17+
18+
.sbdocs-content :is(h1, h2, h3, h4, h5, h6)[id] {
19+
scroll-margin-top: 8px;
20+
}
21+
</style>
22+
23+
<script>
24+
(function docsAnchorScroll() {
25+
var ANCHOR_PREFIX = "anchor--";
26+
var OBSERVE_MS = 20000;
27+
var cancelled = false;
28+
var observer = null;
29+
var timeoutId = null;
30+
var rafId = null;
31+
32+
function cleanup() {
33+
cancelled = true;
34+
if (observer) {
35+
observer.disconnect();
36+
observer = null;
37+
}
38+
if (timeoutId !== null) {
39+
clearTimeout(timeoutId);
40+
timeoutId = null;
41+
}
42+
if (rafId !== null) {
43+
cancelAnimationFrame(rafId);
44+
rafId = null;
45+
}
46+
}
47+
48+
function targetIdFromHash() {
49+
var h = window.location.hash;
50+
if (!h || h.length < 2) {
51+
return null;
52+
}
53+
var id = decodeURIComponent(h.slice(1));
54+
if (id.indexOf(ANCHOR_PREFIX) !== 0) {
55+
return null;
56+
}
57+
return id;
58+
}
59+
60+
function tryScroll(targetId) {
61+
var el = document.getElementById(targetId);
62+
if (!el) {
63+
return false;
64+
}
65+
el.scrollIntoView({ block: "start", inline: "nearest", behavior: "auto" });
66+
return true;
67+
}
68+
69+
function scheduleScrollToHash() {
70+
cleanup();
71+
cancelled = false;
72+
73+
var targetId = targetIdFromHash();
74+
if (!targetId) {
75+
return;
76+
}
77+
78+
if (tryScroll(targetId)) {
79+
return;
80+
}
81+
82+
observer = new MutationObserver(function () {
83+
if (!cancelled && tryScroll(targetId)) {
84+
cleanup();
85+
}
86+
});
87+
observer.observe(document.documentElement, { childList: true, subtree: true });
88+
89+
timeoutId = window.setTimeout(function () {
90+
cleanup();
91+
}, OBSERVE_MS);
92+
93+
function poll() {
94+
if (cancelled) {
95+
return;
96+
}
97+
if (tryScroll(targetId)) {
98+
cleanup();
99+
return;
100+
}
101+
rafId = window.requestAnimationFrame(poll);
102+
}
103+
rafId = window.requestAnimationFrame(poll);
104+
}
105+
106+
window.addEventListener("hashchange", scheduleScrollToHash);
107+
if (document.readyState === "loading") {
108+
document.addEventListener("DOMContentLoaded", scheduleScrollToHash);
109+
} else {
110+
scheduleScrollToHash();
111+
}
112+
})();
113+
</script>

β€Ž.storybook/preview.tsβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { storyDarkModeDecorator, vue3SourceDecorator } from "@vueless/storybook";
21
import { getRandomId } from "vueless";
2+
import { vue3SourceDecorator, storyDarkModeDecorator } from "@vueless/storybook";
3+
import { getThemeDark, getThemeLight, getThemeLightPreview } from "@vueless/storybook/themes";
34
import { setup } from "@storybook/vue3-vite";
45

56
import type { Preview } from "@storybook/vue3-vite";
67

78
/* Theme styles */
8-
import "./themes/preview.css";
9-
import { themeDark } from "./themes/themeDark";
10-
import { themeLight } from "./themes/themeLight";
11-
import { themeLightPreview } from "./themes/themeLightPreview";
9+
import "./theme/theme.css";
10+
import "@vueless/storybook/preview.css";
11+
import { theme } from "./theme/theme";
1212

1313
/* Vue plugins */
1414
import { createVueless } from "vueless";
@@ -39,12 +39,12 @@ export default {
3939
layout: "fullscreen",
4040
backgrounds: { disable: true },
4141
docs: {
42-
theme: themeLightPreview,
42+
theme: getThemeLightPreview(theme),
4343
source: { language: "html" },
4444
},
4545
darkMode: {
46-
light: themeLight,
47-
dark: themeDark,
46+
light: getThemeLight(theme),
47+
dark: getThemeDark(theme),
4848
classTarget: "body",
4949
stylePreview: true,
5050
},
Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Loading
2.76 KB
Binary file not shown.

β€Ž.storybook/public/favicons/favicon.svgβ€Ž

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
Β (0)