@atlaskit/css 0.10.7 → 0.12.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
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/css
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#177956](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/177956)
|
|
8
|
+
[`124aac4a851f1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/124aac4a851f1) -
|
|
9
|
+
Added metric typography tokens which can be used via the CSS `font` shorthand.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 0.11.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#172429](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/172429)
|
|
20
|
+
[`efcc283cecdfe`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/efcc283cecdfe) -
|
|
21
|
+
Added metric typography tokens which can be used via the CSS `font` shorthand.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
|
|
3
27
|
## 0.10.7
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -96,7 +96,15 @@ function replaceXcssWithCssMap(
|
|
|
96
96
|
let firstUsagePath: ASTPath<core.Node> | null = null;
|
|
97
97
|
const styleVariables = new Set<string>();
|
|
98
98
|
const variableDependencies = new Map<string, Set<string>>();
|
|
99
|
-
|
|
99
|
+
const inlineXcssUsages: Array<{
|
|
100
|
+
path: ASTPath<core.CallExpression>;
|
|
101
|
+
keyName: string;
|
|
102
|
+
jsxAttribute: ASTPath<core.JSXAttribute>;
|
|
103
|
+
componentName: string;
|
|
104
|
+
variableName: string;
|
|
105
|
+
}> = [];
|
|
106
|
+
|
|
107
|
+
// First pass: collect all xcss variable declarations
|
|
100
108
|
source
|
|
101
109
|
.find(j.CallExpression, {
|
|
102
110
|
// get all xcss calls
|
|
@@ -137,11 +145,49 @@ function replaceXcssWithCssMap(
|
|
|
137
145
|
variableDependencies.set(variableName, dependencies);
|
|
138
146
|
}
|
|
139
147
|
}
|
|
148
|
+
} else {
|
|
149
|
+
// This is an inline xcss call - check if it's inside a JSX attribute
|
|
150
|
+
let current = path.parentPath;
|
|
151
|
+
let jsxElement: ASTPath<core.JSXElement> | null = null;
|
|
152
|
+
|
|
153
|
+
while (current) {
|
|
154
|
+
if (
|
|
155
|
+
current.node.type === 'JSXAttribute' &&
|
|
156
|
+
current.node.name.type === 'JSXIdentifier' &&
|
|
157
|
+
current.node.name.name === 'xcss'
|
|
158
|
+
) {
|
|
159
|
+
// Found inline xcss usage - now find the JSX element
|
|
160
|
+
let elementCurrent = current.parentPath;
|
|
161
|
+
while (elementCurrent) {
|
|
162
|
+
if (elementCurrent.node.type === 'JSXElement') {
|
|
163
|
+
jsxElement = elementCurrent as ASTPath<core.JSXElement>;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
elementCurrent = elementCurrent.parentPath;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (jsxElement && jsxElement.node.openingElement.name.type === 'JSXIdentifier') {
|
|
170
|
+
const componentName = jsxElement.node.openingElement.name.name;
|
|
171
|
+
const variableName = `${componentName.toLowerCase()}Styles`;
|
|
172
|
+
const keyName = 'root';
|
|
173
|
+
|
|
174
|
+
inlineXcssUsages.push({
|
|
175
|
+
path,
|
|
176
|
+
keyName,
|
|
177
|
+
jsxAttribute: current as ASTPath<core.JSXAttribute>,
|
|
178
|
+
componentName,
|
|
179
|
+
variableName,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
current = current.parentPath;
|
|
185
|
+
}
|
|
140
186
|
}
|
|
141
187
|
}
|
|
142
188
|
});
|
|
143
189
|
|
|
144
|
-
// find the first usage of any style variable
|
|
190
|
+
// find the first usage of any style variable or inline xcss
|
|
145
191
|
source.find(j.Identifier).forEach((path) => {
|
|
146
192
|
if (
|
|
147
193
|
styleVariables.has(path.node.name) &&
|
|
@@ -156,7 +202,15 @@ function replaceXcssWithCssMap(
|
|
|
156
202
|
}
|
|
157
203
|
});
|
|
158
204
|
|
|
159
|
-
//
|
|
205
|
+
// Check for inline xcss usage as well for first usage
|
|
206
|
+
if (
|
|
207
|
+
inlineXcssUsages.length > 0 &&
|
|
208
|
+
(!firstUsagePath || inlineXcssUsages[0].path.node.loc?.start)
|
|
209
|
+
) {
|
|
210
|
+
firstUsagePath = inlineXcssUsages[0].path;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Process variable xcss declarations
|
|
160
214
|
source
|
|
161
215
|
.find(j.CallExpression, {
|
|
162
216
|
callee: {
|
|
@@ -202,7 +256,40 @@ function replaceXcssWithCssMap(
|
|
|
202
256
|
}
|
|
203
257
|
});
|
|
204
258
|
|
|
205
|
-
//
|
|
259
|
+
// Process inline xcss usages - create separate cssMap for each
|
|
260
|
+
const cssMapDeclarations: core.VariableDeclaration[] = [];
|
|
261
|
+
|
|
262
|
+
inlineXcssUsages.forEach(({ path, keyName, jsxAttribute, componentName, variableName }) => {
|
|
263
|
+
const args = path.node.arguments;
|
|
264
|
+
if (args.length === 1 && args[0].type === 'ObjectExpression') {
|
|
265
|
+
// Create separate cssMap declaration for each inline xcss
|
|
266
|
+
const cssMapObject = j.objectProperty(
|
|
267
|
+
j.identifier(keyName),
|
|
268
|
+
ensureSelectorAmpersand(j, args[0]),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const cssMapVariableDeclaration = j.variableDeclaration('const', [
|
|
272
|
+
j.variableDeclarator(
|
|
273
|
+
j.identifier(variableName),
|
|
274
|
+
j.callExpression(j.identifier('cssMap'), [j.objectExpression([cssMapObject])]),
|
|
275
|
+
),
|
|
276
|
+
]);
|
|
277
|
+
|
|
278
|
+
cssMapDeclarations.push(cssMapVariableDeclaration);
|
|
279
|
+
|
|
280
|
+
// Update the JSX attribute to use the cssMap reference
|
|
281
|
+
jsxAttribute.node.value = j.jsxExpressionContainer(
|
|
282
|
+
j.memberExpression(j.identifier(variableName), j.identifier(keyName)),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Track first xcss call if not already set
|
|
286
|
+
if (!firstXcssPath) {
|
|
287
|
+
firstXcssPath = path;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// create new cssMap with the combined xcss object properties (for variable declarations)
|
|
206
293
|
if (cssMapProperties.length > 0) {
|
|
207
294
|
const cssMapObject = j.objectExpression(cssMapProperties);
|
|
208
295
|
const cssMapVariableDeclaration = j.variableDeclaration('const', [
|
|
@@ -212,44 +299,46 @@ function replaceXcssWithCssMap(
|
|
|
212
299
|
),
|
|
213
300
|
]);
|
|
214
301
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
302
|
+
cssMapDeclarations.unshift(cssMapVariableDeclaration);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Insert all cssMap declarations
|
|
306
|
+
if (cssMapDeclarations.length > 0 && firstUsagePath) {
|
|
307
|
+
const programBody = source.get().node.program.body;
|
|
308
|
+
let insertIndex = 0;
|
|
309
|
+
|
|
310
|
+
// find the last variable declaration that any style depends on
|
|
311
|
+
let lastDependencyIndex = -1;
|
|
312
|
+
for (let i = 0; i < programBody.length; i++) {
|
|
313
|
+
const node = programBody[i];
|
|
314
|
+
if (node.type === 'VariableDeclaration') {
|
|
315
|
+
const varName = node.declarations[0]?.id.name;
|
|
316
|
+
if (varName) {
|
|
317
|
+
// check if this variable is a dependency of any style
|
|
318
|
+
for (const [, deps] of variableDependencies.entries()) {
|
|
319
|
+
if (deps.has(varName)) {
|
|
320
|
+
lastDependencyIndex = i;
|
|
321
|
+
break;
|
|
233
322
|
}
|
|
234
323
|
}
|
|
235
324
|
}
|
|
236
325
|
}
|
|
326
|
+
}
|
|
237
327
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
programBody.splice(insertIndex, 0, cssMapVariableDeclaration);
|
|
328
|
+
// insert after the last dependency
|
|
329
|
+
if (lastDependencyIndex !== -1) {
|
|
330
|
+
insertIndex = lastDependencyIndex + 1;
|
|
331
|
+
} else {
|
|
332
|
+
// if no dependencies, find the first non-import/type declaration
|
|
333
|
+
insertIndex = programBody.findIndex(
|
|
334
|
+
(node: { type: string }) =>
|
|
335
|
+
node.type !== 'ImportDeclaration' &&
|
|
336
|
+
node.type !== 'TypeAlias' &&
|
|
337
|
+
node.type !== 'InterfaceDeclaration',
|
|
338
|
+
);
|
|
252
339
|
}
|
|
340
|
+
|
|
341
|
+
programBody.splice(insertIndex, 0, ...cssMapDeclarations);
|
|
253
342
|
}
|
|
254
343
|
|
|
255
344
|
// First handle backgroundColor transformation for Box components
|
|
@@ -387,19 +476,35 @@ function replaceXcssWithCssMap(
|
|
|
387
476
|
if (value && value.type === 'JSXExpressionContainer') {
|
|
388
477
|
const expression = value.expression;
|
|
389
478
|
if (expression.type === 'Identifier') {
|
|
390
|
-
|
|
391
|
-
|
|
479
|
+
if (styleVariables.has(expression.name)) {
|
|
480
|
+
// <Box xcss={buttonStyles} /> => <Box xcss={styles.button} />
|
|
481
|
+
path.node.value = j.jsxExpressionContainer(
|
|
482
|
+
j.memberExpression(
|
|
483
|
+
j.identifier('styles'),
|
|
484
|
+
j.identifier(getCssMapKey(expression.name)),
|
|
485
|
+
),
|
|
486
|
+
);
|
|
487
|
+
}
|
|
392
488
|
} else if (expression.type === 'ArrayExpression') {
|
|
393
|
-
// <Box xcss={[baseStyles, otherStyles]} />
|
|
489
|
+
// <Box xcss={[baseStyles, otherStyles]} /> => <Box xcss={[styles.base, styles.other]} />
|
|
394
490
|
expression.elements.forEach((element) => {
|
|
395
|
-
if (element?.type === 'Identifier') {
|
|
396
|
-
|
|
491
|
+
if (element?.type === 'Identifier' && styleVariables.has(element.name)) {
|
|
492
|
+
const memberExpression = j.memberExpression(
|
|
493
|
+
j.identifier('styles'),
|
|
494
|
+
j.identifier(getCssMapKey(element.name)),
|
|
495
|
+
);
|
|
496
|
+
// Replace the identifier with the member expression
|
|
497
|
+
Object.assign(element, memberExpression);
|
|
397
498
|
} else if (
|
|
398
|
-
// <Box xcss={condition && styles} />
|
|
499
|
+
// <Box xcss={condition && styles} /> => <Box xcss={condition && styles.root} />
|
|
399
500
|
element?.type === 'LogicalExpression' &&
|
|
400
|
-
element.right.type === 'Identifier'
|
|
501
|
+
element.right.type === 'Identifier' &&
|
|
502
|
+
styleVariables.has(element.right.name)
|
|
401
503
|
) {
|
|
402
|
-
element.right
|
|
504
|
+
element.right = j.memberExpression(
|
|
505
|
+
j.identifier('styles'),
|
|
506
|
+
j.identifier(getCssMapKey(element.right.name)),
|
|
507
|
+
);
|
|
403
508
|
}
|
|
404
509
|
});
|
|
405
510
|
}
|
|
@@ -908,7 +908,7 @@ export type BorderRadius = keyof typeof borderRadiusMap;
|
|
|
908
908
|
|
|
909
909
|
/**
|
|
910
910
|
* THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
911
|
-
* @codegen <<SignedSource::
|
|
911
|
+
* @codegen <<SignedSource::2c0cffbebdab4e28fe2b45925623e523>>
|
|
912
912
|
* @codegenId typography
|
|
913
913
|
* @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
|
|
914
914
|
* @codegenParams ["fontSize", "fontWeight", "fontFamily", "lineHeight", "body", "ui"]
|
|
@@ -964,6 +964,18 @@ export const fontMap = {
|
|
|
964
964
|
'font.heading.xxsmall',
|
|
965
965
|
'normal 600 12px/16px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
966
966
|
),
|
|
967
|
+
'font.metric.large': token(
|
|
968
|
+
'font.metric.large',
|
|
969
|
+
'normal 653 28px/32px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
970
|
+
),
|
|
971
|
+
'font.metric.medium': token(
|
|
972
|
+
'font.metric.medium',
|
|
973
|
+
'normal 653 24px/28px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
974
|
+
),
|
|
975
|
+
'font.metric.small': token(
|
|
976
|
+
'font.metric.small',
|
|
977
|
+
'normal 653 16px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
978
|
+
),
|
|
967
979
|
};
|
|
968
980
|
|
|
969
981
|
export type Font = keyof typeof fontMap;
|
|
@@ -1008,7 +1020,7 @@ export type FontFamily = keyof typeof fontFamilyMap;
|
|
|
1008
1020
|
|
|
1009
1021
|
/**
|
|
1010
1022
|
* THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
1011
|
-
* @codegen <<SignedSource::
|
|
1023
|
+
* @codegen <<SignedSource::c207cc4caf0794de5f13707a9c28451f>>
|
|
1012
1024
|
* @codegenId text
|
|
1013
1025
|
* @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
|
|
1014
1026
|
* @codegenDependency ../../../primitives/scripts/codegen-file-templates/dimensions.tsx <<SignedSource::cc9b3f12104c6ede803da6a42daac0b0>>
|
|
@@ -1044,6 +1056,23 @@ export const textWeightMap = {
|
|
|
1044
1056
|
|
|
1045
1057
|
export type TextWeight = keyof typeof textWeightMap;
|
|
1046
1058
|
|
|
1059
|
+
export const metricTextSizeMap = {
|
|
1060
|
+
large: token(
|
|
1061
|
+
'font.metric.large',
|
|
1062
|
+
'normal 653 28px/32px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
1063
|
+
),
|
|
1064
|
+
medium: token(
|
|
1065
|
+
'font.metric.medium',
|
|
1066
|
+
'normal 653 24px/28px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
1067
|
+
),
|
|
1068
|
+
small: token(
|
|
1069
|
+
'font.metric.small',
|
|
1070
|
+
'normal 653 16px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, "Helvetica Neue", sans-serif',
|
|
1071
|
+
),
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
export type MetricTextSize = keyof typeof metricTextSizeMap;
|
|
1075
|
+
|
|
1047
1076
|
/**
|
|
1048
1077
|
* @codegenEnd
|
|
1049
1078
|
*/
|
|
@@ -1211,6 +1240,7 @@ type FontFamilyToken = keyof typeof fontFamilyMap;
|
|
|
1211
1240
|
type FontToken = keyof typeof fontMap;
|
|
1212
1241
|
type TextWeightToken = keyof typeof textWeightMap;
|
|
1213
1242
|
type TextSizeToken = keyof typeof textSizeMap;
|
|
1243
|
+
type MetricTextSizeToken = keyof typeof metricTextSizeMap;
|
|
1214
1244
|
type SpacingStyleMap = Record<SpacingProperty, Record<SpacingToken, SerializedStyles>>;
|
|
1215
1245
|
type BackgroundColorStyleMap = Record<BackgroundColorToken, SerializedStyles>;
|
|
1216
1246
|
type SurfaceColorStyleMap = Record<SurfaceColorToken, SerializedStyles>;
|
|
@@ -1220,6 +1250,7 @@ type FontFamilyStyleMap = Record<FontFamilyToken, SerializedStyles>;
|
|
|
1220
1250
|
type FontStyleMap = Record<FontToken, SerializedStyles>;
|
|
1221
1251
|
type TextWeightStyleMap = Record<TextWeightToken, SerializedStyles>;
|
|
1222
1252
|
type TextStyleMap = Record<TextSizeToken, SerializedStyles>;
|
|
1253
|
+
type MetricTextStyleMap = Record<MetricTextSizeToken, SerializedStyles>;
|
|
1223
1254
|
|
|
1224
1255
|
export const paddingStylesMap: SpacingStyleMap = spacingProperties.reduce(
|
|
1225
1256
|
(styleMap, spacingProperty: SpacingProperty) => {
|
|
@@ -1269,3 +1300,8 @@ export const surfaceColorStylesMap: SurfaceColorStyleMap = getSerializedStylesMa
|
|
|
1269
1300
|
|
|
1270
1301
|
export const isSurfaceColorToken = (color: unknown): color is SurfaceColorToken =>
|
|
1271
1302
|
surfaceColorMap[color as SurfaceColorToken] !== undefined;
|
|
1303
|
+
|
|
1304
|
+
export const metricTextSizeStylesMap: MetricTextStyleMap = getSerializedStylesMap(
|
|
1305
|
+
'font',
|
|
1306
|
+
metricTextSizeMap,
|
|
1307
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Style components backed by Atlassian Design System design tokens powered by Compiled CSS-in-JS.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"./test-utils": "./src/test-utils/index.tsx"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@atlaskit/tokens": "^5.
|
|
52
|
+
"@atlaskit/tokens": "^5.4.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@compiled/react": "^0.18.3"
|
|
55
55
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@af/visual-regression": "workspace:^",
|
|
61
61
|
"@atlaskit/button": "^23.2.0",
|
|
62
62
|
"@atlaskit/ds-lib": "^4.0.0",
|
|
63
|
-
"@atlaskit/primitives": "^14.
|
|
63
|
+
"@atlaskit/primitives": "^14.10.0",
|
|
64
64
|
"@emotion/react": "^11.7.1",
|
|
65
65
|
"@testing-library/react": "^13.4.0",
|
|
66
66
|
"@types/jscodeshift": "^0.11.0",
|