|
| 1 | +/** @jsxImportSource solid-js */ |
| 2 | +import type { Preview, SolidRenderer } from "storybook-solidjs-vite" |
| 3 | +import type { DecoratorFunction } from "storybook/internal/types" |
| 4 | +import { applyKiloTheme, applyVscodeTheme, clearVscodeTheme } from "../src/stories/theme-decorator" |
| 5 | +import "./fonts.css" |
| 6 | +import "../src/styles/index.css" |
| 7 | + |
| 8 | +const themeDecorator: DecoratorFunction<SolidRenderer> = (Story, context) => { |
| 9 | + const themeId = (context.globals["theme"] as string) ?? "kilo" |
| 10 | + const vscodeThemeId = (context.globals["vscodeTheme"] as string) ?? "dark-modern" |
| 11 | + |
| 12 | + const colorScheme = (() => { |
| 13 | + if (themeId === "kilo-vscode") return applyVscodeTheme(vscodeThemeId) |
| 14 | + clearVscodeTheme() |
| 15 | + return (context.globals["colorScheme"] as "light" | "dark") ?? "dark" |
| 16 | + })() |
| 17 | + |
| 18 | + applyKiloTheme(themeId, colorScheme) |
| 19 | + document.body.style.background = "var(--background-base)" |
| 20 | + document.body.style.color = "var(--text-base)" |
| 21 | + return Story() |
| 22 | +} |
| 23 | + |
| 24 | +const preview: Preview = { |
| 25 | + parameters: { |
| 26 | + controls: { |
| 27 | + matchers: { |
| 28 | + color: /(background|color)$/i, |
| 29 | + date: /Date$/i, |
| 30 | + }, |
| 31 | + }, |
| 32 | + layout: "centered", |
| 33 | + }, |
| 34 | + decorators: [themeDecorator], |
| 35 | + globalTypes: { |
| 36 | + theme: { |
| 37 | + description: "Theme", |
| 38 | + toolbar: { |
| 39 | + title: "Theme", |
| 40 | + icon: "paintbrush", |
| 41 | + items: [ |
| 42 | + { value: "kilo", title: "Kilo" }, |
| 43 | + { value: "kilo-vscode", title: "Kilo VSCode" }, |
| 44 | + ], |
| 45 | + dynamicTitle: true, |
| 46 | + }, |
| 47 | + }, |
| 48 | + colorScheme: { |
| 49 | + description: "Color Scheme", |
| 50 | + toolbar: { |
| 51 | + title: "Color Scheme", |
| 52 | + icon: "circlehollow", |
| 53 | + items: [ |
| 54 | + { value: "dark", title: "Dark", icon: "moon" }, |
| 55 | + { value: "light", title: "Light", icon: "sun" }, |
| 56 | + ], |
| 57 | + dynamicTitle: true, |
| 58 | + }, |
| 59 | + }, |
| 60 | + vscodeTheme: { |
| 61 | + description: "VSCode Theme", |
| 62 | + toolbar: { |
| 63 | + title: "VSCode Theme", |
| 64 | + icon: "browser", |
| 65 | + items: [ |
| 66 | + { value: "dark-modern", title: "Dark Modern (default)" }, |
| 67 | + { value: "dark-plus", title: "Dark+" }, |
| 68 | + { value: "dark-vs", title: "Dark (Visual Studio)" }, |
| 69 | + { value: "light-modern", title: "Light Modern" }, |
| 70 | + { value: "light-plus", title: "Light+" }, |
| 71 | + { value: "light-vs", title: "Light (Visual Studio)" }, |
| 72 | + { value: "hc-black", title: "High Contrast" }, |
| 73 | + { value: "hc-light", title: "High Contrast Light" }, |
| 74 | + { value: "monokai", title: "Monokai" }, |
| 75 | + { value: "solarized-dark", title: "Solarized Dark" }, |
| 76 | + { value: "solarized-light", title: "Solarized Light" }, |
| 77 | + { value: "red", title: "Red" }, |
| 78 | + { value: "quiet-light", title: "Quiet Light" }, |
| 79 | + { value: "tomorrow-night-blue", title: "Tomorrow Night Blue" }, |
| 80 | + { value: "kimbie-dark", title: "Kimbie Dark" }, |
| 81 | + { value: "abyss", title: "Abyss" }, |
| 82 | + ], |
| 83 | + dynamicTitle: true, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + initialGlobals: { |
| 88 | + theme: "kilo", |
| 89 | + colorScheme: "dark", |
| 90 | + vscodeTheme: "dark-modern", |
| 91 | + }, |
| 92 | +} |
| 93 | + |
| 94 | +export default preview |
0 commit comments