@atlaskit/css 0.6.0 → 0.6.1

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,14 @@
1
1
  # @atlaskit/css
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#160054](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/160054)
8
+ [`a85c8b06aad62`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a85c8b06aad62) -
9
+ Updates to the 0.5.2-primitives-emotion-to-compiled codemod to group imports from
10
+ @atlaskit/primitives.
11
+
3
12
  ## 0.6.0
4
13
 
5
14
  ### Minor Changes
@@ -50,8 +50,6 @@ const styleMaps = {
50
50
  export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
51
51
  const base = j(fileInfo.source);
52
52
 
53
- addJsxPragma(j, base);
54
-
55
53
  // replace xcss with cssMap
56
54
  const xcssSpecifier = getImportSpecifier(j, base, 'xcss');
57
55
  if (!xcssSpecifier) {
@@ -62,6 +60,8 @@ export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API,
62
60
 
63
61
  updateImports(j, base);
64
62
 
63
+ addJsxPragma(j, base);
64
+
65
65
  return base.toSource();
66
66
  }
67
67
 
@@ -221,20 +221,34 @@ function ensureSelectorAmpersand(j: core.JSCodeshift, objectExpression: core.Obj
221
221
  }
222
222
 
223
223
  function updateImports(j: core.JSCodeshift, source: ReturnType<typeof j>) {
224
- // remove xcss import
224
+ // remove xcss import and collect primitives to import
225
+ const primitivesToImport = new Set<string>();
225
226
  source
226
227
  .find(j.ImportDeclaration)
227
- .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === '@atlaskit/primitives')
228
+ .filter((path: ASTPath<ImportDeclaration>) => {
229
+ const importSource = path.node.source.value as string;
230
+ return (
231
+ importSource === '@atlaskit/primitives' || importSource.startsWith('@atlaskit/primitives/')
232
+ );
233
+ })
228
234
  .forEach((path) => {
229
235
  if (path.node.specifiers) {
230
- path.node.specifiers = path.node.specifiers.filter(
231
- (specifier) => specifier.local?.name !== 'xcss',
232
- );
233
- if (path.node.specifiers.length === 0) {
234
- // if no specifiers remain, remove the import
235
- j(path).remove();
236
- }
236
+ path.node.specifiers.forEach((specifier) => {
237
+ if (specifier.type === 'ImportSpecifier' && specifier.imported) {
238
+ const importedName = specifier.imported.name;
239
+ if (importedName !== 'xcss') {
240
+ primitivesToImport.add(importedName);
241
+ }
242
+ } else if (specifier.type === 'ImportDefaultSpecifier') {
243
+ // handle deep imports like `import Anchor from '@atlaskit/primitives/anchor'`
244
+ if (specifier.local) {
245
+ primitivesToImport.add(specifier.local.name);
246
+ }
247
+ }
248
+ });
237
249
  }
250
+ // remove the import declaration
251
+ j(path).remove();
238
252
  });
239
253
 
240
254
  const importsNeeded = {
@@ -245,18 +259,17 @@ function updateImports(j: core.JSCodeshift, source: ReturnType<typeof j>) {
245
259
 
246
260
  // check existing imports
247
261
  source.find(j.ImportDeclaration).forEach((path) => {
248
- switch (path.node.source.value) {
262
+ const importSource = path.node.source.value as string;
263
+ switch (importSource) {
249
264
  case '@atlaskit/css':
250
- if (path.node.specifiers) {
251
- path.node.specifiers.forEach((specifier) => {
252
- if (specifier.local?.name === 'cssMap') {
253
- importsNeeded.cssMap = true;
254
- }
255
- if (specifier.local?.name === 'jsx') {
256
- importsNeeded.jsx = true;
257
- }
258
- });
259
- }
265
+ path.node.specifiers?.forEach((specifier) => {
266
+ if (specifier.local?.name === 'cssMap') {
267
+ importsNeeded.cssMap = true;
268
+ }
269
+ if (specifier.local?.name === 'jsx') {
270
+ importsNeeded.jsx = true;
271
+ }
272
+ });
260
273
  break;
261
274
  case '@atlaskit/tokens':
262
275
  importsNeeded.token = true;
@@ -264,7 +277,17 @@ function updateImports(j: core.JSCodeshift, source: ReturnType<typeof j>) {
264
277
  case '@emotion/react':
265
278
  // remove the jsx import from @emotion/react
266
279
  path.node.specifiers = path.node.specifiers?.filter(
267
- (specifier) => j.ImportSpecifier.check(specifier) && specifier.imported.name !== 'jsx',
280
+ (specifier) => !(j.ImportSpecifier.check(specifier) && specifier.imported.name === 'jsx'),
281
+ );
282
+ if (path.node.specifiers?.length === 0) {
283
+ j(path).remove();
284
+ }
285
+ break;
286
+ case 'react':
287
+ // remove default import React from 'react' if not needed
288
+ path.node.specifiers = path.node.specifiers?.filter(
289
+ (specifier) =>
290
+ !(specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name === 'React'),
268
291
  );
269
292
  if (path.node.specifiers?.length === 0) {
270
293
  j(path).remove();
@@ -275,15 +298,47 @@ function updateImports(j: core.JSCodeshift, source: ReturnType<typeof j>) {
275
298
 
276
299
  const newImports: ImportDeclaration[] = [];
277
300
 
278
- if (!importsNeeded.cssMap || !importsNeeded.jsx) {
279
- // add cssMap and jsx together if either is missing
280
- const cssMapImport = j.importDeclaration(
281
- [j.importSpecifier(j.identifier('cssMap')), j.importSpecifier(j.identifier('jsx'))],
282
- j.literal('@atlaskit/css'),
301
+ // add grouped import for primitives
302
+ // e.g. import { Anchor, Box } from '@atlaskit/primitives/compiled';
303
+ if (primitivesToImport.size > 0) {
304
+ const primitivesImport = j.importDeclaration(
305
+ Array.from(primitivesToImport)
306
+ .sort()
307
+ .map((name) => j.importSpecifier(j.identifier(name))),
308
+ j.literal('@atlaskit/primitives/compiled'),
283
309
  );
284
- newImports.push(cssMapImport);
310
+ newImports.push(primitivesImport);
311
+ }
312
+
313
+ // add cssMap and jsx import if needed
314
+ if (!importsNeeded.cssMap || !importsNeeded.jsx) {
315
+ const existingCssImports = source
316
+ .find(j.ImportDeclaration)
317
+ .filter((path) => path.node.source.value === '@atlaskit/css');
318
+
319
+ const newSpecifiers: core.ImportSpecifier[] = [];
320
+
321
+ if (!importsNeeded.cssMap) {
322
+ newSpecifiers.push(j.importSpecifier(j.identifier('cssMap')));
323
+ }
324
+ if (!importsNeeded.jsx) {
325
+ newSpecifiers.push(j.importSpecifier(j.identifier('jsx')));
326
+ }
327
+
328
+ if (existingCssImports.size() > 0) {
329
+ // existing import from '@atlaskit/css'
330
+ const existingCssImport = existingCssImports.at(0).get();
331
+
332
+ if (existingCssImport && existingCssImport.node.specifiers) {
333
+ existingCssImport.node.specifiers.push(...newSpecifiers);
334
+ }
335
+ } else {
336
+ const cssMapImport = j.importDeclaration(newSpecifiers, j.literal('@atlaskit/css'));
337
+ newImports.push(cssMapImport);
338
+ }
285
339
  }
286
340
 
341
+ // add token import
287
342
  if (!importsNeeded.token) {
288
343
  const tokenImport = j.importDeclaration(
289
344
  [j.importSpecifier(j.identifier('token'))],
@@ -292,26 +347,7 @@ function updateImports(j: core.JSCodeshift, source: ReturnType<typeof j>) {
292
347
  newImports.push(tokenImport);
293
348
  }
294
349
 
295
- // remove default import React from 'react' if not needed
296
- source.find(j.ImportDeclaration, { source: { value: 'react' } }).forEach((path) => {
297
- path.node.specifiers = path.node.specifiers?.filter(
298
- (specifier) =>
299
- !(specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name === 'React'),
300
- );
301
- if (path.node.specifiers?.length === 0) {
302
- j(path).remove();
303
- }
304
- });
305
-
306
- // update @atlaskit/primitives imports to @atlaskit/primitives/compiled
307
- source
308
- .find(j.ImportDeclaration)
309
- .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === '@atlaskit/primitives')
310
- .forEach((path) => {
311
- path.node.source.value = '@atlaskit/primitives/compiled';
312
- });
313
-
314
- // add new imports after any existing comments to ensure they're below the jsx pragma
350
+ // add new imports after any existing comments
315
351
  const rootNode = source.get().node;
316
352
  const firstNonCommentIndex = rootNode.program.body.findIndex(
317
353
  (node: core.Node) =>
@@ -846,14 +846,15 @@ export type Fill = keyof typeof fillMap;
846
846
 
847
847
  /**
848
848
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
849
- * @codegen <<SignedSource::dbfb4c7de16d0ae4a53d66f9663aca91>>
849
+ * @codegen <<SignedSource::042cbfe8041c09e3817ae74154994f32>>
850
850
  * @codegenId misc
851
851
  * @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
852
852
  * @codegenParams ["layer"]
853
853
  * @codegenDependency ../../../primitives/scripts/codegen-file-templates/dimensions.tsx <<SignedSource::cc9b3f12104c6ede803da6a42daac0b0>>
854
- * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::6f10945ad9139d0119003738c65ae40a>>
854
+ * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::92793ca02dbfdad66e53ffbe9f0baa0a>>
855
855
  */
856
856
  export const layerMap = {
857
+ '1': 1,
857
858
  card: 100,
858
859
  navigation: 200,
859
860
  dialog: 300,
@@ -906,12 +907,12 @@ export type BorderRadius = keyof typeof borderRadiusMap;
906
907
 
907
908
  /**
908
909
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
909
- * @codegen <<SignedSource::97e5ae47f252660a5ef7569a3880c26c>>
910
+ * @codegen <<SignedSource::96d9a841cb440c2bd770d0af5c670f10>>
910
911
  * @codegenId typography
911
912
  * @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
912
913
  * @codegenParams ["fontSize", "fontWeight", "fontFamily", "lineHeight", "body", "ui"]
913
914
  * @codegenDependency ../../../primitives/scripts/codegen-file-templates/dimensions.tsx <<SignedSource::cc9b3f12104c6ede803da6a42daac0b0>>
914
- * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::6f10945ad9139d0119003738c65ae40a>>
915
+ * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::92793ca02dbfdad66e53ffbe9f0baa0a>>
915
916
  */
916
917
  export const fontMap = {
917
918
  'font.body': token(
@@ -1006,11 +1007,11 @@ export type FontFamily = keyof typeof fontFamilyMap;
1006
1007
 
1007
1008
  /**
1008
1009
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
1009
- * @codegen <<SignedSource::7dc7abf82a13bc780c338b9602508ae6>>
1010
+ * @codegen <<SignedSource::ae96213e36b930556f9ad18382088ff8>>
1010
1011
  * @codegenId text
1011
1012
  * @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
1012
1013
  * @codegenDependency ../../../primitives/scripts/codegen-file-templates/dimensions.tsx <<SignedSource::cc9b3f12104c6ede803da6a42daac0b0>>
1013
- * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::6f10945ad9139d0119003738c65ae40a>>
1014
+ * @codegenDependency ../../../primitives/scripts/codegen-file-templates/layer.tsx <<SignedSource::92793ca02dbfdad66e53ffbe9f0baa0a>>
1014
1015
  */
1015
1016
  export const textSizeMap = {
1016
1017
  medium: token(
@@ -21,7 +21,8 @@ This is built on top of [Compiled CSS-in-JS](https://compiledcssinjs.com/) which
21
21
  performant, static styling solution with the same syntax and a few breaking changes—the primary ones
22
22
  being dynamic styles as well as deep imports or exports for reuse of styles may not work.
23
23
 
24
- This will require major configuration, noted below.
24
+ This will require configuration, refer to our
25
+ [Get started](/get-started/develop#set-up-your-bundling-environment) guide.
25
26
 
26
27
  ## Usage
27
28
 
@@ -230,137 +231,6 @@ export function Card({
230
231
 
231
232
  ## Configuration required
232
233
 
233
- <SectionMessage title="More details coming soon!" appearance="warning">
234
- <p>This section is under development, more details will come soon.</p>
235
- </SectionMessage>
236
-
237
234
  In order to use any Atlassian Design System packages that distribute Compiled CSS-in-JS, you
238
- **must** configure your project via Babel as well your bundler with Webpack and/or Parcel and using
239
- the latest version of these plugins:
240
-
241
- - `@atlaskit/tokens/babel-plugin`
242
- - `@compiled/babel-plugin` configured with `sortShorthand: true` (or configured through
243
- `@compiled/webpack-loader` or `@compiled/parcel-config` or similar)
244
- - **SUGGESTED:** You should turn on
245
- [@atlaskit/eslint-plugin-ui-styling-standard](/components/eslint-plugin-ui-styling-standard) to
246
- guide you
247
-
248
- Refer to https://compiledcssinjs.com/docs/installation
249
-
250
- ### Setup your Babel plugins
251
-
252
- Most products will use Babel across the dev lifecycle, so this is typically a baseline
253
- configuration.
254
-
255
- ```sh
256
- yarn install @atlaskit/tokens
257
- yarn install --dev @compiled/babel-plugin
258
- yarn install --dev @compiled/babel-plugin-strip-runtime # optional, for extracting styles
259
- ```
260
-
261
- Plugin order matters, your `@atlaskit/tokens/babel-plugin` must come before your
262
- `@compiled/babel-plugin`, otherwise you may experience errors.
263
-
264
- ```js
265
- // babel.config.js
266
- module.exports = {
267
- plugins: [
268
- // This will handle all `token()` calls, eg. if used in a non-Compiled CSS-in-JS library:
269
- '@atlaskit/tokens/babel-plugin',
270
- // ↓↓ Compiled should run last ↓↓
271
- ['@compiled/babel-plugin', { transformerBabelPlugins: ['@atlaskit/tokens/babel-plugin'] }],
272
- // OPTIONAL: If you are distributing packages with Compiled styles, you should also include the following.
273
- // Your `dest` may vary depending on how you distribute, eg. if you have multiple `cjs` and `esm` distributions
274
- // those will each need a separate `dest` through Babel's environment-specific configuration.
275
- [
276
- '@compiled/babel-plugin-strip-runtime',
277
- {
278
- sortShorthand: true,
279
- extractStylesToDirectory: { source: 'src', dest: 'dist' }
280
- },
281
- ],
282
- ],
283
- };
284
- ```
285
-
286
- For full documentation, refer to https://compiledcssinjs.com/docs/installation#babel
287
-
288
- ### Bundling with Webpack
289
-
290
- This configuration may vary, this is the default production-like configuration expected where the
291
- primary suggestion is to use extracted styles for performance and consistency reasons. Development
292
- configuration may vary.
293
-
294
- ```sh
295
- yarn install @atlaskit/tokens
296
- yarn install --dev @compiled/webpack-loader mini-css-extract-plugin
297
- ```
298
-
299
- ```js
300
- const { CompiledExtractPlugin } = require('@compiled/webpack-loader');
301
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
302
-
303
- module.exports = {
304
- module: {
305
- rules: [
306
- {
307
- test: /\.(js|jsx|ts|tsx)$/,
308
- use: [
309
- { loader: 'babel-loader' },
310
- {
311
- // ↓↓ Compiled should run last ↓↓
312
- loader: '@compiled/webpack-loader',
313
- options: {
314
- transformerBabelPlugins: ['@atlaskit/tokens/babel-plugin'],
315
- extract: true,
316
- inlineCss: true,
317
- },
318
- },
319
- ],
320
- },
321
- {
322
- test: /compiled-css\.css$/i,
323
- use: [MiniCssExtractPlugin.loader, 'css-loader'],
324
- },
325
- {
326
- test: /(?<!compiled-css)(?<!\.compiled)\.css$/,
327
- use: ['style-loader', 'css-loader'],
328
- },
329
- ],
330
- },
331
- plugins: [
332
- new MiniCssExtractPlugin(),
333
- new CompiledExtractPlugin({ sortShorthand: true }),
334
- ],
335
- };
336
- ```
337
-
338
- For full documentation, refer to https://compiledcssinjs.com/docs/installation#webpack
339
-
340
- ### Bundling with Parcel
341
-
342
- ```sh
343
- yarn install @atlaskit/tokens
344
- yarn install --dev @compiled/parcel-config
345
- ```
346
-
347
- Setup your `.compiledcssrc`:
348
-
349
- ```json
350
- {
351
- "transformerBabelPlugins": [["@atlaskit/tokens/babel-plugin"]],
352
- "extract": true,
353
- "inlineCss": true,
354
- "sortShorthand": true
355
- }
356
- ```
357
-
358
- Setup your `.parcelrc`:
359
-
360
- ```json
361
- {
362
- "extends": ["@parcel/config-default", "@compiled/parcel-config"]
363
- }
364
- ```
365
-
366
- For full documentation, refer to https://compiledcssinjs.com/docs/installation#(recommended)-parcel
235
+ **must** configure your project, please refer to our
236
+ [Get started](/get-started/develop#set-up-your-bundling-environment) guide.
@@ -2,21 +2,21 @@
2
2
  order: 1
3
3
  ---
4
4
 
5
+ import SectionMessage from '@atlaskit/section-message';
6
+
5
7
  ## Migration to `@atlaskit/css`
6
8
 
7
- `@atlaskit/css` is the replacement for `@atlaskit/primitives/xcss` which will only work with the
8
- Compiled variants of packages, eg. `@atlaskit/primitives/compiled` (note that not all packages will
9
- be migrated to Compiled by the end of 2024).
9
+ <SectionMessage title="Migration from Emotion to Compiled" appearance="discovery">
10
+ <p>
11
+ The Atlassian Design System is under the process of migrating from Emotion to Compiled for our
12
+ CSS-in-JS. Further details to come.
13
+ </p>
14
+ </SectionMessage>
10
15
 
11
- Typically, this migration means moving from the `const styles = xcss({ padding: 'space.100' })` API
12
- to a `const styles = cssMap({ root: { padding: token('space.100') } })` API, and we have a codemod
13
- to assist with a majority of this migration for you. Some things are not available in the Compiled
14
- API such as dynamic styles or imports, please use the
16
+ We have a codemod available to support this migration, but there are some breaking changes between
17
+ Emotion and Compiled, such as dynamic styles or imports. Please use the
15
18
  [UI Styling Standard ESLint Plugin](/components/eslint-plugin-ui-styling-standard/) to guide you.
16
19
 
17
- Refer to [Configuration required](/components/css/examples#configuration-required) for details on
18
- how to configure your project to use `@atlaskit/css`
19
-
20
20
  ## Codemod
21
21
 
22
22
  We have a codemod to assist in migrations from `xcss()` to `@atlaskit/css`.
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* index.tsx generated by @compiled/babel-plugin v0.32.1 */
1
+ /* index.tsx generated by @compiled/babel-plugin v0.32.2 */
2
2
  "use strict";
3
3
 
4
4
  var _typeof = require("@babel/runtime/helpers/typeof");
@@ -1,4 +1,4 @@
1
- /* index.tsx generated by @compiled/babel-plugin v0.32.1 */
1
+ /* index.tsx generated by @compiled/babel-plugin v0.32.2 */
2
2
  import * as React from 'react';
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import { createStrictAPI } from '@compiled/react';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* index.tsx generated by @compiled/babel-plugin v0.32.1 */
1
+ /* index.tsx generated by @compiled/babel-plugin v0.32.2 */
2
2
  import * as React from 'react';
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import { createStrictAPI } from '@compiled/react';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/css",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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",
@@ -15,7 +15,7 @@
15
15
  "category": "Libraries",
16
16
  "ignorePropTypes": true,
17
17
  "status": {
18
- "type": "alpha"
18
+ "type": "beta"
19
19
  }
20
20
  }
21
21
  },
@@ -38,7 +38,7 @@
38
38
  ".": "./src/index.tsx"
39
39
  },
40
40
  "dependencies": {
41
- "@atlaskit/tokens": "^2.0.0",
41
+ "@atlaskit/tokens": "^2.2.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@compiled/react": "^0.18.1"
44
44
  },