Skip to content

Commit 978cccf

Browse files
Chris Hassonhassoncs
authored andcommitted
refactor(storybook): centralize theme variables and remove duplication
Moves shared design system variables from `generated-theme-styles/common.css` to a new `theme-shared.css` file. This centralizes theme-agnostic variables and removes duplication across generated theme files. The `theme-variables.css` file is updated to only contain semantic color mappings and Tailwind delegations, removing layout and sizing variables that are now in `theme-shared.css`. The theme generation script is also updated to only output base theme colors, simplifying the generated CSS.
1 parent b1e2329 commit 978cccf

File tree

6 files changed

+470
-710
lines changed

6 files changed

+470
-710
lines changed

apps/storybook/.storybook/design-system.css

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 174 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
1-
/* We have to redefine these color variables in order to allow dynamic
2-
theme switching in Storybook due to the way tailwind builds its utility
1+
/* Theme Variables - Color delegations and semantic mappings */
2+
3+
/* We have to redefine these color variables in order to allow dynamic
4+
theme switching in Storybook due to the way tailwind builds its utility
35
classes at build time based on the @theme */
46

5-
/* @layer base :root */
7+
/* Non-prefixed variable delegations - point to VS Code variables */
8+
--background: var(--vscode-background);
9+
--foreground: var(--vscode-foreground);
10+
--editor-foreground: var(--vscode-editor-foreground);
11+
--editor-background: var(--vscode-editor-background);
12+
--editorGroup-border: var(--vscode-editorGroup-border);
13+
--editorWarning-foreground: var(--vscode-editorWarning-foreground);
14+
--editorWarning-background: var(--vscode-editorWarning-background);
15+
--button-foreground: var(--vscode-button-foreground);
16+
--button-background: var(--vscode-button-background);
17+
--button-secondaryForeground: var(--vscode-button-secondaryForeground);
18+
--button-secondaryBackground: var(--vscode-button-secondaryBackground);
19+
--button-hoverBackground: var(--vscode-button-hoverBackground);
20+
--button-secondaryHoverBackground: var(--vscode-button-secondaryHoverBackground);
21+
--dropdown-foreground: var(--vscode-dropdown-foreground);
22+
--dropdown-background: var(--vscode-dropdown-background);
23+
--dropdown-border: var(--vscode-dropdown-border);
24+
--input-foreground: var(--vscode-input-foreground);
25+
--input-background: var(--vscode-input-background);
26+
--input-border: var(--vscode-input-border);
27+
--focusBorder: var(--vscode-focusBorder);
28+
--badge-foreground: var(--vscode-badge-foreground);
29+
--badge-background: var(--vscode-badge-background);
30+
--notifications-foreground: var(--vscode-notifications-foreground);
31+
--notifications-background: var(--vscode-notifications-background);
32+
--notifications-border: var(--vscode-notifications-border);
33+
--descriptionForeground: var(--vscode-descriptionForeground);
34+
--errorForeground: var(--vscode-errorForeground);
35+
--list-hoverForeground: var(--vscode-list-hoverForeground);
36+
--list-hoverBackground: var(--vscode-list-hoverBackground);
37+
--list-focusBackground: var(--vscode-list-focusBackground);
38+
--list-activeSelectionBackground: var(--vscode-list-activeSelectionBackground);
39+
--list-activeSelectionForeground: var(--vscode-list-activeSelectionForeground);
40+
--toolbar-hoverBackground: var(--vscode-toolbar-hoverBackground);
41+
--panel-border: var(--vscode-panel-border);
42+
--sideBar-foreground: var(--vscode-sideBar-foreground);
43+
--sideBar-background: var(--vscode-sideBar-background);
44+
--sideBar-border: var(--vscode-sideBar-border);
45+
--sideBarSectionHeader-foreground: var(--vscode-sideBarSectionHeader-foreground);
46+
--sideBarSectionHeader-background: var(--vscode-sideBarSectionHeader-background);
47+
--sideBarSectionHeader-border: var(--vscode-sideBarSectionHeader-border);
48+
--charts-green: var(--vscode-charts-green);
49+
--charts-yellow: var(--vscode-charts-yellow);
50+
--charts-red: var(--vscode-charts-red);
51+
--charts-blue: var(--vscode-charts-blue);
52+
--charts-orange: var(--vscode-charts-orange);
53+
--inputValidation-infoForeground: var(--vscode-inputValidation-infoForeground);
54+
--inputValidation-infoBackground: var(--vscode-inputValidation-infoBackground);
55+
--inputValidation-infoBorder: var(--vscode-inputValidation-infoBorder);
56+
--widget-border: var(--vscode-widget-border);
57+
--textLink-foreground: var(--vscode-textLink-foreground);
58+
--textCodeBlock-background: var(--vscode-textCodeBlock-background);
59+
--menu-background: var(--vscode-menu-background);
60+
--menu-foreground: var(--vscode-menu-foreground);
61+
--disabledForeground: var(--vscode-disabledForeground);
62+
--checkbox-background: var(--vscode-checkbox-background);
63+
--checkbox-foreground: var(--vscode-checkbox-foreground);
64+
--checkbox-border: var(--vscode-checkbox-border);
65+
66+
/* Semantic color mappings to VSCode variables */
667
--background: var(--vscode-editor-background);
768
--foreground: var(--vscode-editor-foreground);
869
--card: var(--vscode-editor-background);
@@ -19,24 +80,61 @@ classes at build time based on the @theme */
1980
--accent-foreground: var(--vscode-list-hoverForeground);
2081
--destructive: var(--vscode-errorForeground);
2182
--destructive-foreground: var(--vscode-button-foreground);
22-
--border: var(--vscode-input-border, transparent); /* --border gets theme value or transparent fallback */
83+
--border: var(--vscode-input-border, transparent);
2384
--input: var(--vscode-input-background);
2485
--ring: var(--vscode-input-border);
2586
--chart-1: var(--vscode-charts-red);
2687
--chart-2: var(--vscode-charts-blue);
2788
--chart-3: var(--vscode-charts-yellow);
2889
--chart-4: var(--vscode-charts-orange);
2990
--chart-5: var(--vscode-charts-green);
30-
--radius: 0.5rem;
3191

