Skip to content

Commit 1df5daf

Browse files
committed
feat(storybook): sync webview themes and default styles from real VS Code
1 parent 73198af commit 1df5daf

14 files changed

Lines changed: 4157 additions & 191 deletions

.storybook/global.css

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* Storybook-specific layout. VS Code's default webview stylesheet is
2+
imported from ./themes/generated/default-styles.css. */
3+
14
html {
25
background: var(--vscode-sideBar-background);
36
}
@@ -24,85 +27,3 @@ body {
2427
/* arbitrary size choice for the rough VSCode sidebar size */
2528
width: 300px;
2629
}
27-
28-
img,
29-
video {
30-
max-width: 100%;
31-
max-height: 100%;
32-
}
33-
34-
a,
35-
a code {
36-
color: var(--vscode-textLink-foreground);
37-
}
38-
39-
p > a {
40-
text-decoration: var(--text-link-decoration);
41-
}
42-
43-
a:hover {
44-
color: var(--vscode-textLink-activeForeground);
45-
}
46-
47-
a:focus,
48-
input:focus,
49-
select:focus,
50-
textarea:focus {
51-
outline: 1px solid -webkit-focus-ring-color;
52-
outline-offset: -1px;
53-
}
54-
55-
code {
56-
font-family: var(--monaco-monospace-font);
57-
color: var(--vscode-textPreformat-foreground);
58-
background-color: var(--vscode-textPreformat-background);
59-
padding: 1px 3px;
60-
border-radius: 4px;
61-
}
62-
63-
pre code {
64-
padding: 0;
65-
}
66-
67-
blockquote {
68-
background: var(--vscode-textBlockQuote-background);
69-
border-color: var(--vscode-textBlockQuote-border);
70-
}
71-
72-
kbd {
73-
background-color: var(--vscode-keybindingLabel-background);
74-
color: var(--vscode-keybindingLabel-foreground);
75-
border-style: solid;
76-
border-width: 1px;
77-
border-radius: 3px;
78-
border-color: var(--vscode-keybindingLabel-border);
79-
border-bottom-color: var(--vscode-keybindingLabel-bottomBorder);
80-
box-shadow: inset 0 -1px 0 var(--vscode-widget-shadow);
81-
vertical-align: middle;
82-
padding: 1px 3px;
83-
}
84-
85-
::-webkit-scrollbar {
86-
width: 10px;
87-
height: 10px;
88-
}
89-
90-
::-webkit-scrollbar-corner {
91-
background-color: var(--vscode-editor-background);
92-
}
93-
94-
::-webkit-scrollbar-thumb {
95-
background-color: var(--vscode-scrollbarSlider-background);
96-
}
97-
::-webkit-scrollbar-thumb:hover {
98-
background-color: var(--vscode-scrollbarSlider-hoverBackground);
99-
}
100-
::-webkit-scrollbar-thumb:active {
101-
background-color: var(--vscode-scrollbarSlider-activeBackground);
102-
}
103-
::highlight(find-highlight) {
104-
background-color: var(--vscode-editor-findMatchHighlightBackground);
105-
}
106-
::highlight(current-find-highlight) {
107-
background-color: var(--vscode-editor-findMatchBackground);
108-
}

.storybook/playground-themes.d.ts

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

.storybook/preview.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/// <reference types="vite/client" />
22

33
import codiconCssUrl from "@vscode/codicons/dist/codicon.css?url";
4-
import { theme as darkTheme } from "@vscode-elements/webview-playground/dist/themes/dark-v2.js";
5-
import { theme as hcDarkTheme } from "@vscode-elements/webview-playground/dist/themes/hc-dark.js";
6-
import { theme as hcLightTheme } from "@vscode-elements/webview-playground/dist/themes/hc-light.js";
7-
import { theme as lightTheme } from "@vscode-elements/webview-playground/dist/themes/light-v2.js";
84
import { createElement, useEffect } from "react";
95

106
import "./global.css";
7+
import darkTheme from "./themes/generated/dark.json";
8+
import "./themes/generated/default-styles.css";
9+
import hcLightTheme from "./themes/generated/high-contrast-light.json";
10+
import hcDarkTheme from "./themes/generated/high-contrast.json";
11+
import lightTheme from "./themes/generated/light.json";
1112

1213
import type { Preview } from "@storybook/react-vite";
1314
import type { WebviewApi } from "vscode-webview";
@@ -44,22 +45,17 @@ if (
4445
document.head.appendChild(link);
4546
}
4647

47-
// VS Code injects --vscode-font-family at runtime, but the upstream
48-
// vscode-elements theme data omits it. Set a static default so
49-
// Storybook (and Chromatic) renders with a predictable sans-serif
50-
// stack instead of falling back to the browser default (Times).
51-
const VSCODE_FONT_FAMILY =
52-
'"Segoe WPC", "Segoe UI", system-ui, "Ubuntu", "Droid Sans", sans-serif';
53-
54-
const THEMES: Record<
55-
string,
56-
{ variables: Array<[string, string]>; kind: string }
57-
> = {
58-
light: { variables: lightTheme, kind: "vscode-light" },
59-
dark: { variables: darkTheme, kind: "vscode-dark" },
60-
"high-contrast": { variables: hcDarkTheme, kind: "vscode-high-contrast" },
48+
// Theme variable dumps captured from a real VS Code instance.
49+
// Regenerate with `pnpm sync:vscode-themes`.
50+
const THEMES: Record<string, { variables: string[][]; kind: string }> = {
51+
light: { variables: lightTheme.variables, kind: "vscode-light" },
52+
dark: { variables: darkTheme.variables, kind: "vscode-dark" },
53+
"high-contrast": {
54+
variables: hcDarkTheme.variables,
55+
kind: "vscode-high-contrast",
56+
},
6157
"high-contrast-light": {
62-
variables: hcLightTheme,
58+
variables: hcLightTheme.variables,
6359
kind: "vscode-high-contrast-light",
6460
},
6561
};
@@ -100,7 +96,6 @@ const preview: Preview = {
10096

10197
useEffect(() => {
10298
const root = document.documentElement.style;
103-
root.setProperty("--vscode-font-family", VSCODE_FONT_FAMILY);
10499

105100
// Mirror VS Code's body attribute so theme-aware hooks work in Storybook.
106101
document.body.setAttribute("data-vscode-theme-kind", kind);
@@ -115,7 +110,6 @@ const preview: Preview = {
115110
variables.forEach(([property]) => {
116111
root.removeProperty(property);
117112
});
118-
root.removeProperty("--vscode-font-family");
119113
document.body.removeAttribute("data-vscode-theme-kind");
120114
};
121115
}, [variables, kind]);

0 commit comments

Comments
 (0)