Skip to content

Commit 85ac3d7

Browse files
docs(ui): add storybook theme addon (#1713)
1 parent 0a2d3d7 commit 85ac3d7

File tree

5 files changed

+55
-26
lines changed

5 files changed

+55
-26
lines changed

.storybook/main.ts

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

33
const config = {
44
stories: ['../app/**/*.stories.@(js|ts)'],
5-
addons: ['@storybook/addon-a11y', '@storybook/addon-docs'],
5+
addons: ['@storybook/addon-a11y', '@storybook/addon-docs', '@storybook/addon-themes'],
66
framework: '@storybook-vue/nuxt',
77
features: {
88
backgrounds: false,

.storybook/preview.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Preview } from '@storybook-vue/nuxt'
2+
import { withThemeByDataAttribute } from '@storybook/addon-themes'
23
import { currentLocales } from '../config/i18n'
34
import { fn } from 'storybook/test'
45
import { ACCENT_COLORS } from '../shared/utils/constants'
@@ -58,31 +59,22 @@ const preview: Preview = {
5859
],
5960
},
6061
},
61-
theme: {
62-
name: 'Theme',
63-
description: 'Color mode',
64-
defaultValue: 'dark',
65-
toolbar: {
66-
icon: 'moon',
67-
dynamicTitle: true,
68-
items: [
69-
{ value: 'light', icon: 'sun', title: 'Light' },
70-
{ value: 'dark', icon: 'moon', title: 'Dark' },
71-
],
72-
},
73-
},
7462
},
7563
decorators: [
64+
withThemeByDataAttribute({
65+
themes: {
66+
Light: 'light',
67+
Dark: 'dark',
68+
},
69+
defaultTheme: 'Dark',
70+
attributeName: 'data-theme',
71+
}),
7672
(story, context) => {
77-
const { locale, theme, accentColor } = context.globals as {
73+
const { locale, accentColor } = context.globals as {
7874
locale: string
79-
theme: string
8075
accentColor?: string
8176
}
8277

83-
// Set theme from globals
84-
document.documentElement.setAttribute('data-theme', theme)
85-
8678
// Set accent color from globals
8779
if (accentColor) {
8880
document.documentElement.style.setProperty('--accent-color', `var(--swatch-${accentColor})`)

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@
122122
"@intlify/core-base": "11.2.8",
123123
"@npm/types": "2.1.0",
124124
"@playwright/test": "1.58.2",
125-
"@storybook-vue/nuxt": "9.0.1",
126-
"@storybook/addon-a11y": "^10.2.7",
127-
"@storybook/addon-docs": "^10.2.7",
125+
"@storybook-vue/nuxt": "catalog:storybook",
126+
"@storybook/addon-a11y": "catalog:storybook",
127+
"@storybook/addon-docs": "catalog:storybook",
128+
"@storybook/addon-themes": "catalog:storybook",
128129
"@types/node": "24.10.13",
129130
"@types/sanitize-html": "2.16.0",
130131
"@types/semver": "7.7.1",
@@ -145,7 +146,7 @@
145146
"oxlint": "1.50.0",
146147
"schema-dts": "1.1.5",
147148
"simple-git-hooks": "2.13.1",
148-
"storybook": "^10.2.7",
149+
"storybook": "catalog:storybook",
149150
"typescript": "5.9.3",
150151
"vitest": "npm:@voidzero-dev/vite-plus-test@0.0.0-g52709db6.20260226-1136",
151152
"vitest-environment-nuxt": "1.0.1",

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ patchedDependencies:
3737
savePrefix: ''
3838

3939
shellEmulator: true
40+
41+
catalogs:
42+
storybook:
43+
'@storybook-vue/nuxt': '9.0.1'
44+
'@storybook/addon-a11y': '^10.2.7'
45+
'@storybook/addon-docs': '^10.2.7'
46+
'@storybook/addon-themes': '^10.2.7'
47+
'storybook': '^10.2.7'

0 commit comments

Comments
 (0)