feat(ui): scaffold packages/ui with theme foundations#1030
Open
EhabY wants to merge 4 commits into
Open
Conversation
Source all VS Code themes (light, dark, hc-dark, hc-light) from @vscode-elements/webview-playground instead of maintaining local copies, and add per-theme Chromatic snapshot modes. Also drops the sideEffects field that broke CSS tree-shaking, and fixes the Foundations story's token value column inheriting an unrelated --vscode-textPreformat-background instead of the row's own background, which made values unreadable in both high-contrast themes.
086eaf9 to
b9d3bea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes DEVEX-624.
Scaffolds the shared component library for the Workspaces webview work. Foundations only — no components yet (DEVEX-618/619/620 build on this).
packages/ui— React + TS package wired like existing packages (catalog deps, root Storybook/ESLint/typecheck globs pick it up automatically). Consumed as source likewebview-shared, but shaped for a future standalone NPM split: properexportsmap (.,./tokens.css,./codicon.css),reactas the only peer dependency,@vscode/codicons(asset-only) as the only runtime dependency, noworkspace:*runtime deps. A short README documents the theming model and the rules that keep the package splittable.tokens.css— semantic--ui-*tokens mapped to--vscode-*variables; the single place the library is theme-matched to VS Code. Same pattern as Microsoft's Webview UI Toolkit design-token layer, but pure CSS: components style against a small curated semantic set instead of scattering raw--vscode-*references (VS Code exposes 500+). Every token always resolves: variables VS Code may omit (hover/selection fills in high contrast themes,contrastBorder/contrastActiveBorderoutside them) declare fallbacks, matching native behavior where contrast borders replace fills.useVscodeTheme— the issue asked to move it fromwebview-shared, but no such hook existed anywhere in the repo, so it is implemented here instead: returns the active theme kind from thedata-vscode-theme-kindbody attribute VS Code maintains in webviews, synced viaMutationObserver+useSyncExternalStore. No re-export fromwebview-sharedsince there are no consumers yet.data-vscode-theme-kindon the body so theme-aware hooks behave as in real webviews. Theme data is no longer vendored: the two existing ~700-line theme files are deleted and all four themes import from@vscode-elements/webview-playground(the package the vendored data was originally copied from), pinned via the catalog. Net: this PR removes ~1,500 lines from the repo.UI/Foundationsstory — enumerates every--ui-*token from the loaded stylesheets (cannot drift fromtokens.css) and renders each as a swatch on a checkerboard with its resolved value, plus the live theme kind via the hook. Chromatic modes snapshot this story in all four themes (scoped to this story to keep snapshot counts down).Testing
test/webview/ui/useVscodeTheme.test.ts— theme-kind mapping, missing-attribute default, re-render on theme change.--ui-active-selection-foregroundis#000000/#ffffffin light/dark — VS Code really does snap selected-row text to full contrast) and fallbacks engage where variables are absent (HC dark omits selection fills; contrast borders take over).pnpm typecheck,pnpm lint,pnpm format:check,pnpm test,pnpm build,pnpm storybook:ciall pass.Implementation plan & decisions
Context
packages/{shared,webview-shared,tasks,workspaces,netcheck,speedtest,mocks,storybook-utils}with pnpmcatalog:deps (catalogMode: strict)..storybookglobspackages/*/src/**/*.stories.@(ts|tsx)— apackages/uistory is picked up with zero config.typecheck:packages/build:webviewsrunpnpm -r --filter ./packages/*— packages without abuildscript are skipped (e.g.webview-shared, consumed as source via itsexportsmap).Finding:
useVscodeThemedid not existThe issue says "move
useVscodeThemefrompackages/webview-shared", but no such hook exists on main or any branch. Decision: implement it fresh inpackages/ui(DOMdata-vscode-theme-kind+MutationObserverviauseSyncExternalStore).Decisions
webview-shared(no vite build), but kept easy to separate later — self-contained package, properexportsmap,reactpeer dep, noworkspace:*deps. A real build step only becomes necessary at the actual NPM split../codicon.cssre-exporting@vscode/codicons) since follow-up issues will use it.--vscode-*per component, as vscode-elements does): the deprecated@vscode/webview-ui-toolkitvalidated the token-layer pattern but implemented it with a JS design-token system; a pure-CSS layer gets the same single theming point without the machinery, and gives the future standalone package one place to define non-webview fallbacks.sideEffectsfield: it was tried for NPM-split readiness, but this Vite/rolldown pipeline then tree-shook thestorybook.preview.ts→tokens.csschain out of the production Storybook build (even with**/*.cssdeclared). Dev mode masked it. Dropped as speculative; revisit at the actual split on a pipeline that honors it.@vscode-elements/webview-playgroundpublishes the exact theme modules the repo had copied by hand. Importing them (untyped ESM, typed via a small wildcard.d.ts) deletes ~2,800 vendored lines across four themes and makes theme refreshes apnpm update.Deliverables
packages/ui/{package.json,tsconfig.json,storybook.preview.ts,README.md}+src/{index.ts,tokens.css,codicon.css,useVscodeTheme.ts,foundations.stories.tsx,css.d.ts}@repo/uialiases invitest.config.ts(webview project) andtest/tsconfig.jsonwebview-playground, body-attribute mirroring, per-theme Chromatic modes on the foundations storytest/webview/ui/