feat(css): expose primitive and semantic color tokens as CSS variables#5
Open
nacal wants to merge 1 commit into
Open
feat(css): expose primitive and semantic color tokens as CSS variables#5nacal wants to merge 1 commit into
nacal wants to merge 1 commit into
Conversation
Adds src/_tokens.scss which emits a :root block of --wip-color-primitive-* and --wip-color-semantic-* custom properties via the flavor-aware adapter. Consumers can now reference design-system colors directly from their own CSS (e.g. var(--wip-color-semantic-neutral-100)) instead of hardcoding hex values. The existing scopeRoot pipeline in scripts/build-flavor-css.mjs rescopes the :root block per flavor in the combined dist/styles.css. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
src/_tokens.scssを追加し、@pepabo-inhouse/adapter経由でプリミティブ・セマンティックカラーを:root { --wip-color-* }として公開src/_all.scssの先頭で@use './tokens';を読み込み、既存のフレーバービルドに乗せるsrc/docs/Color.mdxに「CSS 変数として参照する」セクションを追加これにより、wip-ui を消費する側のアプリケーションでも
var(--wip-color-semantic-neutral-100)のようにデザイントークンを直接参照できるようになり、#f4f4f5などのハードコードが不要になります。仕組み
_tokens.scssはadapter.get-primitive-color()/adapter.get-semantic-color()を呼び、scripts/build-flavor-css.mjsのflavorImporterがフレーバーごとに値を解決します。prefixPlugin:dist/css/{flavor}.css)::rootのままドキュメントレベルに残すdist/styles.css)::root→[data-flavor="xxx"]に書き換え、last-flavor-wins を回避<FlavorProvider>を使わない consumer でもvar(--wip-color-*)は pepper 値で解決されます。動作確認
dist/styles.cssの--wip-color-semantic-neutral-100をフレーバーごとに抽出:#edeef0#f5f5f5#d9dce9#f2f6f7#ededed#edeef0#dddfeanpm run lint(typecheck + biome): 通過dist/styles.css内に:root { ... }は 1 つだけ(pepper baseline)、残りは[data-flavor="..."]でスコープ済みであることを確認議論ポイント
--wip-color-primitive-gray-100/--wip-color-semantic-neutral-100の階層型を採用。理由は JS API (colors.primitive.gray,colors.semantic.neutral) や inhouse のトークン分類と一致するため。フラット (--wip-color-gray-100) のほうがよければご指摘ください。Test plan
npm run build:flavorsでビルドエラーなし、警告なしdist/css/{flavor}.css各ファイル内の:root { --wip-color-* }の値がフレーバーごとに異なるdist/styles.css内で[data-flavor="xxx"] { --wip-color-* }にスコープされているnpm run storybook) で Foundations/Colors のドキュメントが正しく表示されるvar(--wip-color-semantic-neutral-100)を参照して値が解決される🤖 Generated with Claude Code