-
Notifications
You must be signed in to change notification settings - Fork 42
chore: implement storybook #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
df33940
d47927c
77adc50
5a1abb8
dc8dc2e
1d1fc50
e1d726c
0798669
34dd889
23ae3a2
ea85877
b2779b9
7d3b120
7ac9626
90768d4
a0324cb
ada1dcb
162bc3a
5587a8d
9dd27f4
76a6f3e
12d7c2b
eed89ac
fba820c
9def7ca
08d95ac
8861bb5
468b87c
d28e7ae
5261c61
a501c75
cdae85b
c85a0d5
f21ab72
1271eef
01544dc
901d0d6
ca15391
763cbea
6a825dc
64b5fc6
5227a74
d08350c
a47f0f0
af22f0d
4672a84
ca614fa
181a491
82385b8
ea16883
6d225a5
93a3e85
ecf7da1
ee1d2a6
144ea5e
7b5e825
cfedf94
0d5d139
e346f15
90c39bc
9350f36
6ac98ab
3411417
d534058
1d716b1
563c07c
0983d78
1e6e091
5a94c21
1440080
6b3aa21
93243c2
eef9896
7f12290
c0321a6
f05a685
19f74de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,6 @@ pnpm-debug.log | |
|
|
||
| # Workspace packages | ||
| packages/*/node_modules/ | ||
|
|
||
| # Storybook | ||
| storybook-static/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ | |
| flake.lock | ||
| pnpm-debug.log | ||
| pnpm-lock.yaml | ||
| /storybook-static/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| declare module "*.css"; | ||
| declare module "*.css?url" { | ||
| const url: string; | ||
| export default url; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| html { | ||
| background: var(--vscode-sideBar-background); | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| #storybook-preview-wrapper { | ||
| background-color: var(--vscode-sideBar-background); | ||
| } | ||
|
|
||
| #root { | ||
| overscroll-behavior-x: none; | ||
| background-color: var(--vscode-sideBar-background); | ||
| color: var(--vscode-editor-foreground); | ||
| font-family: var(--vscode-font-family); | ||
| font-weight: var(--vscode-font-weight); | ||
| font-size: var(--vscode-font-size); | ||
| margin: 0; | ||
| max-width: 100%; | ||
| /* arbitrary size choice for the rough VSCode sidebar size */ | ||
| width: 300px; | ||
| } | ||
|
|
||
| img, | ||
| video { | ||
| max-width: 100%; | ||
| max-height: 100%; | ||
| } | ||
|
|
||
| a, | ||
| a code { | ||
| color: var(--vscode-textLink-foreground); | ||
| } | ||
|
|
||
| p > a { | ||
| text-decoration: var(--text-link-decoration); | ||
| } | ||
|
|
||
| a:hover { | ||
| color: var(--vscode-textLink-activeForeground); | ||
| } | ||
|
|
||
| a:focus, | ||
| input:focus, | ||
| select:focus, | ||
| textarea:focus { | ||
| outline: 1px solid -webkit-focus-ring-color; | ||
| outline-offset: -1px; | ||
| } | ||
|
|
||
| code { | ||
| font-family: var(--monaco-monospace-font); | ||
| color: var(--vscode-textPreformat-foreground); | ||
| background-color: var(--vscode-textPreformat-background); | ||
| padding: 1px 3px; | ||
| border-radius: 4px; | ||
| } | ||
|
|
||
| pre code { | ||
| padding: 0; | ||
| } | ||
|
|
||
| blockquote { | ||
| background: var(--vscode-textBlockQuote-background); | ||
| border-color: var(--vscode-textBlockQuote-border); | ||
| } | ||
|
|
||
| kbd { | ||
| background-color: var(--vscode-keybindingLabel-background); | ||
| color: var(--vscode-keybindingLabel-foreground); | ||
| border-style: solid; | ||
| border-width: 1px; | ||
| border-radius: 3px; | ||
| border-color: var(--vscode-keybindingLabel-border); | ||
| border-bottom-color: var(--vscode-keybindingLabel-bottomBorder); | ||
| box-shadow: inset 0 -1px 0 var(--vscode-widget-shadow); | ||
| vertical-align: middle; | ||
| padding: 1px 3px; | ||
| } | ||
|
|
||
| ::-webkit-scrollbar { | ||
| width: 10px; | ||
| height: 10px; | ||
| } | ||
|
|
||
| ::-webkit-scrollbar-corner { | ||
| background-color: var(--vscode-editor-background); | ||
| } | ||
|
|
||
| ::-webkit-scrollbar-thumb { | ||
| background-color: var(--vscode-scrollbarSlider-background); | ||
| } | ||
| ::-webkit-scrollbar-thumb:hover { | ||
| background-color: var(--vscode-scrollbarSlider-hoverBackground); | ||
| } | ||
| ::-webkit-scrollbar-thumb:active { | ||
| background-color: var(--vscode-scrollbarSlider-activeBackground); | ||
| } | ||
| ::highlight(find-highlight) { | ||
| background-color: var(--vscode-editor-findMatchHighlightBackground); | ||
| } | ||
| ::highlight(current-find-highlight) { | ||
| background-color: var(--vscode-editor-findMatchBackground); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { mergeConfig } from "vite"; | ||
|
|
||
| import type { StorybookConfig } from "@storybook/react-vite"; | ||
|
|
||
| const config: StorybookConfig = { | ||
| stories: ["../packages/*/src/**/*.stories.@(ts|tsx)"], | ||
| addons: ["@storybook/addon-essentials", "@storybook/addon-a11y"], | ||
| framework: { | ||
| name: "@storybook/react-vite", | ||
| options: {}, | ||
| }, | ||
| viteFinal(baseConfig) { | ||
| return mergeConfig(baseConfig, { | ||
| assetsInclude: ["**/*.ttf", "**/*.woff", "**/*.woff2"], | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import codiconCssUrl from "@vscode/codicons/dist/codicon.css?url"; | ||
| import { createElement, useEffect } from "react"; | ||
|
|
||
| import "./global.css"; | ||
| import { darkTheme } from "./themes/dark-v2"; | ||
| import { lightTheme } from "./themes/light-v2"; | ||
|
|
||
| import type { Preview } from "@storybook/react"; | ||
| import type { WebviewApi } from "vscode-webview"; | ||
|
|
||
| // Mock the acquireVsCodeApi function for Storybook, so that components | ||
| // that rely on it can function without errors. | ||
| if ( | ||
| typeof window !== "undefined" && | ||
| !(window as { acquireVsCodeApi?: () => WebviewApi<unknown> }).acquireVsCodeApi | ||
| ) { | ||
| (window as { acquireVsCodeApi: () => WebviewApi<unknown> }).acquireVsCodeApi = | ||
| () => ({ | ||
| postMessage: () => undefined, | ||
| getState: () => undefined, | ||
| setState: (state) => state, | ||
| }); | ||
|
Comment on lines
+11
to
+22
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the tsconfig is slimmed (separate comment), declare global {
interface Window {
acquireVsCodeApi?: <T = unknown>() => WebviewApi<T>;
}
}
if (typeof window !== "undefined") {
window.acquireVsCodeApi ??= () => ({
postMessage: () => undefined,
getState: () => undefined,
setState: (state) => state,
});
} |
||
| } | ||
|
|
||
| // Inject codicon stylesheet immediately (before any components render) | ||
| // Must be a <link> element with id "vscode-codicon-stylesheet" for vscode-elements | ||
| if ( | ||
| typeof document !== "undefined" && | ||
| !document.getElementById("vscode-codicon-stylesheet") | ||
| ) { | ||
| const link = document.createElement("link"); | ||
| link.id = "vscode-codicon-stylesheet"; | ||
| link.rel = "stylesheet"; | ||
| link.href = codiconCssUrl; | ||
| document.head.appendChild(link); | ||
| } | ||
|
|
||
| // This allows the system viewing the storybook to use the same font | ||
| // stack as vscode, which is important for accurate rendering of text. | ||
| const getDefaultFontStack = () => { | ||
| if (navigator.userAgent.includes("Linux")) { | ||
| return 'system-ui, "Ubuntu", "Droid Sans", sans-serif'; | ||
| } else if (navigator.userAgent.includes("Mac")) { | ||
| return "-apple-system, BlinkMacSystemFont, sans-serif"; | ||
| } else if (navigator.userAgent.includes("Windows")) { | ||
| return '"Segoe WPC", "Segoe UI", sans-serif'; | ||
| } else { | ||
| return "sans-serif"; | ||
| } | ||
| }; | ||
|
|
||
| const preview: Preview = { | ||
| parameters: { | ||
| layout: "centered", | ||
| }, | ||
| globalTypes: { | ||
| theme: { | ||
| description: "Global theme for components", | ||
| defaultValue: "dark", | ||
| toolbar: { | ||
| title: "Theme", | ||
| icon: "circlehollow", | ||
| items: [ | ||
| { value: "light", icon: "circlehollow", title: "Light" }, | ||
| { value: "dark", icon: "circle", title: "Dark" }, | ||
| ], | ||
| dynamicTitle: true, | ||
| }, | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story, context) => { | ||
| const selectedTheme = | ||
| context.globals.theme === "light" ? lightTheme : darkTheme; | ||
|
|
||
| useEffect(() => { | ||
| // Apply CSS custom properties to the document root | ||
| selectedTheme.forEach(([property, value]) => { | ||
| document.documentElement.style.setProperty(property, value); | ||
| }); | ||
|
|
||
| // Cleanup function to remove properties when unmounting | ||
| return () => { | ||
| selectedTheme.forEach(([property]) => { | ||
| document.documentElement.style.removeProperty(property); | ||
| }); | ||
| }; | ||
| }, [selectedTheme]); | ||
|
|
||
| return createElement( | ||
| "div", | ||
|
jakehwll marked this conversation as resolved.
|
||
| { | ||
| id: "root", | ||
| style: { | ||
| fontFamily: getDefaultFontStack(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an issue with how this is used actually, Set it as a CSS variable instead (extend the theme arrays or call |
||
| }, | ||
| }, | ||
| createElement(Story), | ||
| ); | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default preview; | ||
Uh oh!
There was an error while loading. Please reload this page.