32-
/* @layer base :root */
33-
--font-display: var(--vscode-font-family);
92+
/* Layout and Sizing Variables (theme-agnostic) */
93+
--border-width: 1;
94+
--corner-radius: 0;
95+
--corner-radius-round: 2;
96+
--design-unit: 4;
97+
--disabled-opacity: 0.4;
98+
--font-family:
99+
-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji,
100+
Segoe UI Emoji, Segoe UI Symbol;
101+
--font-weight: 400;
102+
--input-height: 26;
103+
--input-min-width: 100px;
104+
--type-ramp-base-font-size: 13px;
105+
--type-ramp-base-line-height: normal;
106+
--type-ramp-minus1-font-size: 11px;
107+
--type-ramp-minus1-line-height: 16px;
108+
--type-ramp-minus2-font-size: 9px;
109+
--type-ramp-minus2-line-height: 16px;
110+
--type-ramp-plus1-font-size: 16px;
111+
--type-ramp-plus1-line-height: 24px;
112+
--scrollbarWidth: 10px;
113+
--scrollbarHeight: 10px;
114+
115+
/* Component Layout Variables (theme-agnostic) */
116+
--button-icon-corner-radius: 5px;
117+
--button-icon-outline-offset: 0;
118+
--button-icon-padding: 3px;
119+
--button-padding-horizontal: 11px;
120+
--button-padding-vertical: 4px;
121+
--checkbox-corner-radius: 3;
122+
--dropdown-list-max-height: 200px;
123+
--tag-corner-radius: 2px;
34124

