Skip to content

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

TypeScript

fix(docsite): remove accent palette expansion (#6794)

rubyycheung796bcc286686
diff --git a/apps/docsite/src/__tests__/theme-editor-color-authoring.test.ts b/apps/docsite/src/__tests__/theme-editor-color-authoring.test.ts
new file mode 100644
index 0000000000..3728faf75d
--- /dev/null
+++ b/apps/docsite/src/__tests__/theme-editor-color-authoring.test.ts
@@ -0,0 +1,48 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {readFileSync} from 'node:fs';
+import {dirname, join} from 'node:path';
+import {fileURLToPath} from 'node:url';
+import {describe, expect, it} from 'vitest';
+
+const testDirectory = dirname(fileURLToPath(import.meta.url));
+const themeEditorDirectory = join(
+ testDirectory,
+ '../app/playground/themeEditor',
+);
+const editorSource = readFileSync(
+ join(themeEditorDirectory, 'ThemeEditor.tsx'),
+ 'utf8',
+);
+const baseStylesSource = readFileSync(
+ join(themeEditorDirectory, 'BaseStylesPanel.tsx'),
+ 'utf8',
+);
+const helperSource = readFileSync(
+ join(themeEditorDirectory, 'helpers.ts'),
+ 'utf8',
+);
+
+describe('theme editor color authoring', () => {
+ it('does not expose or invoke accent-based palette expansion', () => {
+ expect(baseStylesSource).not.toContain('Create from accent');
+ expect(editorSource).not.toContain('expandColorScale');
+ expect(editorSource).not.toContain('getExpandedColorScale');
+ expect(helperSource).not.toContain('expandColorScale');
+ expect(helperSource).not.toContain('getExpandedColorScale');
+ });
+
+ it('keeps direct editing for the visible semantic color foundations', () => {
+ for (const token of [
+ '--color-accent',
+ '--color-neutral',
+ '--color-background-card',
+ '--color-background-surface',
+ '--color-background-body',
+ '--color-background-muted',
+ '--color-text-primary',
+ ]) {
+ expect(baseStylesSource).toContain(`'${token}'`);
+ }
+ });
+});
diff --git a/apps/docsite/src/__tests__/theme-helpers.test.ts b/apps/docsite/src/__tests__/theme-helpers.test.ts
deleted file mode 100644
index 41e1cadb29..0000000000
--- a/apps/docsite/src/__tests__/theme-helpers.test.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-import {describe, it, expect} from 'vitest';
-import {getExpandedColorScale} from '../app/playground/themeEditor/helpers';
-
-describe('theme editor helpers - getExpandedColorScale', () => {
- it('omits --color-accent from output to prevent overriding user picker selection', () => {
- const scale = getExpandedColorScale('#0064E0');
- expect(scale).not.toHaveProperty('--color-accent');
- });
-
- it('correctly generates other derived semantic color tokens', () => {
- const scale = getExpandedColorScale('#0064E0');
- const expectedKeys = [
- '--color-accent-muted',
- '--color-neutral',
- '--color-background-surface',
- '--color-background-body',
- '--color-text-primary',
- '--color-text-secondary',
- '--shadow-inset-hover',
- '--shadow-inset-selected',
- ];
- for (const key of expectedKeys) {
- expect(scale).toHaveProperty(key);
- expect(typeof scale[key]).toBe('string');
- }
- });
-
- it('properly falls back on invalid hex accent color', () => {
- const scale = getExpandedColorScale('invalid-hex');
- // Should fall back to black, which produces valid tokens
- expect(scale).toHaveProperty('--color-neutral');
- expect(typeof scale['--color-neutral']).toBe('string');
- });
-});
diff --git a/apps/docsite/src/app/playground/themeEditor/BaseStylesPanel.tsx b/apps/docsite/src/app/playground/themeEditor/BaseStylesPanel.tsx
index 747e18840b..ce40702a4e 100644
--- a/apps/docsite/src/app/playground/themeEditor/BaseStylesPanel.tsx
+++ b/apps/docsite/src/app/playground/themeEditor/BaseStylesPanel.tsx
@@ -9,7 +9,6 @@ import {VStack, HStack} from '@astryxdesign/core/Stack';
import {Grid} from '@astryxdesign/core/Grid';
import {Selector} from '@astryxdesign/core/Selector';
import {NumberInput} from '@astryxdesign/core/NumberInput';
-import {Switch} from '@astryxdesign/core/Switch';
import {ToggleButton, ToggleButtonGroup} from '@astryxdesign/core/ToggleButton';
import {Tooltip} from '@astryxdesign/core/Tooltip';
import {Icon} from '@astryxdesign/core/Icon';
@@ -23,8 +22,6 @@ import {useLiveNumberInput} from '@/lib/useLiveNumberInput';
const styles = stylex.create({
fullWidthField: {width: '100%'},
- // 4px below the accent header, on top of the section's own gap.
- headerSpace: {marginBottom: 'var(--spacing-1)'},
});
interface ScaleOption {
@@ -149,7 +146,6 @@ interface BaseStylesPanelProps {
sizeBase: number;
durationStep: number;
activePreset: string | null;
- autoPickColors: boolean;
onTokenChange: (name: string, value: string) => void;
onApplyTypeScale: (base: number, ratio: number) => void;
onApplyRadiusScale: (base: number) => void;
@@ -157,8 +153,6 @@ interface BaseStylesPanelProps {
onApplySizeScale: (base: number) => void;
onApplyDurationScale: (multiplier: number) => void;
onApplyUnifiedPreset: (key: string) => void;
- onSetAutoPickColors: (val: boolean) => void;
- onExpandColorScale: (accent: string) => void;
}
export function BaseStylesPanel({
@@ -171,7 +165,6 @@ export function BaseStylesPanel({
sizeBase,
durationStep,
activePreset,
- autoPickColors,
onTokenChange,
onApplyTypeScale,
onApplyRadiusScale,
@@ -179,8 +172,6 @@ export function BaseStylesPanel({
onApplySizeScale,
onApplyDurationScale,
onApplyUnifiedPreset,
- onSetAutoPickColors,
- onExpandColorScale,
}: BaseStylesPanelProps) {
// Reflect the active token values in the typography controls. Fonts map
// directly to a token; the type scale ratio is derived from the raw
@@ -306,64 +297,27 @@ export function BaseStylesPanel({
<VStack gap={5}>
{/* Color */}
<VStack gap={3}>
- <HStack vAlign="center" justify="between" xstyle={styles.headerSpace}>
- <Text type="label" color="secondary">
- Create from accent
- </Text>
- <Switch
- label="Create from accent"
- isLabelHidden
- value={autoPickColors}
- onChange={val => {
- onSetAutoPickColors(val);
- if (val) {
- const accentRaw = tokens['--color-accent'] || '';
- const parsed = accentRaw.match(
- /^light-dark\(([^,]+),\s*([^)]+)\)$/,
- );
- const accentHex = parsed ? parsed[1].trim() : accentRaw;
- if (accentHex && accentHex.startsWith('#')) {
- onExpandColorScale(accentHex);
- }
- }
- }}
- />
- </HStack>
+ <Text type="label" color="secondary">
+ Colors
+ </Text>
<VStack gap={0}>
- <ColorSwatch
- tokenName="--color-accent"
- value={tokens['--color-accent'] || ''}
- onChange={(name, value) => {
- onTokenChange(name, value);
- if (autoPickColors) {
- const parsed = value.match(
- /^light-dark\(([^,]+),\s*([^)]+)\)$/,
- );
- const hex = parsed ? parsed[1].trim() : value;
- if (hex && hex.startsWith('#') && hex.length >= 7) {
- onExpandColorScale(hex);
- }
- }
- }}
- mode={mode}
- />
- {!autoPickColors &&
- [
- '--color-neutral',
- '--color-background-card',
- '--color-background-surface',
- '--color-background-body',
- '--color-background-muted',
- '--color-text-primary',
- ].map(tokenName => (
- <ColorSwatch
- key={tokenName}
- tokenName={tokenName}
- value={tokens[tokenName] || ''}
- onChange={onTokenChange}
- mode={mode}
- />
- ))}
+ {[
+ '--color-accent',
+ '--color-neutral',
+ '--color-background-card',
+ '--color-background-surface',
+ '--color-background-body',
+ '--color-background-muted',
+ '--color-text-primary',
+ ].map(tokenName => (
+ <ColorSwatch
+ key={tokenName}
+ tokenName={tokenName}
+ value={tokens[tokenName] || ''}
+ onChange={onTokenChange}
+ mode={mode}
+ />
+ ))}
</VStack>
</VStack>
diff --git a/apps/docsite/src/app/playground/themeEditor/ThemeEditor.tsx b/apps/docsite/src/app/playground/themeEditor/ThemeEditor.tsx
index 3235a68948..7df953458b 100644
--- a/apps/docsite/src/app/playground/themeEditor/ThemeEditor.tsx
+++ b/apps/docsite/src/app/playground/themeEditor/ThemeEditor.tsx
@@ -21,7 +21,6 @@ import {
defineTheme,
expandTypeScale,
expandRadiusScale,
- expandColorScale,
colorDefaults,
spacingDefaults,
radiusDefaults,
@@ -48,7 +47,6 @@ import {
buildComponentOverrides,
buildSpacingScale,
mergeComponentStyleMaps,
- getExpandedColorScale,
} from './helpers';
const s = stylex.create({
@@ -112,7 +110,6 @@ export function ThemeEditor({
const [durationStep, setDurationStep] = useState(1);
// A unified preset is only "active" once the user explicitly applies one.
const [activePreset, setActivePreset] = useState<string | null>(null);
- const [autoPickColors, setAutoPickColors] = useState(false);
const [customOverrides, setCustomOverrides] = useState<CustomOverride[]>([]);
const currentTheme = useMemo(() => {
@@ -225,11 +222,6 @@ export function ThemeEditor({
}));
}, []);
- const handleExpandColorScale = useCallback((accentHex: string) => {
- const derived = getExpandedColorScale(accentHex);
- setTokens(prev => ({...prev, ...derived}));
- }, []);
-
return (
<VStack xstyle={s.root}>
{/* Self-load theme fonts so the editor's controls render in the loaded
@@ -256,7 +248,6 @@ export function ThemeEditor({
sizeBase={sizeBase}
durationStep={durationStep}
activePreset={activePreset}
- autoPickColors={autoPickColors}
onTokenChange={handleTokenChange}
onApplyTypeScale={applyTypeScale}
onApplyRadiusScale={applyRadiusScale}
@@ -264,8 +255,6 @@ export function ThemeEditor({
onApplySizeScale={applySizeScale}
onApplyDurationScale={applyDurationScale}
onApplyUnifiedPreset={applyUnifiedPreset}
- onSetAutoPickColors={setAutoPickColors}
- onExpandColorScale={handleExpandColorScale}
/>
)}
{panelTab === 'components' && (
diff --git a/apps/docsite/src/app/playground/themeEditor/helpers.ts b/apps/docsite/src/app/playground/themeEditor/helpers.ts
index 4672ec7d8f..3513270154 100644
--- a/apps/docsite/src/app/playground/themeEditor/helpers.ts
+++ b/apps/docsite/src/app/playground/themeEditor/helpers.ts
@@ -1,7 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import {COMPONENT_VAR_TO_OVERRIDE, COMPONENT_VAR_NAMES} from './constants';
-import {expandColorScale, expandRadiusScale} from '@astryxdesign/core/theme';
+import {expandRadiusScale} from '@astryxdesign/core/theme';
export function parseLightDark(
value: string,
@@ -288,31 +288,3 @@ export function generateThemeCode(
lines.push('});');
return lines.join('\n');
}
-
-export function getExpandedColorScale(
- accentHex: string,
-): Record<string, string> {
- const derived = expandColorScale({accent: accentHex}) as Record<
- string,
- string
- >;
- // Do not override the user's custom picker selection for `--color-accent` itself
- delete derived['--color-accent'];
- let hex = accentHex.replace('#', '');
- // Normalize 3-char short hex (e.g. "f00") to 6-char ("ff0000")
- if (hex.length === 3) {
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
- }
- // Guard against invalid hex — fall back to black
- if (hex.length !== 6 || !/^[0-9a-fA-F]{6}$/.test(hex)) {
- hex = '000000';
- }
- const r = parseInt(hex.slice(0, 2), 16);
- const g = parseInt(hex.slice(2, 4), 16);
- const b = parseInt(hex.slice(4, 6), 16);
- derived['--shadow-inset-hover'] =
- `inset 0px 0px 0px 2px rgba(${r}, ${g}, ${b}, 0.3)`;
- derived['--shadow-inset-selected'] =
- `inset 0px 0px 0px 2px rgba(${r}, ${g}, ${b}, 0.5)`;
- return derived;
-}