Skip to content

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

TypeScript

refactor(core): rename xdsTokenDefaults export to tokenDefaults (#3137)

EJ Hammond08d4cf4510a0
diff --git a/.changeset/core-token-defaults-rename.md b/.changeset/core-token-defaults-rename.md
new file mode 100644
index 0000000000..de14ffe7f4
--- /dev/null
+++ b/.changeset/core-token-defaults-rename.md
@@ -0,0 +1,10 @@
+---
+'@astryxdesign/core': patch
+---
+
+[breaking] Rename `xdsTokenDefaults` export to `tokenDefaults`
+@ejhammond
+
+The token-defaults constant is renamed from `xdsTokenDefaults` to
+`tokenDefaults` (exported from `@astryxdesign/core/theme`). Update imports
+accordingly. Part of removing xds naming from the public API.
diff --git a/apps/docsite/src/app/playground/PlaygroundClient.tsx b/apps/docsite/src/app/playground/PlaygroundClient.tsx
index e563077fcd..7dd21ea9e7 100644
--- a/apps/docsite/src/app/playground/PlaygroundClient.tsx
+++ b/apps/docsite/src/app/playground/PlaygroundClient.tsx
@@ -91,7 +91,7 @@ import {configureMonaco, type MonacoInstance} from './monacoSetup';
import type * as MonacoTypes from 'monaco-editor';
import type {DefinedTheme} from '@astryxdesign/core/theme';
-import {xdsTokenDefaults} from '@astryxdesign/core/theme';
+import {tokenDefaults} from '@astryxdesign/core/theme';
// Hidden from the generated registry (isHiddenFromOverview), so it's added
// explicitly as the first entry in the Templates dropdown.
@@ -549,7 +549,7 @@ export function PlaygroundClient({defaultIsMobile}: PlaygroundClientProps) {
const source = generateThemeCode(
name,
activeTheme.tokens,
- xdsTokenDefaults,
+ tokenDefaults,
14,
1.2,
[],
diff --git a/apps/docsite/src/components/tokens/helpers.ts b/apps/docsite/src/components/tokens/helpers.ts
index b7076cd3cc..b9bdcaac7d 100644
--- a/apps/docsite/src/components/tokens/helpers.ts
+++ b/apps/docsite/src/components/tokens/helpers.ts
@@ -5,7 +5,7 @@ import type {UseThemeReturn} from '@astryxdesign/core/theme';
import {
borderDefaults,
ThemeContext,
- xdsTokenDefaults,
+ tokenDefaults,
} from '@astryxdesign/core/theme';
import type {TokenValue} from '@astryxdesign/core/theme';
@@ -43,7 +43,7 @@ function buildTokenMap(
): Record<string, string> {
const resolved: Record<string, string> = {};
- for (const [key, value] of Object.entries(xdsTokenDefaults)) {
+ for (const [key, value] of Object.entries(tokenDefaults)) {
resolved[key] = resolveValue(value, mode);
}
for (const [key, value] of Object.entries(extraDefaults)) {
@@ -95,7 +95,7 @@ export function getTokensByPrefix(
): string[] {
const allKeys = new Set([
...Object.keys(theme.tokens),
- ...Object.keys(xdsTokenDefaults),
+ ...Object.keys(tokenDefaults),
...Object.keys(extraDefaults),
]);
return [...allKeys].filter(k => k.startsWith(prefix));
diff --git a/apps/sandbox/src/app/(sandbox)/pages/doc-preview/token-tables/helpers.ts b/apps/sandbox/src/app/(sandbox)/pages/doc-preview/token-tables/helpers.ts
index 14452bcc6e..db7a9ee403 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/doc-preview/token-tables/helpers.ts
+++ b/apps/sandbox/src/app/(sandbox)/pages/doc-preview/token-tables/helpers.ts
@@ -1,7 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import type {DefinedTheme} from '@astryxdesign/core/theme';
-import {xdsTokenDefaults} from '@astryxdesign/core/theme';
+import {tokenDefaults} from '@astryxdesign/core/theme';
/**
* Parse a light-dark() CSS value into [light, dark] components.
@@ -18,7 +18,7 @@ export function parseLightDark(value: string): [string, string] | null {
* Resolve a token's value for a specific mode from a defined theme.
* Checks __inputTokens for [light, dark] tuples first,
* then parses light-dark() from resolved tokens,
- * then falls back to xdsTokenDefaults.
+ * then falls back to tokenDefaults.
*/
export function resolveTokenForMode(
theme: DefinedTheme,
@@ -50,7 +50,7 @@ export function resolveTokenForMode(
return resolved;
}
// 3. Fall back to defaults
- const def = xdsTokenDefaults[tokenName];
+ const def = tokenDefaults[tokenName];
if (def) {
const parsed = parseLightDark(def);
if (parsed) {
@@ -77,7 +77,7 @@ export function resolveToken(
}
return resolved;
}
- const def = xdsTokenDefaults[tokenName];
+ const def = tokenDefaults[tokenName];
if (def) {
const parsed = parseLightDark(def);
if (parsed) {
@@ -110,7 +110,7 @@ export function getTokensByPrefix(
prefix: string,
): string[] {
const allKeys = new Set([
- ...Object.keys(xdsTokenDefaults),
+ ...Object.keys(tokenDefaults),
...Object.keys(theme.tokens),
]);
return [...allKeys]
diff --git a/apps/sandbox/src/components/themePreview/themeAudit.ts b/apps/sandbox/src/components/themePreview/themeAudit.ts
index 8ff66a9363..8f2e5feea6 100644
--- a/apps/sandbox/src/components/themePreview/themeAudit.ts
+++ b/apps/sandbox/src/components/themePreview/themeAudit.ts
@@ -7,7 +7,7 @@
* theme source files:
*
* 1. "Which tokens did this theme actually change vs the Astryx defaults?"
- * — diff `theme.tokens` against `xdsTokenDefaults` and bucket each
+ * — diff `theme.tokens` against `tokenDefaults` and bucket each
* entry as unchanged / overridden / new.
*
* 2. "Did each color token snap to a step on a tonal ramp, or did the
@@ -18,7 +18,7 @@
*/
import type {DefinedTheme} from '@astryxdesign/core/theme';
-import {xdsTokenDefaults} from '@astryxdesign/core/theme';
+import {tokenDefaults} from '@astryxdesign/core/theme';
import {
findClosestRampStep,
type Mode,
@@ -116,7 +116,7 @@ export function categorizeToken(name: string): TokenCategory {
}
// =============================================================================
-// Token diff — overridden / unchanged / new vs xdsTokenDefaults
+// Token diff — overridden / unchanged / new vs tokenDefaults
// =============================================================================
export type DiffStatus =
@@ -150,7 +150,7 @@ export interface TokenDiff {
}
/**
- * Build a full token diff vs xdsTokenDefaults.
+ * Build a full token diff vs tokenDefaults.
*
* Note: defineTheme pre-seeds `theme.tokens` from base + generated +
* explicit overrides, so every token defaults supplies will also appear on
@@ -161,7 +161,7 @@ export interface TokenDiff {
export function diffThemeTokens(theme: DefinedTheme): TokenDiff {
const themeTokens = theme.tokens;
const allKeys = new Set<string>([
- ...Object.keys(xdsTokenDefaults),
+ ...Object.keys(tokenDefaults),
...Object.keys(themeTokens),
]);
@@ -182,7 +182,7 @@ export function diffThemeTokens(theme: DefinedTheme): TokenDiff {
}
for (const name of allKeys) {
- const defaultValue = xdsTokenDefaults[name];
+ const defaultValue = tokenDefaults[name];
const themeValue = themeTokens[name];
const category = categorizeToken(name);
diff --git a/packages/core/src/theme/defineTheme.ts b/packages/core/src/theme/defineTheme.ts
index 7c3813596c..76c35306f2 100644
--- a/packages/core/src/theme/defineTheme.ts
+++ b/packages/core/src/theme/defineTheme.ts
@@ -361,7 +361,7 @@ export interface DefinedTheme {
// =============================================================================
/** All Astryx token defaults as a flat map. Useful for resolving full token sets. */
-export const xdsTokenDefaults: Record<string, string> = {
+export const tokenDefaults: Record<string, string> = {
...colorDefaults,
...spacingDefaults,
...sizeDefaults,
diff --git a/packages/core/src/theme/index.ts b/packages/core/src/theme/index.ts
index b86c88416c..00cf1a0ac3 100644
--- a/packages/core/src/theme/index.ts
+++ b/packages/core/src/theme/index.ts
@@ -28,7 +28,7 @@ export {
type ThemeCSSOutput,
type ThemeRulesSplit,
isDefinedTheme,
- xdsTokenDefaults,
+ tokenDefaults,
} from './defineTheme';
export type {
DefineThemeInput,
diff --git a/packages/core/src/theme/tokens.ts b/packages/core/src/theme/tokens.ts
index acd045a2a6..504f847140 100644
--- a/packages/core/src/theme/tokens.ts
+++ b/packages/core/src/theme/tokens.ts
@@ -16,7 +16,7 @@
*/
import {
- xdsTokenDefaults,
+ tokenDefaults,
type DefinedTheme,
type TokenName,
type TokenValue,
@@ -60,7 +60,7 @@ export function tokenVar(name: TokenName | (string & {})): string {
/** Flat map of every known Astryx token name to its `var(--token-name)` reference. */
export const tokenVars: Record<TokenName, string> = Object.fromEntries(
- Object.keys(xdsTokenDefaults).map(name => [name, tokenVar(name)]),
+ Object.keys(tokenDefaults).map(name => [name, tokenVar(name)]),
) as Record<TokenName, string>;
/**
@@ -147,7 +147,7 @@ function resolveXDSTokenValue(
/**
* Resolve all Astryx token values for a theme and effective color mode.
*
- * The result starts with `xdsTokenDefaults`, applies `theme.tokens`, then
+ * The result starts with `tokenDefaults`, applies `theme.tokens`, then
* reapplies `theme.__inputTokens` when available so explicit tuple overrides
* retain their original light/dark sides instead of relying on CSS parsing.
* This mirrors the token resolution used by `useTheme()` but does not need
@@ -162,7 +162,7 @@ export function resolveThemeTokens(
const {mode} = options;
const resolved: Record<string, string> = {};
- for (const [key, value] of Object.entries(xdsTokenDefaults)) {
+ for (const [key, value] of Object.entries(tokenDefaults)) {
resolved[key] = resolveXDSTokenValue(value, mode);
}
diff --git a/packages/core/src/theme/useTheme.ts b/packages/core/src/theme/useTheme.ts
index ac5a3ccb39..66ee5886db 100644
--- a/packages/core/src/theme/useTheme.ts
+++ b/packages/core/src/theme/useTheme.ts
@@ -63,7 +63,7 @@ export interface UseThemeReturn {
* For tokens with [light, dark] tuples, returns the value matching
* the current mode. For single-value tokens, returns the value as-is.
*
- * Falls back to xdsTokenDefaults if the token isn't overridden by the theme.
+ * Falls back to tokenDefaults if the token isn't overridden by the theme.
*
* @example
* ```
@@ -75,7 +75,7 @@ export interface UseThemeReturn {
/**
* All tokens resolved for the current color mode.
*
- * Merges xdsTokenDefaults with the theme's overrides, resolving
+ * Merges tokenDefaults with the theme's overrides, resolving
* light-dark() values based on the effective color mode.
*
* Memoized — stable reference unless theme or mode changes.