@atlaskit/tokens 1.36.0 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/codemods/css-to-design-tokens/__tests__/css-to-design-tokens.test.tsx +489 -0
- package/codemods/css-to-design-tokens/__tests__/utils.test.tsx +145 -0
- package/codemods/css-to-design-tokens/lib/colors.tsx +71 -0
- package/codemods/css-to-design-tokens/lib/declaration.tsx +43 -0
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +336 -0
- package/codemods/css-to-design-tokens/lib/meta.tsx +173 -0
- package/codemods/css-to-design-tokens/lib/tokens.tsx +54 -0
- package/codemods/css-to-design-tokens/lib/value.tsx +85 -0
- package/codemods/css-to-design-tokens/transform.tsx +99 -0
- package/codemods/hypermod.config.tsx +9 -0
- package/codemods/theme-to-design-tokens/__tests__/theme-to-design-tokens.test.tsx +1104 -0
- package/codemods/theme-to-design-tokens/transform.tsx +628 -0
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +159 -0
- package/codemods/theme-to-design-tokens/utils/ast.tsx +46 -0
- package/codemods/theme-to-design-tokens/utils/color.tsx +45 -0
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +38 -0
- package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +326 -0
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +232 -0
- package/codemods/theme-to-design-tokens/utils/named-colors.tsx +150 -0
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +22 -0
- package/codemods/utils/tokens.tsx +376 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
jest.autoMockOff();
|
|
2
|
+
|
|
3
|
+
import jscodeshift from 'jscodeshift';
|
|
4
|
+
|
|
5
|
+
import codemod from '../transform';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
export async function withMockedConsoleWarn(fn: any) {
|
|
9
|
+
const originalWarn = console.warn;
|
|
10
|
+
const warn = jest.fn();
|
|
11
|
+
console.warn = warn;
|
|
12
|
+
|
|
13
|
+
await fn(warn);
|
|
14
|
+
|
|
15
|
+
console.warn = originalWarn;
|
|
16
|
+
}
|
|
17
|
+
/* eslint-enable no-console */
|
|
18
|
+
|
|
19
|
+
interface Options {
|
|
20
|
+
parser: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function applyTransform(
|
|
24
|
+
transform: any,
|
|
25
|
+
input: string,
|
|
26
|
+
options: Options = {
|
|
27
|
+
parser: 'tsx',
|
|
28
|
+
},
|
|
29
|
+
) {
|
|
30
|
+
const transformer = transform.default ? transform.default : transform;
|
|
31
|
+
const output = await transformer(
|
|
32
|
+
{ source: input },
|
|
33
|
+
{ jscodeshift: jscodeshift.withParser(options.parser) },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return (output || '').trim();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('theme-to-design-tokens', () => {
|
|
40
|
+
it('should ignore colors already wrapped in a token (object styles)', async () => {
|
|
41
|
+
const result = await applyTransform(
|
|
42
|
+
codemod,
|
|
43
|
+
`
|
|
44
|
+
import { token } from "@atlaskit/tokens";
|
|
45
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
46
|
+
|
|
47
|
+
css({
|
|
48
|
+
color: token("color.text.selected", B500),
|
|
49
|
+
backgroundColor: token("color.background.card", N500),
|
|
50
|
+
border: N500,
|
|
51
|
+
});`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(result).toMatchInlineSnapshot(`
|
|
55
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
56
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
57
|
+
|
|
58
|
+
css({
|
|
59
|
+
color: token(\\"color.text.selected\\", B500),
|
|
60
|
+
backgroundColor: token(\\"color.background.card\\", N500),
|
|
61
|
+
border: token(\\"color.border\\", N500),
|
|
62
|
+
});"
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should ignore colors already wrapped in a token (template literals)', async () => {
|
|
67
|
+
const result = await applyTransform(
|
|
68
|
+
codemod,
|
|
69
|
+
`
|
|
70
|
+
import { token } from \"@atlaskit/tokens";
|
|
71
|
+
const DragHandle = styled.div\`
|
|
72
|
+
background: \${token("surface.raised", colors.N20)};
|
|
73
|
+
color: \${token("color.text.subtlest", colors.N80)};
|
|
74
|
+
border: \${colors.N80};
|
|
75
|
+
\`;`,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(result).toMatchInlineSnapshot(`
|
|
79
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
80
|
+
const DragHandle = styled.div\`
|
|
81
|
+
background: \${token(\\"surface.raised\\", colors.N20)};
|
|
82
|
+
color: \${token(\\"color.text.subtlest\\", colors.N80)};
|
|
83
|
+
border: \${token(\\"color.border\\", colors.N80)};
|
|
84
|
+
\`;"
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should ignore colors already wrapped in a token (JSX Attributes)', async () => {
|
|
89
|
+
const result = await applyTransform(
|
|
90
|
+
codemod,
|
|
91
|
+
`
|
|
92
|
+
import { token } from "@atlaskit/tokens";
|
|
93
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
94
|
+
<WarningIcon
|
|
95
|
+
primaryColor={token("color.icon.warning", Y400)}
|
|
96
|
+
secondaryColor={Y400}
|
|
97
|
+
/>
|
|
98
|
+
`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(result).toMatchInlineSnapshot(`
|
|
102
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
103
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
104
|
+
<WarningIcon
|
|
105
|
+
primaryColor={token(\\"color.icon.warning\\", Y400)}
|
|
106
|
+
secondaryColor={token(\\"color.icon.warning\\", Y400)}
|
|
107
|
+
/>"
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should transform legacy tokens', async () => {
|
|
112
|
+
const result = await applyTransform(
|
|
113
|
+
codemod,
|
|
114
|
+
`
|
|
115
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
116
|
+
|
|
117
|
+
css({
|
|
118
|
+
color: B500,
|
|
119
|
+
backgroundColor: N500,
|
|
120
|
+
});`,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(result).toMatchInlineSnapshot(`
|
|
124
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
125
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
126
|
+
|
|
127
|
+
css({
|
|
128
|
+
color: token(\\"color.text.information\\", B500),
|
|
129
|
+
backgroundColor: token(\\"color.background.neutral.bold\\", N500),
|
|
130
|
+
});"
|
|
131
|
+
`);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should not transform non color css properties', async () => {
|
|
135
|
+
const result = await applyTransform(codemod, `css({ gap: '2px', });`);
|
|
136
|
+
|
|
137
|
+
expect(result).toMatchInlineSnapshot(`"css({ gap: '2px', });"`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should transform hard-coded tokens', async () => {
|
|
141
|
+
const result = await applyTransform(
|
|
142
|
+
codemod,
|
|
143
|
+
`
|
|
144
|
+
css({
|
|
145
|
+
color: '#eee',
|
|
146
|
+
backgroundColor: 'lightblue',
|
|
147
|
+
borderColor: '#FF0000',
|
|
148
|
+
});`,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(result).toMatchInlineSnapshot(`
|
|
152
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
153
|
+
css({
|
|
154
|
+
color: token(\\"color.text\\", '#eee'),
|
|
155
|
+
backgroundColor: token(\\"color.background.input\\", 'lightblue'),
|
|
156
|
+
borderColor: token(\\"color.border\\", '#FF0000'),
|
|
157
|
+
});"
|
|
158
|
+
`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should transform legacy tokens from default import', async () => {
|
|
162
|
+
const result = await applyTransform(
|
|
163
|
+
codemod,
|
|
164
|
+
`
|
|
165
|
+
import colors from '@atlaskit/theme/colors';
|
|
166
|
+
css({
|
|
167
|
+
color: colors.B500,
|
|
168
|
+
backgroundColor: colors.N500,
|
|
169
|
+
});`,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(result).toMatchInlineSnapshot(`
|
|
173
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
174
|
+
import colors from '@atlaskit/theme/colors';
|
|
175
|
+
css({
|
|
176
|
+
color: token(\\"color.text.information\\", colors.B500),
|
|
177
|
+
backgroundColor: token(\\"color.background.neutral.bold\\", colors.N500),
|
|
178
|
+
});"
|
|
179
|
+
`);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should transform typical surface/text colors', async () => {
|
|
183
|
+
const result = await applyTransform(
|
|
184
|
+
codemod,
|
|
185
|
+
`
|
|
186
|
+
const DragHandle = styled.div\`
|
|
187
|
+
background: \${colors.N20};
|
|
188
|
+
color: \${colors.N80};
|
|
189
|
+
\`;
|
|
190
|
+
`,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
expect(result).toMatchInlineSnapshot(`
|
|
194
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
195
|
+
const DragHandle = styled.div\`
|
|
196
|
+
background: \${token(\\"elevation.surface.overlay\\", colors.N20)};
|
|
197
|
+
color: \${token(\\"color.text.subtlest\\", colors.N80)};
|
|
198
|
+
\`;"
|
|
199
|
+
`);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should transform box shadow in template literals', async () => {
|
|
203
|
+
const result = await applyTransform(
|
|
204
|
+
codemod,
|
|
205
|
+
`
|
|
206
|
+
export const EnvironmentWrapper = styled.div\`
|
|
207
|
+
box-shadow: 0 0 1px \${colors.N60A};
|
|
208
|
+
\`;
|
|
209
|
+
`,
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
expect(result).toMatchInlineSnapshot(`
|
|
213
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
214
|
+
export const EnvironmentWrapper = styled.div\`
|
|
215
|
+
box-shadow: \${token(\\"elevation.shadow.raised\\", \`0 0 1px \${colors.N60A}\`)};
|
|
216
|
+
\`;"
|
|
217
|
+
`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('should transform comma-separated box shadow with a single replaceable color', async () => {
|
|
221
|
+
const result = await applyTransform(
|
|
222
|
+
codemod,
|
|
223
|
+
`
|
|
224
|
+
export const EnvironmentWrapper = styled.div\`
|
|
225
|
+
box-shadow: 0 0 1px \${colors.N60A},
|
|
226
|
+
2px 2px 1rem black;
|
|
227
|
+
\`;
|
|
228
|
+
`,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
expect(result).toMatchInlineSnapshot(`
|
|
232
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
233
|
+
export const EnvironmentWrapper = styled.div\`
|
|
234
|
+
box-shadow: \${token(\\"elevation.shadow.raised\\", \`0 0 1px \${colors.N60A},
|
|
235
|
+
2px 2px 1rem black\`)};
|
|
236
|
+
\`;"
|
|
237
|
+
`);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should warn about comma-separated box shadow when two colors are expressions', async () => {
|
|
241
|
+
await withMockedConsoleWarn(async (warn: any) => {
|
|
242
|
+
const result = await applyTransform(
|
|
243
|
+
codemod,
|
|
244
|
+
`
|
|
245
|
+
export const EnvironmentWrapper = styled.div\`
|
|
246
|
+
box-shadow: 0 0 1px \${colors.N60A},
|
|
247
|
+
2px 2px 1rem \${colors.N70A};
|
|
248
|
+
\`;
|
|
249
|
+
`,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
expect(result).toMatchInlineSnapshot(`
|
|
253
|
+
"export const EnvironmentWrapper = styled.div\`
|
|
254
|
+
box-shadow: 0 0 1px \${colors.N60A},
|
|
255
|
+
2px 2px 1rem \${colors.N70A};
|
|
256
|
+
\`;"
|
|
257
|
+
`);
|
|
258
|
+
|
|
259
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should not apply text tokens to background', async () => {
|
|
264
|
+
const result = await applyTransform(
|
|
265
|
+
codemod,
|
|
266
|
+
`
|
|
267
|
+
const EnvironmentWrapper = styled.div\`
|
|
268
|
+
background: \${colors.N0};
|
|
269
|
+
\`;
|
|
270
|
+
`,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(result).toMatchInlineSnapshot(`
|
|
274
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
275
|
+
const EnvironmentWrapper = styled.div\`
|
|
276
|
+
background: \${token(\\"elevation.surface\\", colors.N0)};
|
|
277
|
+
\`;"
|
|
278
|
+
`);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('should transform static colors in css properties', async () => {
|
|
282
|
+
const result = await applyTransform(
|
|
283
|
+
codemod,
|
|
284
|
+
`
|
|
285
|
+
import colors from '@atlaskit/theme/colors';
|
|
286
|
+
css({
|
|
287
|
+
color: '#eeeeee',
|
|
288
|
+
backgroundColor: 'red',
|
|
289
|
+
});`,
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
expect(result).toMatchInlineSnapshot(`
|
|
293
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
294
|
+
import colors from '@atlaskit/theme/colors';
|
|
295
|
+
css({
|
|
296
|
+
color: token(\\"color.text\\", '#eeeeee'),
|
|
297
|
+
backgroundColor: token(\\"color.background.danger\\", 'red'),
|
|
298
|
+
});"
|
|
299
|
+
`);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should skip non-colors in properties', async () => {
|
|
303
|
+
const result = await applyTransform(
|
|
304
|
+
codemod,
|
|
305
|
+
`
|
|
306
|
+
series.push({
|
|
307
|
+
name: "Processing time (ms)",
|
|
308
|
+
});`,
|
|
309
|
+
);
|
|
310
|
+
expect(result).toMatchInlineSnapshot(`
|
|
311
|
+
"series.push({
|
|
312
|
+
name: \\"Processing time (ms)\\",
|
|
313
|
+
});"
|
|
314
|
+
`);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('should transform static colors in styled.div template literals', async () => {
|
|
318
|
+
const result = await applyTransform(
|
|
319
|
+
codemod,
|
|
320
|
+
`
|
|
321
|
+
const SomeWrapper = styled.div\`
|
|
322
|
+
outline: 3px dashed #eee;
|
|
323
|
+
background-color: #fafafa;
|
|
324
|
+
\`;
|
|
325
|
+
`,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
expect(result).toMatchInlineSnapshot(`
|
|
329
|
+
"const SomeWrapper = styled.div\`
|
|
330
|
+
outline: 3px dashed var(--ds-surface-sunken, #eee);
|
|
331
|
+
background-color: var(--ds-background-input, #fafafa);
|
|
332
|
+
\`;"
|
|
333
|
+
`);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('should transform box-shadow in styled.div template literals', async () => {
|
|
337
|
+
const result = await applyTransform(
|
|
338
|
+
codemod,
|
|
339
|
+
`
|
|
340
|
+
export const LoginPaper = styled.div\`
|
|
341
|
+
box-shadow: #dcdcdc 0 0 10px;
|
|
342
|
+
\`;
|
|
343
|
+
`,
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
expect(result).toMatchInlineSnapshot(`
|
|
347
|
+
"export const LoginPaper = styled.div\`
|
|
348
|
+
box-shadow: var(--ds-shadow-raised, #dcdcdc 0 0 10px);
|
|
349
|
+
\`;"
|
|
350
|
+
`);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should transform static colors in plain template literals', async () => {
|
|
354
|
+
const result = await applyTransform(
|
|
355
|
+
codemod,
|
|
356
|
+
`
|
|
357
|
+
const StringValue = \`
|
|
358
|
+
background-color: #172B4D;
|
|
359
|
+
color: #ffffff;
|
|
360
|
+
\`;
|
|
361
|
+
`,
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
expect(result).toMatchInlineSnapshot(`
|
|
365
|
+
"const StringValue = \`
|
|
366
|
+
background-color: var(--ds-background-input, #172B4D);
|
|
367
|
+
color: var(--ds-surface, #ffffff);
|
|
368
|
+
\`;"
|
|
369
|
+
`);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('should transform static colors in constant declarations', async () => {
|
|
373
|
+
const result = await applyTransform(
|
|
374
|
+
codemod,
|
|
375
|
+
`
|
|
376
|
+
const FONT_COLOR = \`#172B4D\`;
|
|
377
|
+
const BG_COLOR = \"#FAFAFA\";
|
|
378
|
+
const DARK_PURPLE = '#5243AA';
|
|
379
|
+
`,
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
const expected = `import { token } from "@atlaskit/tokens";
|
|
383
|
+
const FONT_COLOR = token("color.text", \`#172B4D\`);
|
|
384
|
+
const BG_COLOR = token("color.text", "#FAFAFA");
|
|
385
|
+
const DARK_PURPLE = token("color.text.accent.purple", '#5243AA');`;
|
|
386
|
+
|
|
387
|
+
expect(result).toEqual(expected);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('should skip non-colors in expressions', async () => {
|
|
391
|
+
const result = await applyTransform(
|
|
392
|
+
codemod,
|
|
393
|
+
`
|
|
394
|
+
function getLink(start, limit) {
|
|
395
|
+
return "#start=" + start + "&limit=" + limit
|
|
396
|
+
}
|
|
397
|
+
`,
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
const expected = `function getLink(start, limit) {
|
|
401
|
+
return "#start=" + start + "&limit=" + limit
|
|
402
|
+
}`;
|
|
403
|
+
expect(result).toEqual(expected);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('should not transform static colors in constant declarations already transformed', async () => {
|
|
407
|
+
const result = await applyTransform(
|
|
408
|
+
codemod,
|
|
409
|
+
`
|
|
410
|
+
import { token } from "@atlaskit/tokens";
|
|
411
|
+
const FONT_COLOR = token("color.text", "#172B4D");
|
|
412
|
+
const BG_COLOR = token("color.text", "#FAFAFA");
|
|
413
|
+
const DARK_PURPLE = token("color.text.accent.purple", '#5243AA');
|
|
414
|
+
`,
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
const expected = `import { token } from "@atlaskit/tokens";
|
|
418
|
+
const FONT_COLOR = token("color.text", "#172B4D");
|
|
419
|
+
const BG_COLOR = token("color.text", "#FAFAFA");
|
|
420
|
+
const DARK_PURPLE = token("color.text.accent.purple", '#5243AA');`;
|
|
421
|
+
|
|
422
|
+
expect(result).toEqual(expected);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('should transform nested style blocks', async () => {
|
|
426
|
+
const result = await applyTransform(
|
|
427
|
+
codemod,
|
|
428
|
+
`
|
|
429
|
+
const dangerButton = css({
|
|
430
|
+
color: '#eeeeee',
|
|
431
|
+
backgroundColor: '#000000',
|
|
432
|
+
':hover': {
|
|
433
|
+
color: '#eeeaaa',
|
|
434
|
+
backgroundColor: '#000eee'
|
|
435
|
+
},
|
|
436
|
+
':active': {
|
|
437
|
+
color: '#eeeaaa',
|
|
438
|
+
backgroundColor: '#000eee'
|
|
439
|
+
},
|
|
440
|
+
':focus': {
|
|
441
|
+
color: '#eeeaaa',
|
|
442
|
+
backgroundColor: '#000eee'
|
|
443
|
+
}
|
|
444
|
+
});`,
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
expect(result).toMatchInlineSnapshot(`
|
|
448
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
449
|
+
const dangerButton = css({
|
|
450
|
+
color: token(\\"color.text.danger\\", '#eeeeee'),
|
|
451
|
+
backgroundColor: token(\\"color.background.danger\\", '#000000'),
|
|
452
|
+
':hover': {
|
|
453
|
+
color: token(\\"color.text.danger\\", '#eeeaaa'),
|
|
454
|
+
backgroundColor: token(\\"color.background.danger.hovered\\", '#000eee')
|
|
455
|
+
},
|
|
456
|
+
':active': {
|
|
457
|
+
color: token(\\"color.text.danger\\", '#eeeaaa'),
|
|
458
|
+
backgroundColor: token(\\"color.background.danger.pressed\\", '#000eee')
|
|
459
|
+
},
|
|
460
|
+
':focus': {
|
|
461
|
+
color: token(\\"color.text.danger\\", '#eeeaaa'),
|
|
462
|
+
backgroundColor: token(\\"color.background.danger\\", '#000eee')
|
|
463
|
+
}
|
|
464
|
+
});"
|
|
465
|
+
`);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('should transform nested style objects', async () => {
|
|
469
|
+
const result = await applyTransform(
|
|
470
|
+
codemod,
|
|
471
|
+
`
|
|
472
|
+
import { B100, B300, B400, B50, N10, N20, N30, N40, N70, R300 } from '@atlaskit/theme/colors';
|
|
473
|
+
const themeColors = {
|
|
474
|
+
borderColor: {
|
|
475
|
+
rest: N40,
|
|
476
|
+
disabled: N20,
|
|
477
|
+
checked: B400,
|
|
478
|
+
active: B50,
|
|
479
|
+
invalid: R300,
|
|
480
|
+
invalidAndChecked: R300,
|
|
481
|
+
focused: B100,
|
|
482
|
+
hovered: N40,
|
|
483
|
+
hoveredAndChecked: B300,
|
|
484
|
+
},
|
|
485
|
+
boxColor: {
|
|
486
|
+
rest: N10,
|
|
487
|
+
disabled: N20,
|
|
488
|
+
active: B50,
|
|
489
|
+
hoveredAndChecked: B300,
|
|
490
|
+
hovered: N30,
|
|
491
|
+
checked: B400,
|
|
492
|
+
},
|
|
493
|
+
tickIconColor: {
|
|
494
|
+
disabledAndChecked: N70,
|
|
495
|
+
activeAndChecked: B400,
|
|
496
|
+
checked: N10,
|
|
497
|
+
},
|
|
498
|
+
};`,
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
expect(result).toMatchInlineSnapshot(`
|
|
502
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
503
|
+
import { B100, B300, B400, B50, N10, N20, N30, N40, N70, R300 } from '@atlaskit/theme/colors';
|
|
504
|
+
const themeColors = {
|
|
505
|
+
borderColor: {
|
|
506
|
+
rest: token(\\"color.border\\", N40),
|
|
507
|
+
disabled: token(\\"color.border.disabled\\", N20),
|
|
508
|
+
checked: token(\\"color.border.information\\", B400),
|
|
509
|
+
active: token(\\"color.border.information\\", B50),
|
|
510
|
+
invalid: token(\\"color.border.danger\\", R300),
|
|
511
|
+
invalidAndChecked: token(\\"color.border.danger\\", R300),
|
|
512
|
+
focused: token(\\"color.border.information\\", B100),
|
|
513
|
+
hovered: token(\\"color.border\\", N40),
|
|
514
|
+
hoveredAndChecked: token(\\"color.border.information\\", B300),
|
|
515
|
+
},
|
|
516
|
+
boxColor: {
|
|
517
|
+
rest: token(\\"color.text\\", N10),
|
|
518
|
+
disabled: token(\\"color.text.disabled\\", N20),
|
|
519
|
+
active: token(\\"color.background.information.pressed\\", B50),
|
|
520
|
+
hoveredAndChecked: token(\\"color.text.information\\", B300),
|
|
521
|
+
hovered: token(\\"color.text\\", N30),
|
|
522
|
+
checked: token(\\"color.text.information\\", B400),
|
|
523
|
+
},
|
|
524
|
+
tickIconColor: {
|
|
525
|
+
disabledAndChecked: token(\\"color.icon.disabled\\", N70),
|
|
526
|
+
activeAndChecked: token(\\"color.icon.information\\", B400),
|
|
527
|
+
checked: token(\\"color.icon\\", N10),
|
|
528
|
+
},
|
|
529
|
+
};"
|
|
530
|
+
`);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it('should transform abstract objects', async () => {
|
|
534
|
+
const result = await applyTransform(
|
|
535
|
+
codemod,
|
|
536
|
+
`
|
|
537
|
+
import { G400, G300, N20 } from '@atlaskit/theme/colors';
|
|
538
|
+
import { colors } from '@atlaskit/theme';
|
|
539
|
+
const colorMap = {
|
|
540
|
+
light: {
|
|
541
|
+
backgroundColorChecked: G400,
|
|
542
|
+
backgroundColorCheckedHover: G300,
|
|
543
|
+
backgroundColorCheckedPressed: colors.G500,
|
|
544
|
+
backgroundColorCheckedDisabled: N20,
|
|
545
|
+
}
|
|
546
|
+
}`,
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
expect(result).toMatchInlineSnapshot(`
|
|
550
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
551
|
+
import { G400, G300, N20 } from '@atlaskit/theme/colors';
|
|
552
|
+
import { colors } from '@atlaskit/theme';
|
|
553
|
+
const colorMap = {
|
|
554
|
+
light: {
|
|
555
|
+
backgroundColorChecked: token(\\"color.background.success\\", G400),
|
|
556
|
+
backgroundColorCheckedHover: token(\\"color.background.success.hovered\\", G300),
|
|
557
|
+
backgroundColorCheckedPressed: token(\\"color.background.success.pressed\\", colors.G500),
|
|
558
|
+
backgroundColorCheckedDisabled: token(\\"color.background.disabled\\", N20),
|
|
559
|
+
}
|
|
560
|
+
}"
|
|
561
|
+
`);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it('should transform deep abstract objects', async () => {
|
|
565
|
+
const result = await applyTransform(
|
|
566
|
+
codemod,
|
|
567
|
+
`
|
|
568
|
+
import { G400, G300, N20 } from '@atlaskit/theme/colors';
|
|
569
|
+
const colorMap = {
|
|
570
|
+
light: {
|
|
571
|
+
background: {
|
|
572
|
+
color: {
|
|
573
|
+
checked: {
|
|
574
|
+
resting: G400,
|
|
575
|
+
hover: G300,
|
|
576
|
+
disabled: N20,
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}`,
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
expect(result).toMatchInlineSnapshot(`
|
|
585
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
586
|
+
import { G400, G300, N20 } from '@atlaskit/theme/colors';
|
|
587
|
+
const colorMap = {
|
|
588
|
+
light: {
|
|
589
|
+
background: {
|
|
590
|
+
color: {
|
|
591
|
+
checked: {
|
|
592
|
+
resting: token(\\"color.background.success\\", G400),
|
|
593
|
+
hover: token(\\"color.background.success.hovered\\", G300),
|
|
594
|
+
disabled: token(\\"color.background.disabled\\", N20),
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}"
|
|
600
|
+
`);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('should not object keys with legacy named colors', async () => {
|
|
604
|
+
const result = await applyTransform(
|
|
605
|
+
codemod,
|
|
606
|
+
`
|
|
607
|
+
import { background, subtleText, primary } from '@atlaskit/theme/colors';
|
|
608
|
+
const colorMap = {
|
|
609
|
+
background: background,
|
|
610
|
+
subtleText: subtleText,
|
|
611
|
+
primary,
|
|
612
|
+
}`,
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
expect(result).toMatchInlineSnapshot(`
|
|
616
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
617
|
+
import { background, subtleText, primary } from '@atlaskit/theme/colors';
|
|
618
|
+
const colorMap = {
|
|
619
|
+
background: token(\\"color.background.input\\", background),
|
|
620
|
+
subtleText: token(\\"color.text.subtlest\\", subtleText),
|
|
621
|
+
primary: token(\\"color.text.brand\\", primary),
|
|
622
|
+
}"
|
|
623
|
+
`);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('should transform tokens via css prop', async () => {
|
|
627
|
+
const result = await applyTransform(
|
|
628
|
+
codemod,
|
|
629
|
+
`
|
|
630
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
631
|
+
|
|
632
|
+
const Button = () => (
|
|
633
|
+
<button css={
|
|
634
|
+
css({
|
|
635
|
+
color: B500,
|
|
636
|
+
backgroundColor: N500,
|
|
637
|
+
})
|
|
638
|
+
}>Submit</button>
|
|
639
|
+
)`,
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
expect(result).toMatchInlineSnapshot(`
|
|
643
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
644
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
645
|
+
|
|
646
|
+
const Button = () => (
|
|
647
|
+
<button css={
|
|
648
|
+
css({
|
|
649
|
+
color: token(\\"color.text.information\\", B500),
|
|
650
|
+
backgroundColor: token(\\"color.background.neutral.bold\\", N500),
|
|
651
|
+
})
|
|
652
|
+
}>Submit</button>
|
|
653
|
+
)"
|
|
654
|
+
`);
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it('should transform tokens via css prop and object styles', async () => {
|
|
658
|
+
const result = await applyTransform(
|
|
659
|
+
codemod,
|
|
660
|
+
`
|
|
661
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
662
|
+
|
|
663
|
+
const Button = () => (
|
|
664
|
+
<button css={{
|
|
665
|
+
color: B500,
|
|
666
|
+
backgroundColor: N500,
|
|
667
|
+
}}>Submit</button>
|
|
668
|
+
)`,
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
expect(result).toMatchInlineSnapshot(`
|
|
672
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
673
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
674
|
+
|
|
675
|
+
const Button = () => (
|
|
676
|
+
<button css={{
|
|
677
|
+
color: token(\\"color.text.information\\", B500),
|
|
678
|
+
backgroundColor: token(\\"color.background.neutral.bold\\", N500),
|
|
679
|
+
}}>Submit</button>
|
|
680
|
+
)"
|
|
681
|
+
`);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
it('should transform colors used in template literals', async () => {
|
|
685
|
+
const result = await applyTransform(
|
|
686
|
+
codemod,
|
|
687
|
+
`
|
|
688
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
689
|
+
|
|
690
|
+
const Button = styled.button\`
|
|
691
|
+
color: \${B500};
|
|
692
|
+
background-color: \${N500};
|
|
693
|
+
\`;`,
|
|
694
|
+
);
|
|
695
|
+
|
|
696
|
+
expect(result).toMatchInlineSnapshot(`
|
|
697
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
698
|
+
import { B500, N500 } from '@atlaskit/theme/colors';
|
|
699
|
+
|
|
700
|
+
const Button = styled.button\`
|
|
701
|
+
color: \${token(\\"color.text.information\\", B500)};
|
|
702
|
+
background-color: \${token(\\"color.background.neutral.bold\\", N500)};
|
|
703
|
+
\`;"
|
|
704
|
+
`);
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
it('should correctly handle mixed identifiers and color expressions in template literals', async () => {
|
|
708
|
+
// This is a contrived example, because usually people don't mix both forms
|
|
709
|
+
// in a single template, but it can happen with other expressions than
|
|
710
|
+
// colors, so this serves as a nice minimal example for the intended
|
|
711
|
+
// behavior.
|
|
712
|
+
const result = await applyTransform(
|
|
713
|
+
codemod,
|
|
714
|
+
`
|
|
715
|
+
const Button = styled.button\`
|
|
716
|
+
color: \${B500};
|
|
717
|
+
background-color: \${colors.N500};
|
|
718
|
+
\`;`,
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
expect(result).toMatchInlineSnapshot(`
|
|
722
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
723
|
+
const Button = styled.button\`
|
|
724
|
+
color: \${token(\\"color.text.information\\", B500)};
|
|
725
|
+
background-color: \${token(\\"color.background.neutral.bold\\", colors.N500)};
|
|
726
|
+
\`;"
|
|
727
|
+
`);
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it('should skip over non-color expressions in template literals', async () => {
|
|
731
|
+
// It's a more realistic example of the same behavior as tested in the
|
|
732
|
+
// previous test.
|
|
733
|
+
const result = await applyTransform(
|
|
734
|
+
codemod,
|
|
735
|
+
`
|
|
736
|
+
export const MessageContainer = styled.section\`
|
|
737
|
+
background-color: \${colors.N0};
|
|
738
|
+
border-radius: \${borderRadius}px;
|
|
739
|
+
color: \${colors.N500};
|
|
740
|
+
padding: \${gridSize() * 2}px;
|
|
741
|
+
margin: \${gridSize() / 2}px 1px;
|
|
742
|
+
\${elevation.e100};
|
|
743
|
+
\`;`,
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
expect(result).toMatchInlineSnapshot(`
|
|
747
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
748
|
+
export const MessageContainer = styled.section\`
|
|
749
|
+
background-color: \${token(\\"elevation.surface\\", colors.N0)};
|
|
750
|
+
border-radius: \${borderRadius}px;
|
|
751
|
+
color: \${token(\\"color.text.subtle\\", colors.N500)};
|
|
752
|
+
padding: \${gridSize() * 2}px;
|
|
753
|
+
margin: \${gridSize() / 2}px 1px;
|
|
754
|
+
\${elevation.e100};
|
|
755
|
+
\`;"
|
|
756
|
+
`);
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
it('should replace template literals that have hard-coded colors and arbitrary expressions', async () => {
|
|
760
|
+
const result = await applyTransform(
|
|
761
|
+
codemod,
|
|
762
|
+
`
|
|
763
|
+
const size = {
|
|
764
|
+
mobileMin: '320px',
|
|
765
|
+
mobileMax: '767px',
|
|
766
|
+
};
|
|
767
|
+
export const device = {
|
|
768
|
+
mobile: \`(min-width: \${size.mobileMin}) and (max-width: \${size.mobileMax})\`,
|
|
769
|
+
};
|
|
770
|
+
const ButtonContainer = styled.div\`
|
|
771
|
+
@media \${device.mobile} {
|
|
772
|
+
z-index: 2;
|
|
773
|
+
background-color: #fff;
|
|
774
|
+
box-shadow: 0px -5px 7px -1px rgba(39, 37, 40, 0.16);
|
|
775
|
+
}
|
|
776
|
+
\`;
|
|
777
|
+
`,
|
|
778
|
+
);
|
|
779
|
+
expect(result).toMatchInlineSnapshot(`
|
|
780
|
+
"const size = {
|
|
781
|
+
mobileMin: '320px',
|
|
782
|
+
mobileMax: '767px',
|
|
783
|
+
};
|
|
784
|
+
export const device = {
|
|
785
|
+
mobile: \`(min-width: \${size.mobileMin}) and (max-width: \${size.mobileMax})\`,
|
|
786
|
+
};
|
|
787
|
+
const ButtonContainer = styled.div\`
|
|
788
|
+
@media \${device.mobile} {
|
|
789
|
+
z-index: 2;
|
|
790
|
+
background-color: var(--ds-surface, #fff);
|
|
791
|
+
box-shadow: var(--ds-shadow-raised, 0px -5px 7px -1px rgba(39, 37, 40, 0.16));
|
|
792
|
+
}
|
|
793
|
+
\`;"
|
|
794
|
+
`);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it('should transform colors used as props', async () => {
|
|
798
|
+
const result = await applyTransform(
|
|
799
|
+
codemod,
|
|
800
|
+
`
|
|
801
|
+
import React from 'react';
|
|
802
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
803
|
+
|
|
804
|
+
const PresenceWrapper = () => (
|
|
805
|
+
<Presence borderColor={R400} />
|
|
806
|
+
);`,
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
expect(result).toMatchInlineSnapshot(`
|
|
810
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
811
|
+
import React from 'react';
|
|
812
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
813
|
+
|
|
814
|
+
const PresenceWrapper = () => (
|
|
815
|
+
<Presence borderColor={token(\\"color.border.danger\\", R400)} />
|
|
816
|
+
);"
|
|
817
|
+
`);
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it('should transform disable styles object', async () => {
|
|
821
|
+
const result = await applyTransform(
|
|
822
|
+
codemod,
|
|
823
|
+
`
|
|
824
|
+
import React from 'react';
|
|
825
|
+
import { N40 } from '@atlaskit/theme/colors';
|
|
826
|
+
|
|
827
|
+
const disabledStyles = css({
|
|
828
|
+
background: N40,
|
|
829
|
+
});
|
|
830
|
+
`,
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
expect(result).toMatchInlineSnapshot(`
|
|
834
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
835
|
+
import React from 'react';
|
|
836
|
+
import { N40 } from '@atlaskit/theme/colors';
|
|
837
|
+
|
|
838
|
+
const disabledStyles = css({
|
|
839
|
+
background: token(\\"color.background.disabled\\", N40),
|
|
840
|
+
});"
|
|
841
|
+
`);
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it('should transform styled bold brand', async () => {
|
|
845
|
+
const result = await applyTransform(
|
|
846
|
+
codemod,
|
|
847
|
+
`
|
|
848
|
+
import React from 'react';
|
|
849
|
+
import { B400, B300, B500 } from '@atlaskit/theme/colors';
|
|
850
|
+
|
|
851
|
+
styled.div\`
|
|
852
|
+
background-color: \${B400};
|
|
853
|
+
|
|
854
|
+
:hover {
|
|
855
|
+
background-color: \${B300};
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
:active {
|
|
859
|
+
background: \${B500};
|
|
860
|
+
}
|
|
861
|
+
\`;
|
|
862
|
+
`,
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
expect(result).toMatchInlineSnapshot(`
|
|
866
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
867
|
+
import React from 'react';
|
|
868
|
+
import { B400, B300, B500 } from '@atlaskit/theme/colors';
|
|
869
|
+
|
|
870
|
+
styled.div\`
|
|
871
|
+
background-color: \${token(\\"color.background.information.bold\\", B400)};
|
|
872
|
+
|
|
873
|
+
:hover {
|
|
874
|
+
background-color: \${token(\\"color.background.information.bold.hovered\\", B300)};
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
:active {
|
|
878
|
+
background: \${token(\\"color.background.information.bold.pressed\\", B500)};
|
|
879
|
+
}
|
|
880
|
+
\`;"
|
|
881
|
+
`);
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
it('should transform colors using property context (low-accuracy)', async () => {
|
|
885
|
+
const result = await applyTransform(
|
|
886
|
+
codemod,
|
|
887
|
+
`
|
|
888
|
+
import { B50, R400 } from '@atlaskit/theme/colors';
|
|
889
|
+
|
|
890
|
+
const cols = {
|
|
891
|
+
1: 'green',
|
|
892
|
+
2: R400,
|
|
893
|
+
3: B50,
|
|
894
|
+
};`,
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
expect(result).toMatchInlineSnapshot(`
|
|
898
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
899
|
+
import { B50, R400 } from '@atlaskit/theme/colors';
|
|
900
|
+
|
|
901
|
+
const cols = {
|
|
902
|
+
1: token(\\"color.text.accent.green\\", 'green'),
|
|
903
|
+
2: token(\\"color.background.danger.bold\\", R400),
|
|
904
|
+
3: token(\\"color.text.information\\", B50),
|
|
905
|
+
};"
|
|
906
|
+
`);
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
it('should transform border properties', async () => {
|
|
910
|
+
const result = await applyTransform(
|
|
911
|
+
codemod,
|
|
912
|
+
`
|
|
913
|
+
import colors from '@atlaskit/theme/colors';
|
|
914
|
+
|
|
915
|
+
const Wrapper = styled.div\`
|
|
916
|
+
border-top: 1px solid \${colors.N300A};
|
|
917
|
+
border-bottom: 1px solid \${colors.N300A};
|
|
918
|
+
\``,
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
expect(result).toMatchInlineSnapshot(`
|
|
922
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
923
|
+
import colors from '@atlaskit/theme/colors';
|
|
924
|
+
|
|
925
|
+
const Wrapper = styled.div\`
|
|
926
|
+
border-top: 1px solid \${token(\\"color.border\\", colors.N300A)};
|
|
927
|
+
border-bottom: 1px solid \${token(\\"color.border\\", colors.N300A)};
|
|
928
|
+
\`"
|
|
929
|
+
`);
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
it('should correctly transform icon colors (error)', async () => {
|
|
933
|
+
const result = await applyTransform(
|
|
934
|
+
codemod,
|
|
935
|
+
`<ErrorIcon primaryColor={colors.R400} />`,
|
|
936
|
+
);
|
|
937
|
+
|
|
938
|
+
expect(result).toMatchInlineSnapshot(`
|
|
939
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
940
|
+
<ErrorIcon primaryColor={token(\\"color.icon.danger\\", colors.R400)} />"
|
|
941
|
+
`);
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
it('should correctly transform icon colors (success)', async () => {
|
|
945
|
+
const result = await applyTransform(
|
|
946
|
+
codemod,
|
|
947
|
+
`<TickIcon primaryColor={colors.G400} />`,
|
|
948
|
+
);
|
|
949
|
+
|
|
950
|
+
expect(result).toMatchInlineSnapshot(`
|
|
951
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
952
|
+
<TickIcon primaryColor={token(\\"color.icon.success\\", colors.G400)} />"
|
|
953
|
+
`);
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
it('should correctly transform icon colors (warning)', async () => {
|
|
957
|
+
const result = await applyTransform(
|
|
958
|
+
codemod,
|
|
959
|
+
`<WarningIcon primaryColor={colors.Y400} />`,
|
|
960
|
+
);
|
|
961
|
+
|
|
962
|
+
expect(result).toMatchInlineSnapshot(`
|
|
963
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
964
|
+
<WarningIcon primaryColor={token(\\"color.icon.warning\\", colors.Y400)} />"
|
|
965
|
+
`);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
it('should correctly transform icon colors (error)', async () => {
|
|
969
|
+
const result = await applyTransform(
|
|
970
|
+
codemod,
|
|
971
|
+
`
|
|
972
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
973
|
+
|
|
974
|
+
<ErrorIcon primaryColor={R400} />
|
|
975
|
+
`,
|
|
976
|
+
);
|
|
977
|
+
|
|
978
|
+
expect(result).toMatchInlineSnapshot(`
|
|
979
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
980
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
981
|
+
|
|
982
|
+
<ErrorIcon primaryColor={token(\\"color.icon.danger\\", R400)} />"
|
|
983
|
+
`);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
it('should correctly transform icon colors (success)', async () => {
|
|
987
|
+
const result = await applyTransform(
|
|
988
|
+
codemod,
|
|
989
|
+
`
|
|
990
|
+
import { G400 } from '@atlaskit/theme/colors';
|
|
991
|
+
<TickIcon primaryColor={G400} />
|
|
992
|
+
`,
|
|
993
|
+
);
|
|
994
|
+
|
|
995
|
+
expect(result).toMatchInlineSnapshot(`
|
|
996
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
997
|
+
import { G400 } from '@atlaskit/theme/colors';
|
|
998
|
+
<TickIcon primaryColor={token(\\"color.icon.success\\", G400)} />"
|
|
999
|
+
`);
|
|
1000
|
+
});
|
|
1001
|
+
|
|
1002
|
+
it('should correctly transform icon colors (warning)', async () => {
|
|
1003
|
+
const result = await applyTransform(
|
|
1004
|
+
codemod,
|
|
1005
|
+
`
|
|
1006
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
1007
|
+
<WarningIcon primaryColor={Y400} />`,
|
|
1008
|
+
);
|
|
1009
|
+
|
|
1010
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1011
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
1012
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
1013
|
+
<WarningIcon primaryColor={token(\\"color.icon.warning\\", Y400)} />"
|
|
1014
|
+
`);
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
it('should correctly transform icon colors (warning)', async () => {
|
|
1018
|
+
const result = await applyTransform(
|
|
1019
|
+
codemod,
|
|
1020
|
+
`
|
|
1021
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
1022
|
+
<WarningIcon primaryColor={Y400} />`,
|
|
1023
|
+
);
|
|
1024
|
+
|
|
1025
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1026
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
1027
|
+
import { Y400 } from '@atlaskit/theme/colors';
|
|
1028
|
+
<WarningIcon primaryColor={token(\\"color.icon.warning\\", Y400)} />"
|
|
1029
|
+
`);
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
it('should correctly transform text colors (subtlest)', async () => {
|
|
1033
|
+
const result = await applyTransform(
|
|
1034
|
+
codemod,
|
|
1035
|
+
`
|
|
1036
|
+
const Example = styled.strong\`
|
|
1037
|
+
color: \${colors.N300};
|
|
1038
|
+
\`;`,
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1042
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
1043
|
+
const Example = styled.strong\`
|
|
1044
|
+
color: \${token(\\"color.text.subtlest\\", colors.N300)};
|
|
1045
|
+
\`;"
|
|
1046
|
+
`);
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
it('should correctly transform text colors (subtle)', async () => {
|
|
1050
|
+
const result = await applyTransform(
|
|
1051
|
+
codemod,
|
|
1052
|
+
`
|
|
1053
|
+
const Example = styled.strong\`
|
|
1054
|
+
color: \${colors.N500};
|
|
1055
|
+
\`;`,
|
|
1056
|
+
);
|
|
1057
|
+
|
|
1058
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1059
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
1060
|
+
const Example = styled.strong\`
|
|
1061
|
+
color: \${token(\\"color.text.subtle\\", colors.N500)};
|
|
1062
|
+
\`;"
|
|
1063
|
+
`);
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
it('should correctly transform text colors (default)', async () => {
|
|
1067
|
+
const result = await applyTransform(
|
|
1068
|
+
codemod,
|
|
1069
|
+
`
|
|
1070
|
+
const Example = styled.strong\`
|
|
1071
|
+
color: \${colors.N800};
|
|
1072
|
+
\`;`,
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1076
|
+
"import { token } from \\"@atlaskit/tokens\\";
|
|
1077
|
+
const Example = styled.strong\`
|
|
1078
|
+
color: \${token(\\"color.text\\", colors.N800)};
|
|
1079
|
+
\`;"
|
|
1080
|
+
`);
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
it('should not transform default argument objects', async () => {
|
|
1084
|
+
const result = await applyTransform(
|
|
1085
|
+
codemod,
|
|
1086
|
+
`const Tag = ({ text: text, testId = TAG_TYPE_TEST_ID }) => null`,
|
|
1087
|
+
);
|
|
1088
|
+
|
|
1089
|
+
expect(result).toMatchInlineSnapshot(
|
|
1090
|
+
`"const Tag = ({ text: text, testId = TAG_TYPE_TEST_ID }) => null"`,
|
|
1091
|
+
);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
it('should not transform default argument objects', async () => {
|
|
1095
|
+
const result = await applyTransform(
|
|
1096
|
+
codemod,
|
|
1097
|
+
`function Tags ({ text: text, testId = TAG_TYPE_TEST_ID }) {}`,
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
expect(result).toMatchInlineSnapshot(
|
|
1101
|
+
`"function Tags ({ text: text, testId = TAG_TYPE_TEST_ID }) {}"`,
|
|
1102
|
+
);
|
|
1103
|
+
});
|
|
1104
|
+
});
|