Skip to content

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

TypeScript

feat(theme): syntax defaults from palette + defineTheme({ syntax }) (#1219)

Cindy Zhangf90a8bb9b83d
diff --git a/apps/storybook/stories/CodeTheme.stories.tsx b/apps/storybook/stories/CodeTheme.stories.tsx
index 37626e956f..59ca4220cd 100644
--- a/apps/storybook/stories/CodeTheme.stories.tsx
+++ b/apps/storybook/stories/CodeTheme.stories.tsx
@@ -1,7 +1,8 @@
import type {Meta, StoryObj} from '@storybook/react';
import React from 'react';
import {XDSCodeBlock} from '@xds/core/CodeBlock';
-import {XDSSyntaxTheme as SyntaxThemeProvider} from '@xds/core/theme/syntax';
+import {XDSSyntaxTheme as SyntaxThemeProvider, defineSyntaxTheme} from '@xds/core/theme/syntax';
+import {defineTheme, XDSTheme} from '@xds/core/theme';
import {
oneDarkPro,
dracula,
@@ -277,3 +278,66 @@ export const NestedOverride: StoryObj = {
</SyntaxThemeProvider>
),
};
+
+// ---------------------------------------------------------------------------
+// Custom syntax theme — defineSyntaxTheme() with your own colors
+// ---------------------------------------------------------------------------
+
+const cyberpunk = defineSyntaxTheme({
+ name: 'cyberpunk',
+ tokens: {
+ keyword: '#ff2a6d',
+ string: '#05d9e8',
+ comment: '#4a5568',
+ number: '#d1f7ff',
+ function: '#ff6ac1',
+ type: '#7efff5',
+ variable: '#e2e8f0',
+ operator: '#ff9e64',
+ constant: '#d1f7ff',
+ tag: '#ff2a6d',
+ attribute: '#7efff5',
+ property: '#05d9e8',
+ punctuation: '#718096',
+ background: '#0d0221',
+ },
+});
+
+export const CustomTheme: StoryObj = {
+ render: () => (
+ <SyntaxThemeProvider theme={cyberpunk}>
+ <XDSCodeBlock
+ code={sampleCode}
+ language="typescript"
+ title="Custom: Cyberpunk"
+ hasLineNumbers
+ />
+ </SyntaxThemeProvider>
+ ),
+};
+
+// ---------------------------------------------------------------------------
+// Theme with syntax defaults — defineTheme({ syntax: ... })
+// ---------------------------------------------------------------------------
+
+const darkDevTheme = defineTheme({
+ name: 'dark-dev',
+ syntax: dracula,
+ tokens: {
+ '--color-background-surface': '#282a36',
+ '--color-text-primary': '#f8f8f2',
+ },
+});
+
+export const ThemeWithSyntaxDefaults: StoryObj = {
+ render: () => (
+ <XDSTheme theme={darkDevTheme} mode="dark">
+ <XDSCodeBlock
+ code={sampleCode}
+ language="typescript"
+ title="defineTheme with syntax: dracula"
+ hasLineNumbers
+ />
+ </XDSTheme>
+ ),
+};
diff --git a/packages/core/src/theme/defineTheme.ts b/packages/core/src/theme/defineTheme.ts
index 72772a1df5..58cf69da60 100644
--- a/packages/core/src/theme/defineTheme.ts
+++ b/packages/core/src/theme/defineTheme.ts
@@ -66,6 +66,7 @@ import {
import type {DomainTokenName} from './domainTokens';
import {domainTokenDefaults} from './domainTokens';
+import type {SyntaxTheme} from './syntax';
// =============================================================================
// Types
@@ -243,6 +244,18 @@ export interface XDSDefineThemeInput {
components?: XDSComponentStyleMap;
/** Icon registry — maps semantic icon names to React nodes */
icons?: Partial<XDSIconRegistry>;
+ /**
+ * Default syntax highlighting theme for code components.
+ * Sets --color-syntax-* tokens at the theme root. Can be overridden
+ * per-region via XDSSyntaxTheme or per-instance via syntaxTheme prop.
+ *
+ * @example
+ * ```tsx
+ * import {dracula} from '@xds/theme-syntax';
+ * defineTheme({ name: 'my-theme', syntax: dracula, ... })
+ * ```
+ */
+ syntax?: SyntaxTheme;
/**
* Overrides for content on a dark surface (e.g. inverted toast,
* dark tooltip). Accepts token and component overrides — same shape
@@ -506,6 +519,15 @@ export function defineTheme(input: XDSDefineThemeInput): XDSDefinedTheme {
if (codeFamily) tokens['--font-family-code'] = codeFamily;
}
+ // 1e. Apply syntax theme tokens (before explicit overrides)
+ if (input.syntax) {
+ const syntaxMap = input.syntax.tokens;
+ const prefix = '--color-syntax-';
+ for (const [key, value] of Object.entries(syntaxMap)) {
+ tokens[prefix + key] = value;
+ }
+ }
+
// 2. Apply explicit token overrides (highest precedence — overwrites generated tokens)
if (input.tokens) {
for (const [key, value] of Object.entries(input.tokens)) {
diff --git a/packages/core/src/theme/index.ts b/packages/core/src/theme/index.ts
index 3459e5a471..b9e80b563d 100644
--- a/packages/core/src/theme/index.ts
+++ b/packages/core/src/theme/index.ts
@@ -53,10 +53,13 @@ export type {
SyntaxThemeInput,
SyntaxThemeTokenKey,
SyntaxThemeTokenMap,
+ SyntaxThemeTokenInput,
+ SyntaxTokenValue,
} from './syntax';
// XDSSyntaxTheme provider
-export {XDSSyntaxTheme, useSyntaxTheme} from './syntax';
+export {XDSSyntaxTheme, useXDSSyntaxTheme} from './syntax';
+export type {UseXDSSyntaxThemeReturn} from './syntax';
export {expandTypeScale, generateTypeScaleComponents} from './expandTypeScale';
export type {XDSTypeScaleConfig, TypeScaleTokens} from './expandTypeScale';
diff --git a/packages/core/src/theme/syntax/XDSSyntaxTheme.tsx b/packages/core/src/theme/syntax/XDSSyntaxTheme.tsx
index 3b939b0205..6b2fbb0cee 100644
--- a/packages/core/src/theme/syntax/XDSSyntaxTheme.tsx
+++ b/packages/core/src/theme/syntax/XDSSyntaxTheme.tsx
@@ -2,38 +2,96 @@
/**
* @file XDSSyntaxTheme.tsx
- * @input XDSSyntaxTheme type from defineSyntaxTheme.ts
- * @output XDSSyntaxTheme provider, useSyntaxTheme hook
+ * @input SyntaxTheme from defineSyntaxTheme.ts
+ * @output XDSSyntaxTheme provider, useXDSSyntaxTheme hook
* @position Provider component; wraps code surfaces to apply syntax coloring
*
- * Sets syntax color tokens as CSS custom properties on a wrapper element.
- * Any XDSCodeBlock or XDSCodeEditor inside inherits these colors via
- * CSS variable cascade.
- *
- * Cascading priority (highest wins):
- * 1. syntaxTheme prop on individual code components (inline style)
- * 2. XDSSyntaxTheme provider (closer ancestor)
- * 3. syntax field in defineTheme() (theme root)
- * 4. Built-in XDS default syntax token values (CSS fallbacks)
- *
* @see https://github.com/facebookexperimental/xds/issues/1148
*/
import React, {createContext, useContext, useMemo} from 'react';
-import {syntaxThemeStyle, type SyntaxTheme} from './defineSyntaxTheme';
+import {
+ syntaxThemeStyle,
+ resolveSyntaxTokenForMode,
+ ALL_SYNTAX_KEYS,
+ type SyntaxTheme,
+ type SyntaxThemeTokenKey,
+} from './defineSyntaxTheme';
+import {useMediaQuery} from '../../hooks/useMediaQuery';
// =============================================================================
// Context
// =============================================================================
-const SyntaxThemeContext = createContext<SyntaxTheme | null>(null);
+/** @internal */
+interface SyntaxThemeContextValue {
+ theme: SyntaxTheme;
+}
+
+const SyntaxThemeContext = createContext<SyntaxThemeContextValue | null>(null);
+
+// =============================================================================
+// Return type
+// =============================================================================
+
+export interface UseXDSSyntaxThemeReturn {
+ /** Syntax theme name */
+ name: string;
+ /** Resolved effective mode ('light' | 'dark') */
+ mode: 'light' | 'dark';
+ /**
+ * Resolve a syntax token to its raw CSS value for the current color mode.
+ *
+ * @example
+ * const keywordColor = token('keyword'); // "#0064E0" in light mode
+ */
+ token: (name: SyntaxThemeTokenKey) => string;
+ /**
+ * All syntax tokens resolved for the current color mode.
+ */
+ tokens: Record<SyntaxThemeTokenKey, string>;
+}
+
+// =============================================================================
+// Hook
+// =============================================================================
/**
- * Read the current syntax theme from context.
- * Returns null if no XDSSyntaxTheme provider is present.
+ * Access the current syntax theme's token values, resolved for the active
+ * color mode. Returns null if no XDSSyntaxTheme provider is present.
+ *
+ * @example
+ * function CodeCanvas() {
+ * const syntax = useXDSSyntaxTheme();
+ * if (!syntax) return null;
+ * ctx.fillStyle = syntax.token('keyword');
+ * }
*/
-export function useSyntaxTheme(): SyntaxTheme | null {
- return useContext(SyntaxThemeContext);
+export function useXDSSyntaxTheme(): UseXDSSyntaxThemeReturn | null {
+ const ctx = useContext(SyntaxThemeContext);
+ const prefersDark = useMediaQuery('(prefers-color-scheme: dark)');
+ const effectiveMode: 'light' | 'dark' = prefersDark ? 'dark' : 'light';
+
+ const tokens = useMemo(() => {
+ if (!ctx) return null;
+ const resolved = {} as Record<SyntaxThemeTokenKey, string>;
+ for (const key of ALL_SYNTAX_KEYS) {
+ resolved[key] = resolveSyntaxTokenForMode(
+ ctx.theme.__inputTokens[key],
+ effectiveMode,
+ );
+ }
+ return resolved;
+ }, [ctx, effectiveMode]);
+
+ if (!ctx || !tokens) return null;
+
+ return {
+ name: ctx.theme.name,
+ mode: effectiveMode,
+ token: (name: SyntaxThemeTokenKey) => tokens[name] ?? '',
+ tokens,
+ };
}
// =============================================================================
@@ -47,17 +105,17 @@ interface XDSSyntaxThemeProps {
/**
* Syntax theme provider. Sets CSS custom properties on a wrapper div
- * so child code components inherit via cascade. Also exposes the theme
- * object via React context for programmatic access.
+ * so child code components inherit via cascade.
*/
export function XDSSyntaxTheme({
theme,
children,
}: XDSSyntaxThemeProps): React.ReactElement {
const style = useMemo(() => syntaxThemeStyle(theme), [theme]);
+ const value = useMemo(() => ({theme}), [theme]);
return (
- <SyntaxThemeContext.Provider value={theme}>
+ <SyntaxThemeContext.Provider value={value}>
<div style={style} data-xds-syntax-theme={theme.name}>
{children}
</div>
diff --git a/packages/core/src/theme/syntax/defineSyntaxTheme.ts b/packages/core/src/theme/syntax/defineSyntaxTheme.ts
index 0a5d8fd412..71e4695515 100644
--- a/packages/core/src/theme/syntax/defineSyntaxTheme.ts
+++ b/packages/core/src/theme/syntax/defineSyntaxTheme.ts
@@ -4,7 +4,7 @@
* @file defineSyntaxTheme.ts
* @input syntaxTokenDefaults from tokens.ts
* @output defineSyntaxTheme, SyntaxTheme, syntaxThemeStyle
- * @position Syntax theme definition API; consumed by presets, XDSCodeTheme, defineTheme
+ * @position Syntax theme definition API; consumed by presets, XDSSyntaxTheme, defineTheme
*
* @see https://github.com/facebookexperimental/xds/issues/1148
*/
@@ -32,18 +32,32 @@ export type SyntaxThemeTokenKey =
| 'punctuation'
| 'background';
-/** A complete mapping of token names to CSS color values. */
+/**
+ * Token value — either a single string or a [light, dark] tuple.
+ * Tuples are converted to CSS light-dark() at theme creation time.
+ */
+export type SyntaxTokenValue = string | [light: string, dark: string];
+
+/** Token map for defineSyntaxTheme input — values can be strings or tuples. */
+export type SyntaxThemeTokenInput = Record<SyntaxThemeTokenKey, SyntaxTokenValue>;
+
+/** Resolved token map — all values are CSS strings (tuples resolved to light-dark()). */
export type SyntaxThemeTokenMap = Record<SyntaxThemeTokenKey, string>;
+/** Input to defineSyntaxTheme. */
export interface SyntaxThemeInput {
name: string;
- tokens: SyntaxThemeTokenMap;
+ tokens: SyntaxThemeTokenInput;
}
-/** A defined syntax theme. */
+/** A defined syntax theme — tokens are resolved to CSS strings. */
export interface SyntaxTheme {
+ /** Theme name */
name: string;
+ /** Resolved token values (light-dark() CSS strings) */
tokens: SyntaxThemeTokenMap;
+ /** Original input tokens (preserves tuples for mode resolution) */
+ __inputTokens: SyntaxThemeTokenInput;
}
// =============================================================================
@@ -56,9 +70,42 @@ function toCSSProperty(key: SyntaxThemeTokenKey): SyntaxTokenName {
return (CSS_PREFIX + key) as SyntaxTokenName;
}
-const ALL_KEYS: SyntaxThemeTokenKey[] = Object.keys(syntaxTokenDefaults)
+/** All valid human-readable token keys, derived from the defaults. */
+export const ALL_SYNTAX_KEYS: SyntaxThemeTokenKey[] = Object.keys(syntaxTokenDefaults)
.map(k => k.replace(CSS_PREFIX, '') as SyntaxThemeTokenKey);
+// =============================================================================
+// Helpers
+// =============================================================================
+
+/** Resolve a token value to a CSS string. Tuples become light-dark(). */
+function resolveTokenValue(value: SyntaxTokenValue): string {
+ if (Array.isArray(value)) {
+ return `light-dark(${value[0]}, ${value[1]})`;
+ }
+ return value;
+}
+
+/**
+ * Resolve a token value for a specific color mode.
+ * - [light, dark] tuple → picks the correct side
+ * - light-dark(a, b) string → parses and picks
+ * - plain string → pass through
+ */
+export function resolveSyntaxTokenForMode(
+ value: SyntaxTokenValue,
+ mode: 'light' | 'dark',
+): string {
+ if (Array.isArray(value)) {
+ return mode === 'dark' ? value[1] : value[0];
+ }
+ const match = value.match(/^light-dark\(([^,]+),([^)]+)\)$/);
+ if (match) {
+ return mode === 'dark' ? match[2].trim() : match[1].trim();
+ }
+ return value;
+}
+
// =============================================================================
// defineSyntaxTheme
// =============================================================================
@@ -66,21 +113,41 @@ const ALL_KEYS: SyntaxThemeTokenKey[] = Object.keys(syntaxTokenDefaults)
/**
* Create a syntax theme from a complete token map.
*
+ * Token values can be:
+ * - A string: used as-is (e.g. '#ff79c6' or 'light-dark(#0064E0, #2694FE)')
+ * - A [light, dark] tuple: converted to light-dark(light, dark)
+ *
* @example
- * const dracula = defineSyntaxTheme({
- * name: 'dracula',
- * tokens: { keyword: '#ff79c6', string: '#f1fa8c', ... },
+ * const myTheme = defineSyntaxTheme({
+ * name: 'my-theme',
+ * tokens: {
+ * keyword: ['#0064E0', '#2694FE'], // [light, dark] tuple
+ * string: '#98c379', // same in both modes
+ * comment: 'light-dark(#666, #999)', // CSS light-dark() string
+ * // ... all 14 tokens
+ * },
* });
*/
export function defineSyntaxTheme(input: SyntaxThemeInput): SyntaxTheme {
- const missing = ALL_KEYS.filter(key => !(key in input.tokens));
+ const missing = ALL_SYNTAX_KEYS.filter(key => !(key in input.tokens));
if (missing.length > 0) {
console.warn(
'[XDS] defineSyntaxTheme("' + input.name + '"): missing tokens: ' +
missing.join(', ') + '. All 14 syntax tokens are required.',
);
}
- return {name: input.name, tokens: {...input.tokens}};
+
+ // Resolve tuples to light-dark() CSS strings
+ const resolved: SyntaxThemeTokenMap = {} as SyntaxThemeTokenMap;
+ for (const key of ALL_SYNTAX_KEYS) {
+ resolved[key] = resolveTokenValue(input.tokens[key]);
+ }
+
+ return {
+ name: input.name,
+ tokens: resolved,
+ __inputTokens: {...input.tokens},
+ };
}
// =============================================================================
@@ -92,7 +159,7 @@ export function syntaxThemeStyle(
theme: SyntaxTheme,
): Record<string, string> {
const vars: Record<string, string> = {};
- for (const key of ALL_KEYS) {
+ for (const key of ALL_SYNTAX_KEYS) {
vars[toCSSProperty(key)] = theme.tokens[key];
}
return vars;
@@ -100,7 +167,7 @@ export function syntaxThemeStyle(
/** Convert a syntax theme to CSS declarations (no selector wrapper). */
export function syntaxThemeToCSS(theme: SyntaxTheme): string {
- return ALL_KEYS
+ return ALL_SYNTAX_KEYS
.map(key => toCSSProperty(key) + ': ' + theme.tokens[key] + ';')
.join('\n ');
}
diff --git a/packages/core/src/theme/syntax/index.ts b/packages/core/src/theme/syntax/index.ts
index 83c185bdb4..7964dc818b 100644
--- a/packages/core/src/theme/syntax/index.ts
+++ b/packages/core/src/theme/syntax/index.ts
@@ -14,6 +14,9 @@ export type {
SyntaxThemeInput,
SyntaxThemeTokenKey,
SyntaxThemeTokenMap,
+ SyntaxThemeTokenInput,
+ SyntaxTokenValue,
} from './defineSyntaxTheme';
-export {XDSSyntaxTheme, useSyntaxTheme} from './XDSSyntaxTheme';
+export {XDSSyntaxTheme, useXDSSyntaxTheme} from './XDSSyntaxTheme';
+export type {UseXDSSyntaxThemeReturn} from './XDSSyntaxTheme';
diff --git a/packages/core/src/theme/syntax/tokens.ts b/packages/core/src/theme/syntax/tokens.ts
index 8e7be26fe4..fdf119ca01 100644
--- a/packages/core/src/theme/syntax/tokens.ts
+++ b/packages/core/src/theme/syntax/tokens.ts
@@ -1,5 +1,5 @@
/**
- * @file syntaxTokens.ts
+ * @file tokens.ts
* @input None (pure token definitions)
* @output syntaxTokenDefaults, SyntaxTokenName
* @position Domain token sub-module; re-exported from domainTokens/index.ts
@@ -7,6 +7,10 @@
* Code syntax highlighting tokens. Used by the CodeBlock component and any
* consumer that renders highlighted source code.
*
+ * Default values reference the theme's named palette via var() so syntax
+ * colors automatically adapt to any theme's color system. Themes can also
+ * set an explicit syntax theme via defineTheme({ syntax: dracula }).
+ *
* 14-token architecture validated against 11 community code themes.
* All themes map cleanly to these 14 slots.
*
@@ -14,34 +18,34 @@
*/
export const syntaxTokenDefaults = {
- // keyword → accent (primary emphasis, control flow: if, return, const)
- '--color-syntax-keyword': 'light-dark(#0064E0, #2694FE)',
- // string → green-text (string literals)
- '--color-syntax-string': 'light-dark(#09441F, #A5F690)',
- // comment → subdued (passive annotations, deliberately muted)
- '--color-syntax-comment': 'light-dark(#4E606F, #6B7D8D)',
- // number → orange-text (warm tone for numeric literals)
- '--color-syntax-number': 'light-dark(#6B2203, #FDB876)',
- // function → blue-text (structural landmarks: function/method names)
- '--color-syntax-function': 'light-dark(#042F97, #AFD7FF)',
- // type → purple-text (type system: interfaces, classes, generics)
- '--color-syntax-type': 'light-dark(#3E0697, #B3B0FE)',
- // variable → text-primary (neutral identifiers, close to body text)
- '--color-syntax-variable': 'light-dark(#0A1317, #DFE2E5)',
- // operator → teal (active syntax: =, +, =>, &&, !==) — separated from comment
- '--color-syntax-operator': 'light-dark(#006D75, #56C8D8)',
- // constant → orange-text (true/false/null, same family as numbers)
- '--color-syntax-constant': 'light-dark(#6B2203, #FDB876)',
- // tag → red-text (HTML/JSX tags: <div>, <Button>)
- '--color-syntax-tag': 'light-dark(#7B0210, #FFB2B8)',
- // attribute → warm amber (HTML/JSX attributes) — separated from number
- '--color-syntax-attribute': 'light-dark(#7A4F1A, #E8C580)',
- // property → cyan-text (object properties, distinct from functions)
- '--color-syntax-property': 'light-dark(#006064, #B2EBF2)',
- // punctuation → muted (brackets, semicolons) — contrast fixed for light mode
- '--color-syntax-punctuation': 'light-dark(#65737E, #6F747C)',
- // background → code block surface color
- '--color-syntax-background': 'light-dark(#FFFFFF, #1A1A1A)',
+ // keyword -> accent text (control flow: if, return, const)
+ '--color-syntax-keyword': 'var(--color-text-accent)',
+ // string -> green text (string literals)
+ '--color-syntax-string': 'var(--color-text-green)',
+ // comment -> secondary text (passive annotations)
+ '--color-syntax-comment': 'var(--color-text-secondary)',
+ // number -> orange text (numeric literals)
+ '--color-syntax-number': 'var(--color-text-orange)',
+ // function -> blue text (function/method names)
+ '--color-syntax-function': 'var(--color-text-blue)',
+ // type -> purple text (types, interfaces, classes)
+ '--color-syntax-type': 'var(--color-text-purple)',
+ // variable -> primary text (neutral identifiers)
+ '--color-syntax-variable': 'var(--color-text-primary)',
+ // operator -> cyan text (=, +, =>, &&)
+ '--color-syntax-operator': 'var(--color-text-cyan)',
+ // constant -> orange text (true, false, null)
+ '--color-syntax-constant': 'var(--color-text-orange)',
+ // tag -> red text (HTML/JSX tags)
+ '--color-syntax-tag': 'var(--color-text-red)',
+ // attribute -> teal text (HTML/JSX attributes)
+ '--color-syntax-attribute': 'var(--color-text-teal)',
+ // property -> cyan text (object properties)
+ '--color-syntax-property': 'var(--color-text-cyan)',
+ // punctuation -> disabled text (brackets, semicolons)
+ '--color-syntax-punctuation': 'var(--color-text-disabled)',
+ // background -> muted surface
+ '--color-syntax-background': 'var(--color-background-muted)',
} as const;
export type SyntaxTokenName = keyof typeof syntaxTokenDefaults;
diff --git a/packages/core/src/theme/useXDSTheme.ts b/packages/core/src/theme/useXDSTheme.ts
index dc49fa4912..882f9f490b 100644
--- a/packages/core/src/theme/useXDSTheme.ts
+++ b/packages/core/src/theme/useXDSTheme.ts
@@ -94,9 +94,9 @@ function resolveValue(value: XDSTokenValue, mode: 'light' | 'dark'): string {
return mode === 'dark' ? value[1] : value[0];
}
// For string values, try to parse light-dark(a, b) from defaults
- const match = value.match(/^light-dark\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);
+ const match = value.match(/^light-dark\(([^,]+),([^)]+)\)$/);
if (match) {
- return mode === 'dark' ? match[2] : match[1];
+ return mode === 'dark' ? match[2].trim() : match[1].trim();
}
return value;
}
diff --git a/packages/themes/default/src/defaultTheme.ts b/packages/themes/default/src/defaultTheme.ts
index c88d23ab8c..25a4123c8f 100644
--- a/packages/themes/default/src/defaultTheme.ts
+++ b/packages/themes/default/src/defaultTheme.ts
@@ -11,9 +11,30 @@
* Only non-typography component overrides need to be specified manually.
*/
-import {defineTheme} from '@xds/core/theme';
+import {defineTheme, defineSyntaxTheme} from '@xds/core/theme';
import {defaultIconRegistry} from './icons';
+/** Default syntax palette — tuned to the XDS blue color ramp. */
+const defaultSyntax = defineSyntaxTheme({
+ name: 'xds-default',
+ tokens: {
+ keyword: ['#0064E0', '#2694FE'],
+ string: ['#09441F', '#A5F690'],
+ comment: ['#4E606F', '#6B7D8D'],
+ number: ['#6B2203', '#FDB876'],
+ function: ['#042F97', '#AFD7FF'],
+ type: ['#3E0697', '#B3B0FE'],
+ variable: ['#0A1317', '#DFE2E5'],
+ operator: ['#006D75', '#56C8D8'],
+ constant: ['#6B2203', '#FDB876'],
+ tag: ['#7B0210', '#FFB2B8'],
+ attribute: ['#7A4F1A', '#E8C580'],
+ property: ['#006064', '#B2EBF2'],
+ punctuation: ['#65737E', '#6F747C'],
+ background: ['#F1F4F7', '#111112'],
+ },
+});
+
export const defaultTheme = defineTheme({
name: 'default',
@@ -26,8 +47,10 @@ export const defaultTheme = defineTheme({
// medium-min=310ms, medium=410ms, medium-max=545ms.
motion: {fast: 175, medium: 410, ratio: 0.75},
+ // Syntax highlighting — tuned to the default palette
+ syntax: defaultSyntax,
+
// The default theme uses the built-in token defaults from tokens.stylex.ts.
- // No additional token overrides needed.
tokens: {},
components: {
diff --git a/packages/themes/neutral/src/neutralTheme.ts b/packages/themes/neutral/src/neutralTheme.ts
index 56d9f43b68..46d652b17e 100644
--- a/packages/themes/neutral/src/neutralTheme.ts
+++ b/packages/themes/neutral/src/neutralTheme.ts
@@ -10,9 +10,30 @@
* use the built-in defaults automatically.
*/
-import {defineTheme} from '@xds/core/theme';
+import {defineTheme, defineSyntaxTheme} from '@xds/core/theme';
import {neutralIconRegistry} from './icons';
+/** Neutral syntax palette — desaturated, low-chroma to match grayscale. */
+const neutralSyntax = defineSyntaxTheme({
+ name: 'xds-neutral',
+ tokens: {
+ keyword: ['#7c3aed', '#a78bfa'],
+ string: ['#16653a', '#6ee7a0'],
+ comment: ['#71717a', '#71717a'],
+ number: ['#b45309', '#fbbf24'],
+ function: ['#2563eb', '#60a5fa'],
+ type: ['#7c3aed', '#c4b5fd'],
+ variable: ['#18181b', '#e4e4e7'],
+ operator: ['#71717a', '#a1a1aa'],
+ constant: ['#b45309', '#fbbf24'],
+ tag: ['#dc2626', '#fca5a5'],
+ attribute: ['#a16207', '#fde68a'],
+ property: ['#0d9488', '#5eead4'],
+ punctuation: ['#a1a1aa', '#52525b'],
+ background: ['#fafafa', '#0a0a0a'],
+ },
+});
+
export const neutralTheme = defineTheme({
name: 'neutral',
@@ -40,6 +61,9 @@ export const neutralTheme = defineTheme({
// medium-min=225ms, medium=300ms, medium-max=400ms.
motion: {fast: 125, medium: 300, ratio: 0.75},
+ // Syntax highlighting — desaturated to match grayscale palette
+ syntax: neutralSyntax,
+
tokens: {
// =========================================================================
// Colors — neutral grayscale palette using oklch