Add @octopusdeploy/design-system-tokens as CSS custom properties - #3257
Closed
enf0rc3 wants to merge 1 commit into
Closed
Add @octopusdeploy/design-system-tokens as CSS custom properties#3257enf0rc3 wants to merge 1 commit into
enf0rc3 wants to merge 1 commit into
Conversation
The tokens package ships no CSS of its own: its ergonomic exports (themeTokens, text, fontFamily) resolve to `var(--name)` strings, and lightTheme/darkTheme/textTheme are the matching name -> value maps a consumer is expected to paint into a :root block. In the Octopus app that job belongs to the Theme component in @octopusdeploy/design-system-components, which is not a dependency here and would pull in a React + Emotion runtime this docs site has no other use for. Instead, a build-time generator emits the same custom properties as a static stylesheet, matching how this repo already does CSS (hand-written files in public/docs/css linked from HtmlHead, no Tailwind or SCSS): - src/themes/octopus/utilities/design-tokens.mjs generates public/docs/css/design-tokens.css (48KB raw, 7KB gzipped) - 564 properties: 489 light colors/shadows, 24 typography composites, 51 theme-invariant scales, plus 413 dark overrides - Dark overrides use html[data-theme='dark'], the selector vars.css already uses, so both stylesheets switch off the existing toggle - Loaded before vars.css, so existing site variables stay authoritative and this change is visually a no-op - Names match the package's TS API, so themeTokens.color.text.primary translates directly to var(--colorTextPrimary) Wired into `dev` and a `prebuild` step so the file cannot drift from the installed package version. Excluded from prettier via .prettierignore, since dev:watch globs public/docs/css and would otherwise fight the generator on every dev run. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Pull request environment is available at https://stoctodocspr3257.z22.web.core.windows.net. You can view the ephemeral environment status in Octopus Deploy. This environment will be automatically deprovisioned when the pull request is closed, or after 7 days of inactivity. |
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.
Adds
@octopusdeploy/design-system-tokensto the docs site so colour, spacing, and typography values can come from the design system instead of being hand-picked.Why not just import the tokens
The package ships no CSS. Its entry point is CommonJS, and the ergonomic exports resolve to CSS variable references, not values:
The actual values live in
lightTheme/darkTheme/textThemeas flat name → value maps that a consumer is expected to paint into a:rootblock. In the Octopus app that job belongs to theThemecomponent in@octopusdeploy/design-system-components— not a dependency here, and adding it would pull in a React + Emotion runtime this docs site has no other use for.Without something emitting that block, importing a theme token yields
var(--colorTextPrimary)against an undefined variable and silently falls back to inherited/initial.Approach
A build-time generator emits the same custom properties as a static stylesheet. This matches how CSS already works in this repo — hand-written files in
public/docs/csslinked fromHtmlHead.astro, no Tailwind, no SCSS, no CSS-in-JS — rather than introducing a new pattern.src/themes/octopus/utilities/design-tokens.mjs→ generatespublic/docs/css/design-tokens.csshtml[data-theme='dark']— the selectorvars.cssalready uses, so both stylesheets switch off the existing togglevars.css, so existing site variables stay authoritativeNames match the package's TS API exactly, so
themeTokens.color.text.primary→var(--colorTextPrimary). App-side code and the package's own guidance translate directly.Usage
Plain CSS in any
.astrofile or<style>block, no imports:Verification
astro buildpasses — 2,696 pages, exit 0design-tokens.csscopied todist/docs/css/;<link>renders in the correct position in built HTMLvars.cssvariables (generated names are camelCase, existing ones kebab-case)vars.cssuntouched — this change is visually a no-opNotes for reviewers
.prettierignoreis load-bearing.dev:watchandformatboth globpublic/docs/css/**/*.css; without the exclusion prettier and the generator rewrite each other on every dev run.space,borderRadius, etc. as plain literals rather thanvar()references, so it defines no custom property names for them.--space-16/--borderRadius-mediumfollow the package's camelCase style for consistency.colorScalesanddialogare intentionally omitted. The package's own skill doc says raw scales are not theme-aware and should not be used in feature code; the theme tokens already resolve to those hex values.--colorButtonTextPrimary,--colorBadgeBackgroundInfo, …). The package scopes those to design-system components, which this repo does not have, so they are present but inert. Cheap at 7KB gzipped. The sanctioned set for use here is--colorText*/--colorBackground*/--colorBorder*/--shadow*.testrunsastro builddirectly and so bypassesprebuild. Harmless because the generated file is committed.Follow-up (not in this PR)
The
/* TODO - update with design system */markers atvars.css:133andvars.css:137are now actionable — those variables can be repointed at generated tokens.🤖 Generated with Claude Code