35125
--text-xs: calc(var(--vscode-font-size) * 0.85);
36126
--text-sm: calc(var(--vscode-font-size) * 0.9);
37127
--text-base: var(--vscode-font-size);
38128
--text-lg: calc(var(--vscode-font-size) * 1.1);
39129

130+
/* Border radius variables */
131+
--radius: 0.5rem;
132+
--radius-lg: var(--radius);
133+
--radius-md: calc(var(--radius) - 2px);
134+
--radius-sm: calc(var(--radius) - 4px);
135+
136+
137+
/* Tailwind color delegations for semantic colors */
40138
--color-background: var(--background);
41139
--color-foreground: var(--foreground);
42140
--color-card: var(--card);
@@ -61,80 +159,119 @@ classes at build time based on the @theme */
61159
--color-chart-3: var(--chart-3);
62160
--color-chart-4: var(--chart-4);
63161
--color-chart-5: var(--chart-5);
64-
--radius-lg: var(--radius);
65-
--radius-md: calc(var(--radius) - 2px);
66-
--radius-sm: calc(var(--radius) - 4px);
67-
68-
/**
69-
* Allow VSCode colors to be used with Tailwind.
70-
*/
71162

163+
/* Tailwind color delegations for VS Code variables */
164+
--color-vscode-background: var(--vscode-background);
72165
--color-vscode-foreground: var(--vscode-foreground);
73-
74166
--color-vscode-editor-foreground: var(--vscode-editor-foreground);
75167
--color-vscode-editor-background: var(--vscode-editor-background);
76-
77168
--color-vscode-editorGroup-border: var(--vscode-editorGroup-border);
78-
79169
--color-vscode-editorWarning-foreground: var(--vscode-editorWarning-foreground);
80170
--color-vscode-editorWarning-background: var(--vscode-editorWarning-background);
81-
82171
--color-vscode-button-foreground: var(--vscode-button-foreground);
83172
--color-vscode-button-background: var(--vscode-button-background);
84173
--color-vscode-button-secondaryForeground: var(--vscode-button-secondaryForeground);
85174
--color-vscode-button-secondaryBackground: var(--vscode-button-secondaryBackground);
86175
--color-vscode-button-hoverBackground: var(--vscode-button-hoverBackground);
87176
--color-vscode-button-secondaryHoverBackground: var(--vscode-button-secondaryHoverBackground);
88-
89177
--color-vscode-dropdown-foreground: var(--vscode-dropdown-foreground);
90178
--color-vscode-dropdown-background: var(--vscode-dropdown-background);
91179
--color-vscode-dropdown-border: var(--vscode-dropdown-border);
92-
93180
--color-vscode-input-foreground: var(--vscode-input-foreground);
94181
--color-vscode-input-background: var(--vscode-input-background);
95-
--color-vscode-input-border: var(
96-
--vscode-input-border,
97-
transparent
98-
); /* Some themes don't have a border color, so we can fallback to transparent */
99-
182+
--color-vscode-input-border: var(--vscode-input-border, transparent);
100183
--color-vscode-focusBorder: var(--vscode-focusBorder);
101-
102184
--color-vscode-badge-foreground: var(--vscode-badge-foreground);
103185
--color-vscode-badge-background: var(--vscode-badge-background);
104-
105186
--color-vscode-notifications-foreground: var(--vscode-notifications-foreground);
106187
--color-vscode-notifications-background: var(--vscode-notifications-background);
107188
--color-vscode-notifications-border: var(--vscode-notifications-border);
108-
109189
--color-vscode-descriptionForeground: var(--vscode-descriptionForeground);
110190
--color-vscode-errorForeground: var(--vscode-errorForeground);
111-
112191
--color-vscode-list-hoverForeground: var(--vscode-list-hoverForeground);
113192
--color-vscode-list-hoverBackground: var(--vscode-list-hoverBackground);
114193
--color-vscode-list-focusBackground: var(--vscode-list-focusBackground);
115194
--color-vscode-list-activeSelectionBackground: var(--vscode-list-activeSelectionBackground);
116195
--color-vscode-list-activeSelectionForeground: var(--vscode-list-activeSelectionForeground);
117-
118196
--color-vscode-toolbar-hoverBackground: var(--vscode-toolbar-hoverBackground);
119-
120197
--color-vscode-panel-border: var(--vscode-panel-border);
121-
122198
--color-vscode-sideBar-foreground: var(--vscode-sideBar-foreground);
123199
--color-vscode-sideBar-background: var(--vscode-sideBar-background);
124200
--color-vscode-sideBar-border: var(--vscode-sideBar-border);
125-
126201
--color-vscode-sideBarSectionHeader-foreground: var(--vscode-sideBarSectionHeader-foreground);
127202
--color-vscode-sideBarSectionHeader-background: var(--vscode-sideBarSectionHeader-background);
128203
--color-vscode-sideBarSectionHeader-border: var(--vscode-sideBarSectionHeader-border);
129-
130204
--color-vscode-charts-green: var(--vscode-charts-green);
131205
--color-vscode-charts-yellow: var(--vscode-charts-yellow);
132-
206+
--color-vscode-charts-red: var(--vscode-charts-red);
207+
--color-vscode-charts-blue: var(--vscode-charts-blue);
208+
--color-vscode-charts-orange: var(--vscode-charts-orange);
133209
--color-vscode-inputValidation-infoForeground: var(--vscode-inputValidation-infoForeground);
134210
--color-vscode-inputValidation-infoBackground: var(--vscode-inputValidation-infoBackground);
135211
--color-vscode-inputValidation-infoBorder: var(--vscode-inputValidation-infoBorder);
136-
137212
--color-vscode-widget-border: var(--vscode-widget-border);
138213
--color-vscode-textLink-foreground: var(--vscode-textLink-foreground);
139214
--color-vscode-textCodeBlock-background: var(--vscode-textCodeBlock-background);
140-
--color-vscode-button-hoverBackground: var(--vscode-button-hoverBackground);
215+
--color-vscode-menu-background: var(--vscode-menu-background);
216+
--color-vscode-menu-foreground: var(--vscode-menu-foreground);
217+
--color-vscode-disabledForeground: var(--vscode-disabledForeground);
218+
--color-vscode-checkbox-background: var(--vscode-checkbox-background);
219+
220+
/* Additional Tailwind color delegations for UI components */
221+
--color-vscode-border-width: var(--vscode-border-width);
222+
--color-vscode-contrast-active-border: var(--vscode-contrast-active-border);
223+
--color-vscode-contrast-border: var(--vscode-contrast-border);
224+
--color-vscode-corner-radius: var(--vscode-corner-radius);
225+
--color-vscode-corner-radius-round: var(--vscode-corner-radius-round);
226+
--color-vscode-design-unit: var(--vscode-design-unit);
227+
--color-vscode-disabled-opacity: var(--vscode-disabled-opacity);
228+
--color-vscode-focus-border: var(--vscode-focus-border);
229+
--color-vscode-font-family: var(--vscode-font-family);
230+
--color-vscode-font-weight: var(--vscode-font-weight);
231+
--color-vscode-input-height: var(--vscode-input-height);
232+
--color-vscode-input-min-width: var(--vscode-input-min-width);
233+
--color-vscode-type-ramp-base-font-size: var(--vscode-type-ramp-base-font-size);
234+
--color-vscode-type-ramp-base-line-height: var(--vscode-type-ramp-base-line-height);
235+
--color-vscode-type-ramp-minus1-font-size: var(--vscode-type-ramp-minus1-font-size);
236+
--color-vscode-type-ramp-minus1-line-height: var(--vscode-type-ramp-minus1-line-height);
237+
--color-vscode-type-ramp-minus2-font-size: var(--vscode-type-ramp-minus2-font-size);
238+
--color-vscode-type-ramp-minus2-line-height: var(--vscode-type-ramp-minus2-line-height);
239+
--color-vscode-type-ramp-plus1-font-size: var(--vscode-type-ramp-plus1-font-size);
240+
--color-vscode-type-ramp-plus1-line-height: var(--vscode-type-ramp-plus1-line-height);
241+
--color-vscode-scrollbarWidth: var(--vscode-scrollbarWidth);
242+
--color-vscode-scrollbarHeight: var(--vscode-scrollbarHeight);
243+
--color-vscode-scrollbar-slider-background: var(--vscode-scrollbar-slider-background);
244+
--color-vscode-scrollbar-slider-hover-background: var(--vscode-scrollbar-slider-hover-background);
245+
--color-vscode-scrollbar-slider-active-background: var(--vscode-scrollbar-slider-active-background);
246+
--color-vscode-button-border: var(--vscode-button-border);
247+
--color-vscode-button-icon-background: var(--vscode-button-icon-background);
248+
--color-vscode-button-icon-corner-radius: var(--vscode-button-icon-corner-radius);
249+
--color-vscode-button-icon-outline-offset: var(--vscode-button-icon-outline-offset);
250+
--color-vscode-button-icon-hover-background: var(--vscode-button-icon-hover-background);
251+
--color-vscode-button-icon-padding: var(--vscode-button-icon-padding);
252+
--color-vscode-button-primary-background: var(--vscode-button-primary-background);
253+
--color-vscode-button-primary-foreground: var(--vscode-button-primary-foreground);
254+
--color-vscode-button-primary-hover-background: var(--vscode-button-primary-hover-background);
255+
--color-vscode-button-secondary-background: var(--vscode-button-secondary-background);
256+
--color-vscode-button-secondary-foreground: var(--vscode-button-secondary-foreground);
257+
--color-vscode-button-secondary-hover-background: var(--vscode-button-secondary-hover-background);
258+
--color-vscode-button-padding-horizontal: var(--vscode-button-padding-horizontal);
259+
--color-vscode-button-padding-vertical: var(--vscode-button-padding-vertical);
260+
--color-vscode-checkbox-border: var(--vscode-checkbox-border);
261+
--color-vscode-checkbox-corner-radius: var(--vscode-checkbox-corner-radius);
262+
--color-vscode-checkbox-foreground: var(--vscode-checkbox-foreground);
263+
--color-vscode-list-active-selection-background: var(--vscode-list-active-selection-background);
264+
--color-vscode-list-active-selection-foreground: var(--vscode-list-active-selection-foreground);
265+
--color-vscode-list-hover-background: var(--vscode-list-hover-background);
266+
--color-vscode-divider-background: var(--vscode-divider-background);
267+
--color-vscode-dropdown-list-max-height: var(--vscode-dropdown-list-max-height);
268+
--color-vscode-input-placeholder-foreground: var(--vscode-input-placeholder-foreground);
269+
--color-vscode-link-active-foreground: var(--vscode-link-active-foreground);
270+
--color-vscode-link-foreground: var(--vscode-link-foreground);
271+
--color-vscode-progress-background: var(--vscode-progress-background);
272+
--color-vscode-panel-tab-active-border: var(--vscode-panel-tab-active-border);
273+
--color-vscode-panel-tab-active-foreground: var(--vscode-panel-tab-active-foreground);
274+
--color-vscode-panel-tab-foreground: var(--vscode-panel-tab-foreground);
275+
--color-vscode-panel-view-background: var(--vscode-panel-view-background);
276+
--color-vscode-panel-view-border: var(--vscode-panel-view-border);
277+
--color-vscode-tag-corner-radius: var(--vscode-tag-corner-radius);

apps/storybook/generated-theme-styles/common.css

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

0 commit comments

Comments
 (0)