Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(tokens): split domainTokens into sub-modules + add data viz tokens (#1185)

Cindy Zhangedea462a9d88
diff --git a/packages/core/src/CodeBlock/highlightStyles.ts b/packages/core/src/CodeBlock/highlightStyles.ts
index bab9c5b552..c27893e717 100644
--- a/packages/core/src/CodeBlock/highlightStyles.ts
+++ b/packages/core/src/CodeBlock/highlightStyles.ts
@@ -5,7 +5,7 @@
* @position Shared utility; consumed by XDSCodeBlock and XDSCodeEditor
*
* SYNC: When modified, update:
- * - /packages/core/src/theme/domainTokens.ts (syntax color token names/defaults)
+ * - /packages/core/src/theme/domainTokens/syntaxTokens.ts (syntax color token names/defaults)
*/
import {syntaxTokenDefaults} from '../theme';
diff --git a/packages/core/src/theme/domainTokens.ts b/packages/core/src/theme/domainTokens.ts
deleted file mode 100644
index da11e3e7c3..0000000000
--- a/packages/core/src/theme/domainTokens.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * @file domainTokens.ts
- * @input None (pure token definitions)
- * @output Exports domain token defaults and types for syntax, dataviz, etc.
- * @position Token definitions; consumed by defineTheme for validation + autocomplete
- *
- * Domain tokens are color tokens owned by specific feature areas (code
- * highlighting, data visualization, etc.) that don't belong in the core
- * color palette but still need to be theme-overridable.
- *
- * These are in a SEPARATE file from tokens.stylex.ts so they're
- * tree-shakeable — importing core components doesn't pull these in.
- * Only defineTheme and domain components reference this file.
- *
- * SYNC: When adding a new domain, update:
- * - This file (add defaults + type)
- * - /packages/core/src/theme/defineTheme.ts (add to XDSTokenName union)
- * - /packages/core/src/theme/index.ts (re-export)
- */
-
-// =============================================================================
-// Syntax Highlighting
-// =============================================================================
-
-export const syntaxTokenDefaults = {
- // keyword → accent (primary emphasis, control flow)
- '--color-syntax-keyword': 'light-dark(#0064E0, #2694FE)',
- // string → green-text
- '--color-syntax-string': 'light-dark(#09441F, #A5F690)',
- // comment → text-secondary (de-emphasized)
- '--color-syntax-comment': 'light-dark(#4E606F, #AAAFB5)',
- // number → orange-text (warm tone for constants)
- '--color-syntax-number': 'light-dark(#6B2203, #FDB876)',
- // function → blue-text (structural landmarks)
- '--color-syntax-function': 'light-dark(#042F97, #AFD7FF)',
- // type → purple-text (type system, interfaces)
- '--color-syntax-type': 'light-dark(#3E0697, #B3B0FE)',
- // variable → text-primary (neutral body text)
- '--color-syntax-variable': 'light-dark(#0A1317, #DFE2E5)',
- // operator → text-secondary
- '--color-syntax-operator': 'light-dark(#4E606F, #AAAFB5)',
- // constant → orange-text (true/false/null, same family as numbers)
- '--color-syntax-constant': 'light-dark(#6B2203, #FDB876)',
- // tag → red-text (HTML/JSX tags)
- '--color-syntax-tag': 'light-dark(#7B0210, #FFB2B8)',
- // attribute → orange-text (HTML/JSX attributes)
- '--color-syntax-attribute': 'light-dark(#6B2203, #FDB876)',
- // property → cyan-text (object properties, distinct from functions)
- '--color-syntax-property': 'light-dark(#006064, #B2EBF2)',
- // punctuation → text-disabled (most de-emphasized)
- '--color-syntax-punctuation': 'light-dark(#A4B0BC, #6F747C)',
-} as const;
-
-export type SyntaxTokenName = keyof typeof syntaxTokenDefaults;
-
-// =============================================================================
-// Data Visualization (planned)
-// =============================================================================
-
-// export const datavizTokenDefaults = {
-// '--color-dataviz-primary': 'light-dark(#0064E0, #2694FE)',
-// '--color-dataviz-secondary': 'light-dark(#50a14f, #98c379)',
-// // ...
-// } as const;
-//
-// export type DatavizTokenName = keyof typeof datavizTokenDefaults;
-
-// =============================================================================
-// Aggregate
-// =============================================================================
-
-/** All domain token defaults merged — used by defineTheme for validation */
-export const domainTokenDefaults: Record<string, string> = {
- ...syntaxTokenDefaults,
- // ...datavizTokenDefaults, // uncomment when added
-};
-
-/** Union of all domain token names */
-export type DomainTokenName = SyntaxTokenName; // | DatavizTokenName
diff --git a/packages/core/src/theme/domainTokens/dataTokens.ts b/packages/core/src/theme/domainTokens/dataTokens.ts
new file mode 100644
index 0000000000..0be6b1a1b4
--- /dev/null
+++ b/packages/core/src/theme/domainTokens/dataTokens.ts
@@ -0,0 +1,99 @@
+/**
+ * @file dataTokens.ts
+ * @input None (pure token definitions)
+ * @output dataTokenDefaults, DataTokenName
+ * @position Domain token sub-module; re-exported from domainTokens/index.ts
+ *
+ * Data visualization tokens. Used by chart and graph components to maintain
+ * consistent, theme-aware color palettes across all data vis surfaces.
+ *
+ * Token structure:
+ * - Categorical: one accent per category (use for distinct series/dimensions)
+ * - Neutral: a single neutral tone (use for labels, reference lines, empty states)
+ * - Sequential ramps (color-5 → color-1): darkest → lightest within a hue.
+ * Use for ordered/quantitative scales, heatmaps, choropleth maps.
+ */
+
+export const dataTokenDefaults = {
+ // --- Categorical palette (single accent color per category) ---
+ '--color-data-categorical-blue': 'light-dark(#0171E3, #0171E3)',
+ '--color-data-categorical-orange': 'light-dark(#EB6E00, #EB6E00)',
+ '--color-data-categorical-purple': 'light-dark(#6B1EFD, #6B1EFD)',
+ '--color-data-categorical-green': 'light-dark(#0B991F, #0B991F)',
+ '--color-data-categorical-pink': 'light-dark(#F351C0, #F351C0)',
+ '--color-data-categorical-cyan': 'light-dark(#0171A4, #0171A4)',
+ '--color-data-categorical-red': 'light-dark(#F5394F, #F5394F)',
+ '--color-data-categorical-teal': 'light-dark(#08A3A3, #08A3A3)',
+ '--color-data-categorical-brown': 'light-dark(#965E03, #965E03)',
+ '--color-data-categorical-indigo': 'light-dark(#6F8AFF, #6F8AFF)',
+
+ // --- Neutral ---
+ '--color-data-neutral': 'light-dark(#8494A3, #8C939B)',
+
+ // --- Sequential ramps (5 = darkest, 1 = lightest) ---
+
+ // Blue
+ '--color-data-blue-5': 'light-dark(#02165E, #02165E)',
+ '--color-data-blue-4': 'light-dark(#004CBC, #004CBC)',
+ '--color-data-blue-3': 'light-dark(#2694FE, #2694FE)',
+ '--color-data-blue-2': 'light-dark(#78BEFF, #78BEFF)',
+ '--color-data-blue-1': 'light-dark(#DBECFF, #DBECFF)',
+
+ // Shamrock
+ '--color-data-shamrock-5': 'light-dark(#0B603D, #0B603D)',
+ '--color-data-shamrock-4': 'light-dark(#138546, #138546)',
+ '--color-data-shamrock-3': 'light-dark(#24BB5E, #24BB5E)',
+ '--color-data-shamrock-2': 'light-dark(#8EF7AA, #8EF7AA)',
+ '--color-data-shamrock-1': 'light-dark(#D6FEE4, #D6FEE4)',
+
+ // Orange
+ '--color-data-orange-5': 'light-dark(#A13F04, #A13F04)',
+ '--color-data-orange-4': 'light-dark(#D66100, #D66100)',
+ '--color-data-orange-3': 'light-dark(#FD9537, #FD9537)',
+ '--color-data-orange-2': 'light-dark(#FDB876, #FDB876)',
+ '--color-data-orange-1': 'light-dark(#FFE6CF, #FFE6CF)',
+
+ // Pink
+ '--color-data-pink-5': 'light-dark(#8E1073, #8E1073)',
+ '--color-data-pink-4': 'light-dark(#D123A1, #D123A1)',
+ '--color-data-pink-3': 'light-dark(#F989D3, #F989D3)',
+ '--color-data-pink-2': 'light-dark(#FEADE3, #FEADE3)',
+ '--color-data-pink-1': 'light-dark(#FCE3F4, #FCE3F4)',
+
+ // Purple
+ '--color-data-purple-5': 'light-dark(#3E0697, #3E0697)',
+ '--color-data-purple-4': 'light-dark(#6B1EFD, #6B1EFD)',
+ '--color-data-purple-3': 'light-dark(#9081FF, #9081FF)',
+ '--color-data-purple-2': 'light-dark(#B3B0FE, #B3B0FE)',
+ '--color-data-purple-1': 'light-dark(#E8E8FB, #E8E8FB)',
+
+ // Red
+ '--color-data-red-5': 'light-dark(#9D0519, #9D0519)',
+ '--color-data-red-4': 'light-dark(#D31130, #D31130)',
+ '--color-data-red-3': 'light-dark(#FB7D87, #FB7D87)',
+ '--color-data-red-2': 'light-dark(#FFB2B8, #FFB2B8)',
+ '--color-data-red-1': 'light-dark(#FEE4E6, #FEE4E6)',
+
+ // Teal
+ '--color-data-teal-5': 'light-dark(#08767D, #08767D)',
+ '--color-data-teal-4': 'light-dark(#0C9293, #0C9293)',
+ '--color-data-teal-3': 'light-dark(#0DB7AF, #0DB7AF)',
+ '--color-data-teal-2': 'light-dark(#6CE6D8, #6CE6D8)',
+ '--color-data-teal-1': 'light-dark(#D7FCF8, #D7FCF8)',
+
+ // Yellow
+ '--color-data-yellow-5': 'light-dark(#8A5001, #8A5001)',
+ '--color-data-yellow-4': 'light-dark(#D69804, #D69804)',
+ '--color-data-yellow-3': 'light-dark(#FBCE03, #FBCE03)',
+ '--color-data-yellow-2': 'light-dark(#FCEC85, #FCEC85)',
+ '--color-data-yellow-1': 'light-dark(#FDF6BA, #FDF6BA)',
+
+ // Gray
+ '--color-data-gray-5': 'light-dark(#25363F, #333338)',
+ '--color-data-gray-4': 'light-dark(#5D6C7B, #666A72)',
+ '--color-data-gray-3': 'light-dark(#AFB9C4, #B2B8BE)',
+ '--color-data-gray-2': 'light-dark(#CCD3DB, #D0D3D6)',
+ '--color-data-gray-1': 'light-dark(#F1F4F7, #F2F4F6)',
+} as const;
+
+export type DataTokenName = keyof typeof dataTokenDefaults;
diff --git a/packages/core/src/theme/domainTokens/index.ts b/packages/core/src/theme/domainTokens/index.ts
new file mode 100644
index 0000000000..f6b110eb68
--- /dev/null
+++ b/packages/core/src/theme/domainTokens/index.ts
@@ -0,0 +1,45 @@
+/**
+ * @file domainTokens/index.ts
+ * @input None (re-exports sub-modules)
+ * @output domainTokenDefaults, DomainTokenName, and all sub-module exports
+ * @position Token definitions; consumed by defineTheme for validation + autocomplete
+ *
+ * Domain tokens are color tokens owned by specific feature areas (code
+ * highlighting, data visualization, etc.) that don't belong in the core
+ * color palette but still need to be theme-overridable.
+ *
+ * These are in a SEPARATE file from tokens.stylex.ts so they're
+ * tree-shakeable — importing core components doesn't pull these in.
+ * Only defineTheme and domain components reference this file.
+ *
+ * Sub-modules:
+ * - syntaxTokens.ts — code syntax highlighting (used by CodeBlock)
+ * - dataTokens.ts — data visualization palette (charts, graphs)
+ *
+ * SYNC: When adding a new domain, update:
+ * - Add a new sub-module file here (e.g. mapTokens.ts)
+ * - Re-export it below and merge into domainTokenDefaults
+ * - Update DomainTokenName union
+ * - /packages/core/src/theme/defineTheme.ts (XDSTokenName union picks this up automatically)
+ * - /packages/core/src/theme/index.ts (re-export the new type if needed)
+ */
+
+export {syntaxTokenDefaults} from './syntaxTokens';
+export type {SyntaxTokenName} from './syntaxTokens';
+
+export {dataTokenDefaults} from './dataTokens';
+export type {DataTokenName} from './dataTokens';
+
+import {syntaxTokenDefaults} from './syntaxTokens';
+import {dataTokenDefaults} from './dataTokens';
+import type {SyntaxTokenName} from './syntaxTokens';
+import type {DataTokenName} from './dataTokens';
+
+/** All domain token defaults merged — used by defineTheme for validation */
+export const domainTokenDefaults: Record<string, string> = {
+ ...syntaxTokenDefaults,
+ ...dataTokenDefaults,
+};
+
+/** Union of all domain token names */
+export type DomainTokenName = SyntaxTokenName | DataTokenName;
diff --git a/packages/core/src/theme/domainTokens/syntaxTokens.ts b/packages/core/src/theme/domainTokens/syntaxTokens.ts
new file mode 100644
index 0000000000..2aec1ea48d
--- /dev/null
+++ b/packages/core/src/theme/domainTokens/syntaxTokens.ts
@@ -0,0 +1,40 @@
+/**
+ * @file syntaxTokens.ts
+ * @input None (pure token definitions)
+ * @output syntaxTokenDefaults, SyntaxTokenName
+ * @position Domain token sub-module; re-exported from domainTokens/index.ts
+ *
+ * Code syntax highlighting tokens. Used by the CodeBlock component and any
+ * consumer that renders highlighted source code.
+ */
+
+export const syntaxTokenDefaults = {
+ // keyword → accent (primary emphasis, control flow)
+ '--color-syntax-keyword': 'light-dark(#0064E0, #2694FE)',
+ // string → green-text
+ '--color-syntax-string': 'light-dark(#09441F, #A5F690)',
+ // comment → text-secondary (de-emphasized)
+ '--color-syntax-comment': 'light-dark(#4E606F, #AAAFB5)',
+ // number → orange-text (warm tone for constants)
+ '--color-syntax-number': 'light-dark(#6B2203, #FDB876)',
+ // function → blue-text (structural landmarks)
+ '--color-syntax-function': 'light-dark(#042F97, #AFD7FF)',
+ // type → purple-text (type system, interfaces)
+ '--color-syntax-type': 'light-dark(#3E0697, #B3B0FE)',
+ // variable → text-primary (neutral body text)
+ '--color-syntax-variable': 'light-dark(#0A1317, #DFE2E5)',
+ // operator → text-secondary
+ '--color-syntax-operator': 'light-dark(#4E606F, #AAAFB5)',
+ // constant → orange-text (true/false/null, same family as numbers)
+ '--color-syntax-constant': 'light-dark(#6B2203, #FDB876)',
+ // tag → red-text (HTML/JSX tags)
+ '--color-syntax-tag': 'light-dark(#7B0210, #FFB2B8)',
+ // attribute → orange-text (HTML/JSX attributes)
+ '--color-syntax-attribute': 'light-dark(#6B2203, #FDB876)',
+ // property → cyan-text (object properties, distinct from functions)
+ '--color-syntax-property': 'light-dark(#006064, #B2EBF2)',
+ // punctuation → text-disabled (most de-emphasized)
+ '--color-syntax-punctuation': 'light-dark(#A4B0BC, #6F747C)',
+} as const;
+
+export type SyntaxTokenName = keyof typeof syntaxTokenDefaults;
diff --git a/packages/core/src/theme/tokens.stylex.ts b/packages/core/src/theme/tokens.stylex.ts
index 454f39d6a3..1460c9e8fb 100644
--- a/packages/core/src/theme/tokens.stylex.ts
+++ b/packages/core/src/theme/tokens.stylex.ts
@@ -6,6 +6,9 @@
* - *Vars: CSS custom properties that themes can override via createTheme
*
* SYNC: When modified, update /packages/agent-tools/docs/tokens.md
+ *
+ * Domain tokens (syntax highlighting, data visualization) live separately in
+ * /packages/core/src/theme/domainTokens/ — they're tree-shaken from core components.
*/
import * as stylex from '@stylexjs/stylex';