Skip to content

Commit 4806683

Browse files
authored
chore: Add reference tokens and replace legacy color tokens in style dictionary (#3952)
1 parent becf284 commit 4806683

22 files changed

+703
-398
lines changed

build-tools/eslint/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
module.exports.rules = {
44
'ban-files': require('./ban-files'),
55
'prefer-live-region': require('./prefer-live-region'),
6+
'no-legacy-tokens': require('./no-legacy-tokens'),
67
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
const LEGACY_TOKEN_PATTERN = /\{color(Grey|Blue|Green|Red|Yellow)\d+\}/g;
5+
const REFERENCE_TOKEN_SUGGESTIONS = {
6+
colorGrey: 'colorNeutral',
7+
colorBlue: 'colorPrimary or colorInfo',
8+
colorGreen: 'colorSuccess',
9+
colorRed: 'colorError',
10+
colorYellow: 'colorWarning',
11+
};
12+
13+
module.exports = {
14+
meta: {
15+
type: 'problem',
16+
messages: {
17+
'no-legacy-tokens':
18+
'Direct palette token {{token}} is deprecated. Use reference tokens like {{suggestion}} instead.',
19+
},
20+
docs: {
21+
description: 'Prevents use of legacy color palette tokens in favor of semantic reference tokens.',
22+
},
23+
fixable: 'code',
24+
},
25+
create(context) {
26+
return {
27+
Literal(node) {
28+
if (typeof node.value === 'string') {
29+
const matches = node.value.match(LEGACY_TOKEN_PATTERN);
30+
if (matches) {
31+
matches.forEach(token => {
32+
const colorFamily = token.match(/color(Grey|Blue|Green|Red|Yellow)/)?.[1];
33+
const suggestion = REFERENCE_TOKEN_SUGGESTIONS[`color${colorFamily}`] || 'semantic reference tokens';
34+
35+
context.report({
36+
node,
37+
messageId: 'no-legacy-tokens',
38+
data: { token, suggestion },
39+
});
40+
});
41+
}
42+
}
43+
},
44+
TemplateElement(node) {
45+
const matches = node.value.raw.match(LEGACY_TOKEN_PATTERN);
46+
if (matches) {
47+
matches.forEach(token => {
48+
const colorFamily = token.match(/color(Grey|Blue|Green|Red|Yellow)/)?.[1];
49+
const suggestion = REFERENCE_TOKEN_SUGGESTIONS[`color${colorFamily}`] || 'semantic reference tokens';
50+
51+
context.report({
52+
node,
53+
messageId: 'no-legacy-tokens',
54+
data: { token, suggestion },
55+
});
56+
});
57+
}
58+
},
59+
};
60+
},
61+
};

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export default tsEslint.config(
133133
],
134134
},
135135
],
136+
'@cloudscape-design/components/no-legacy-tokens': 'error',
136137
},
137138
},
138139
{

style-dictionary/classic/color-charts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { StyleDictionary } from '../utils/interfaces.js';
77
import { tokens as parentTokens } from '../visual-refresh/color-charts.js';
88

99
const tokens: StyleDictionary.ColorChartsDictionary = {
10-
colorChartsLineGrid: { dark: '{colorGrey700}' },
11-
colorChartsLineTick: { dark: '{colorGrey700}' },
12-
colorChartsLineAxis: { dark: '{colorGrey700}' },
10+
colorChartsLineGrid: { dark: '{colorNeutral700}' },
11+
colorChartsLineTick: { dark: '{colorNeutral700}' },
12+
colorChartsLineAxis: { dark: '{colorNeutral700}' },
1313
};
1414

1515
const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = merge(

style-dictionary/classic/color-palette.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import merge from 'lodash/merge.js';
44

5+
import { expandColorDictionary } from '../utils/index.js';
56
import { StyleDictionary } from '../utils/interfaces.js';
67
import { tokens as parentTokens } from '../visual-refresh/color-palette.js';
78

9+
/**
10+
* @deprecated These color palette tokens are deprecated and may be removed in a future version.
11+
* Use semantic reference tokens instead:
12+
* - colorGrey* → colorNeutral*
13+
* - colorBlue* → colorPrimary* or colorInfo*
14+
* - colorRed* → colorError*
15+
* - colorGreen* → colorSuccess*
16+
* - colorYellow* → colorWarning*
17+
*
18+
* Reference tokens provide better semantic meaning and consistency across themes.
19+
*/
820
const tokens: StyleDictionary.ColorPaletteDictionary = {
921
colorBlue50: '#f1faff',
1022
colorBlue200: '#99cbe4',
@@ -38,6 +50,50 @@ const tokens: StyleDictionary.ColorPaletteDictionary = {
3850
colorYellow900: '#906806',
3951
};
4052

41-
const expandedTokens: StyleDictionary.ExpandedGlobalScopeDictionary = merge({}, parentTokens, tokens);
53+
const referenceTokens: StyleDictionary.ReferenceDictionary = {
54+
colorPrimary50: tokens.colorBlue50,
55+
colorPrimary200: tokens.colorBlue200,
56+
colorPrimary300: tokens.colorBlue300,
57+
colorPrimary400: tokens.colorBlue400,
58+
colorPrimary600: tokens.colorBlue600,
59+
colorPrimary700: tokens.colorBlue700,
60+
colorPrimary1000: tokens.colorBlue1000,
61+
colorNeutral100: tokens.colorGrey100,
62+
colorNeutral200: tokens.colorGrey200,
63+
colorNeutral250: tokens.colorGrey250,
64+
colorNeutral300: tokens.colorGrey300,
65+
colorNeutral400: tokens.colorGrey400,
66+
colorNeutral450: tokens.colorGrey450,
67+
colorNeutral500: tokens.colorGrey500,
68+
colorNeutral600: tokens.colorGrey600,
69+
colorNeutral650: tokens.colorGrey650,
70+
colorNeutral700: tokens.colorGrey700,
71+
colorNeutral750: tokens.colorGrey750,
72+
colorNeutral800: tokens.colorGrey800,
73+
colorNeutral850: tokens.colorGrey850,
74+
colorNeutral950: tokens.colorGrey950,
75+
colorError50: tokens.colorRed50,
76+
colorError400: tokens.colorRed400,
77+
colorError600: tokens.colorRed600,
78+
colorError1000: tokens.colorRed1000,
79+
colorInfo50: tokens.colorBlue50,
80+
colorInfo300: tokens.colorBlue300,
81+
colorInfo400: tokens.colorBlue400,
82+
colorInfo600: tokens.colorBlue600,
83+
colorInfo1000: tokens.colorBlue1000,
84+
colorSuccess50: tokens.colorGreen50,
85+
colorSuccess500: tokens.colorGreen500,
86+
colorSuccess600: tokens.colorGreen600,
87+
colorSuccess1000: tokens.colorGreen1000,
88+
colorWarning900: tokens.colorYellow900,
89+
};
90+
91+
const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = merge(
92+
{},
93+
parentTokens,
94+
tokens,
95+
expandColorDictionary(referenceTokens)
96+
);
4297

4398
export { expandedTokens as tokens };
99+
export const mode: StyleDictionary.ModeIdentifier = 'color';

style-dictionary/classic/color-severity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { StyleDictionary } from '../utils/interfaces.js';
77
import { tokens as parentTokens } from '../visual-refresh/color-severity.js';
88

99
const tokens: StyleDictionary.ColorSeverityDictionary = {
10-
colorTextNotificationSeverityMedium: { light: '{colorBlack}', dark: '{colorGrey950}' },
10+
colorTextNotificationSeverityMedium: { light: '{colorBlack}', dark: '{colorNeutral950}' },
1111
};
1212

1313
const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = merge(

0 commit comments

Comments
 (0)