Skip to content

Commit 3f2b865

Browse files
docs(ui): add dark theme for storybook docs v2 (#2172)
1 parent 8ae65d5 commit 3f2b865

File tree

8 files changed

+142
-76
lines changed

8 files changed

+142
-76
lines changed

.storybook/main.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { StorybookConfig } from '@storybook-vue/nuxt'
22

33
const config = {
4-
stories: ['../app/**/*.stories.@(js|ts)'],
4+
stories: ['../.storybook/*.mdx', '../app/**/*.stories.@(js|ts)'],
55
addons: ['@storybook/addon-a11y', '@storybook/addon-docs', '@storybook/addon-themes'],
66
framework: '@storybook-vue/nuxt',
77
staticDirs: ['./.public'],
@@ -11,6 +11,33 @@ const config = {
1111
async viteFinal(newConfig) {
1212
newConfig.plugins ??= []
1313

14+
// Bridge compatibility between Storybook v10 core and v9 @storybook-vue/nuxt
15+
// v10 expects module federation globals that v9 doesn't provide
16+
newConfig.plugins.push({
17+
name: 'storybook-v10-compat',
18+
transformIndexHtml: {
19+
order: 'pre',
20+
handler(html) {
21+
const script = `
22+
<script>
23+
// Minimal shims for Storybook v10 module federation system
24+
// These will be replaced when Storybook runtime loads
25+
window.__STORYBOOK_MODULE_GLOBAL__ = { global: window };
26+
window.__STORYBOOK_MODULE_CLIENT_LOGGER__ = {
27+
deprecate: console.warn.bind(console, '[deprecated]'),
28+
once: console.log.bind(console),
29+
logger: console
30+
};
31+
window.__STORYBOOK_MODULE_CHANNELS__ = {
32+
Channel: class { on() {} off() {} emit() {} once() {} },
33+
createBrowserChannel: () => new window.__STORYBOOK_MODULE_CHANNELS__.Channel()
34+
};
35+
</script>`
36+
return html.replace(/<script>/, script + '<script>')
37+
},
38+
},
39+
})
40+
1441
newConfig.plugins.push({
1542
name: 'ignore-internals',
1643
transform(_, id) {

.storybook/manager.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { addons } from 'storybook/manager-api'
2-
import { create } from 'storybook/theming'
32

4-
const npmxTheme = create({
5-
brandTitle: 'npmx Storybook',
6-
brandImage: '/npmx-storybook.svg',
7-
})
3+
import npmxDark from './theme'
84

95
addons.setConfig({
10-
theme: npmxTheme,
6+
theme: npmxDark,
7+
layoutCustomisations: {
8+
showToolbar: (state, defaultValue) => {
9+
if (state.viewMode === 'docs' && state.storyId) {
10+
const story = state.index?.[state.storyId]
11+
const tags = story?.tags || []
12+
if (tags.includes('hide-toolbar')) {
13+
return false
14+
}
15+
}
16+
return defaultValue
17+
},
18+
},
1119
})

.storybook/preview-head.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<style>
2+
/* Override docs story canvas background to match npmx theme */
3+
.docs-story {
4+
background-color: var(--bg, oklch(0.171 0 0)) !important;
5+
}
6+
</style>

.storybook/preview.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { currentLocales } from '../config/i18n'
44
import { fn } from 'storybook/test'
55
import { ACCENT_COLORS } from '../shared/utils/constants'
66

7+
import npmxDark from './theme'
8+
79
// related: https://github.com/npmx-dev/npmx.dev/blob/1431d24be555bca5e1ae6264434d49ca15173c43/test/nuxt/setup.ts#L12-L26
810
// Stub Nuxt specific globals
911
// @ts-expect-error - dynamic global name
@@ -25,6 +27,9 @@ const preview: Preview = {
2527
date: /Date$/i,
2628
},
2729
},
30+
docs: {
31+
theme: npmxDark,
32+
},
2833
},
2934
// Provides toolbars to switch things like theming and language
3035
globalTypes: {

.storybook/storybook-welcome.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Meta } from '@storybook/addon-docs/blocks';
2+
3+
<Meta title="Welcome" tags={['hide-toolbar']}/>
4+
5+
# Welcome
6+
7+
Welcome to the npmx Storybook.

.storybook/theme.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { create } from 'storybook/theming'
2+
3+
const npmxDark = create({
4+
base: 'dark',
5+
6+
brandTitle: 'npmx Storybook',
7+
brandImage: '/npmx-storybook.svg',
8+
9+
// UI
10+
appContentBg: '#101010', // oklch(0.171 0 0)
11+
})
12+
13+
export default npmxDark

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ overrides:
2323
sharp: 0.34.5
2424
vite: npm:@voidzero-dev/vite-plus-core@0.1.12
2525
vitest: npm:@voidzero-dev/vite-plus-test@0.1.12
26-
storybook: ^10.2.7
26+
storybook: ^10.3.1
2727

2828
packageExtensions:
2929
'@nuxt/scripts':
@@ -43,7 +43,7 @@ shellEmulator: true
4343
catalogs:
4444
storybook:
4545
'@storybook-vue/nuxt': '9.0.1'
46-
'@storybook/addon-a11y': '^10.2.7'
47-
'@storybook/addon-docs': '^10.2.7'
48-
'@storybook/addon-themes': '^10.2.7'
49-
'storybook': '^10.2.7'
46+
'@storybook/addon-a11y': '^10.3.1'
47+
'@storybook/addon-docs': '^10.3.1'
48+
'@storybook/addon-themes': '^10.3.1'
49+
'storybook': '^10.3.1'

0 commit comments

Comments
 (0)