@atlaskit/code 15.2.0 → 15.2.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +644 -645
  2. package/__perf__/source-code-examples/100-line-example.tsx +49 -40
  3. package/codemods/13.0.0-remove-unnecessary-code-props.tsx +61 -75
  4. package/codemods/13.0.0-rename-imports.tsx +214 -251
  5. package/codemods/14.0.0-lite-mode.tsx +5 -9
  6. package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +43 -43
  7. package/codemods/__tests__/13.0.0-rename-imports.tsx +143 -143
  8. package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +35 -35
  9. package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +21 -21
  10. package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +35 -35
  11. package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +1 -6
  12. package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +53 -61
  13. package/codemods/utils/helpers.tsx +161 -201
  14. package/dist/cjs/internal/theme/styles.js +2 -1
  15. package/dist/es2019/internal/theme/styles.js +2 -1
  16. package/dist/esm/internal/theme/styles.js +2 -1
  17. package/dist/types/bidi-warning/ui/index.d.ts +1 -1
  18. package/dist/types/bidi-warning/ui/styled.d.ts +1 -1
  19. package/dist/types/extract-react-types/code-block.d.ts +16 -16
  20. package/dist/types/internal/hooks/use-highlight.d.ts +1 -1
  21. package/dist/types/internal/utils/get-normalized-language.d.ts +1 -1
  22. package/dist/types/syntax-highlighter/async.d.ts +1 -1
  23. package/dist/types/syntax-highlighter/lib/highlight.d.ts +1 -1
  24. package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
  25. package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +1 -1
  26. package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
  27. package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
  28. package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
  29. package/dist/types/syntax-highlighter/lib/process/index.d.ts +1 -1
  30. package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
  31. package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
  32. package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
  33. package/dist/types/syntax-highlighter/types.d.ts +2 -2
  34. package/dist/types/types.d.ts +1 -1
  35. package/dist/types-ts4.5/bidi-warning/ui/index.d.ts +1 -1
  36. package/dist/types-ts4.5/bidi-warning/ui/styled.d.ts +1 -1
  37. package/dist/types-ts4.5/extract-react-types/code-block.d.ts +16 -16
  38. package/dist/types-ts4.5/internal/hooks/use-highlight.d.ts +1 -1
  39. package/dist/types-ts4.5/internal/utils/get-normalized-language.d.ts +1 -1
  40. package/dist/types-ts4.5/syntax-highlighter/async.d.ts +1 -1
  41. package/dist/types-ts4.5/syntax-highlighter/lib/highlight.d.ts +1 -1
  42. package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
  43. package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line.d.ts +1 -1
  44. package/dist/types-ts4.5/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
  45. package/dist/types-ts4.5/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
  46. package/dist/types-ts4.5/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
  47. package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +1 -1
  48. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
  49. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
  50. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
  51. package/dist/types-ts4.5/syntax-highlighter/types.d.ts +2 -2
  52. package/dist/types-ts4.5/types.d.ts +1 -1
  53. package/package.json +5 -7
  54. package/report.api.md +807 -807
@@ -1,16 +1,23 @@
1
1
  // eslint-disable-file
2
2
  export const hundredLineExample = `/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
3
3
  /** @jsx jsx */
4
- import React, { forwardRef, useMemo } from 'react';
4
+ import React, { CSSProperties, forwardRef } from 'react';
5
5
 
6
6
  import { css, jsx } from '@emotion/react';
7
7
 
8
- import { UNSAFE_Box as Box, UNSAFE_BoxProps as BoxProps, UNSAFE_Inline as Inline, UNSAFE_Text as Text, UNSAFE_TextProps as TextProps, } from '@atlaskit/ds-explorations';
8
+ import { BackgroundColor, Box, Inline, xcss } from '@atlaskit/primitives';
9
9
  import { N0, N500, N700, R400, Y300 } from '@atlaskit/theme/colors';
10
10
  import { token } from '@atlaskit/tokens';
11
11
 
12
- // Applies styles to nested links within banner messages.
13
- const nestedLinkStyles = css({
12
+ const CSS_VAR_TEXT_COLOR = '--banner-text-color';
13
+
14
+ const textStyles = css({
15
+ color: \`var(\${CSS_VAR_TEXT_COLOR})\`,
16
+ fontWeight: token('font.weight.medium', '500'),
17
+ lineHeight: token('font.lineHeight.300', '24px'),
18
+ overflow: 'hidden',
19
+ textOverflow: 'ellipsis',
20
+ whiteSpace: 'nowrap',
14
21
  // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
15
22
  'a, a:visited, a:hover, a:focus, a:active': {
16
23
  color: 'currentColor',
@@ -18,10 +25,10 @@ const nestedLinkStyles = css({
18
25
  },
19
26
  });
20
27
 
21
- const backgroundColors: Record<Appearance, BoxProps['backgroundColor']> = {
22
- warning: 'warning.bold',
23
- error: 'danger.bold',
24
- announcement: 'neutral.bold',
28
+ const backgroundColors: Record<Appearance, BackgroundColor> = {
29
+ warning: 'color.background.warning.bold',
30
+ error: 'color.background.danger.bold',
31
+ announcement: 'color.background.neutral.bold',
25
32
  };
26
33
 
27
34
  const tokenBackgroundColors: Record<Appearance, string> = {
@@ -30,12 +37,6 @@ const tokenBackgroundColors: Record<Appearance, string> = {
30
37
  announcement: token('color.background.neutral.bold', N500),
31
38
  };
32
39
 
33
- const textColors: Record<Appearance, TextProps['color']> = {
34
- warning: 'warning.inverse',
35
- error: 'inverse',
36
- announcement: 'inverse',
37
- };
38
-
39
40
  const tokenTextColors: Record<Appearance, string> = {
40
41
  warning: token('color.text.warning.inverse', N700),
41
42
  error: token('color.text.inverse', N0),
@@ -44,7 +45,19 @@ const tokenTextColors: Record<Appearance, string> = {
44
45
 
45
46
  type Appearance = 'warning' | 'error' | 'announcement';
46
47
 
47
- interface BannerProps {
48
+ const containerStyles = xcss({
49
+ overflow: 'hidden',
50
+ maxHeight: 'size.500',
51
+ });
52
+
53
+ const iconWrapperStyles = xcss({
54
+ display: 'block',
55
+ width: 'size.200',
56
+ height: 'size.200', // This matches Icon's "medium" size, without this the (line-)height is greater than that of the Icon
57
+ flexShrink: '0',
58
+ });
59
+
60
+ export interface BannerProps {
48
61
  appearance?: Appearance;
49
62
  children?: React.ReactNode;
50
63
  icon?: React.ReactElement;
@@ -56,42 +69,38 @@ const Banner = forwardRef<HTMLDivElement, BannerProps>(
56
69
  const appearanceType =
57
70
  appearance in backgroundColors ? appearance : 'warning';
58
71
 
59
- const accessibilityProps = useMemo(() => {
60
- const baseProps = {
61
- role: 'alert',
62
- };
63
-
64
- if (appearance === 'announcement') {
65
- return {
66
- ...baseProps,
67
- 'aria-label': 'announcement',
68
- tabIndex: 0,
69
- role: 'region',
70
- };
71
- }
72
-
73
- return baseProps;
74
- }, [appearance]);
75
-
76
72
  return (
77
- <Box display="block" backgroundColor={backgroundColors[appearanceType]} paddingInline="space.150" overflow="hidden" testId={testId} ref={ref} {...accessibilityProps} UNSAFE_style={{ paddingBlock: '14px', maxHeight: '52px', }} css={nestedLinkStyles} >
78
- <Inline gap="space.050" alignItems="center" justifyContent="start">
73
+ <Box
74
+ xcss={containerStyles}
75
+ backgroundColor={backgroundColors[appearanceType]}
76
+ padding="space.150"
77
+ testId={testId}
78
+ ref={ref}
79
+ role="alert"
80
+ >
81
+ <Inline space="space.050" alignBlock="center" alignInline="start">
79
82
  {icon ? (
80
83
  <Box
81
84
  as="span"
82
- display="inline"
83
- width="size.300"
84
- height="size.300" // This matches Icon's "medium" size, without this the (line-)height is greater than that of the Icon
85
- UNSAFE_style={{
85
+ xcss={iconWrapperStyles}
86
+ style={{
86
87
  fill: tokenBackgroundColors[appearanceType],
87
88
  color: tokenTextColors[appearanceType],
88
- flexShrink: 0,
89
89
  }}
90
90
  >
91
91
  {icon}
92
92
  </Box>
93
93
  ) : null}
94
- <Text fontWeight="medium" lineHeight="lineHeight.300" color={textColors[appearanceType]} shouldTruncate> {children} </Text>
94
+ <span
95
+ style={
96
+ {
97
+ [CSS_VAR_TEXT_COLOR]: tokenTextColors[appearanceType],
98
+ } as CSSProperties
99
+ }
100
+ css={textStyles}
101
+ >
102
+ {children}
103
+ </span>
95
104
  </Inline>
96
105
  </Box>
97
106
  );
@@ -1,98 +1,84 @@
1
- import { API, FileInfo, JSCodeshift, Options } from 'jscodeshift';
2
- import { Collection } from 'jscodeshift/src/Collection';
1
+ import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
3
 
4
4
  import {
5
- getImportDeclarationCollection,
6
- getImportSpecifierCollection,
7
- getImportSpecifierName,
8
- getJSXAttributesByName,
9
- getJSXSpreadIdentifierAttributesByName,
10
- getJSXSpreadObjectExpressionAttributesByName,
11
- hasImportDeclaration,
5
+ getImportDeclarationCollection,
6
+ getImportSpecifierCollection,
7
+ getImportSpecifierName,
8
+ getJSXAttributesByName,
9
+ getJSXSpreadIdentifierAttributesByName,
10
+ getJSXSpreadObjectExpressionAttributesByName,
11
+ hasImportDeclaration,
12
12
  } from './utils/helpers';
13
13
 
14
14
  const importPath = '@atlaskit/code';
15
15
  const importName = 'Code';
16
- const propsToBeRemoved = [
17
- 'lineNumberContainerStyle',
18
- 'showLineNumbers',
19
- 'highlight',
20
- ];
16
+ const propsToBeRemoved = ['lineNumberContainerStyle', 'showLineNumbers', 'highlight'];
21
17
 
22
18
  function removeProps(
23
- j: JSCodeshift,
24
- collection: Collection<any>,
25
- elementName: string,
26
- propName: string,
19
+ j: JSCodeshift,
20
+ collection: Collection<any>,
21
+ elementName: string,
22
+ propName: string,
27
23
  ) {
28
- collection.findJSXElements(elementName).forEach((jsxElementPath) => {
29
- const jsxAttributeCollection = getJSXAttributesByName(
30
- j,
31
- jsxElementPath,
32
- propName,
33
- );
34
- if (jsxAttributeCollection) {
35
- jsxAttributeCollection.remove();
36
- }
24
+ collection.findJSXElements(elementName).forEach((jsxElementPath) => {
25
+ const jsxAttributeCollection = getJSXAttributesByName(j, jsxElementPath, propName);
26
+ if (jsxAttributeCollection) {
27
+ jsxAttributeCollection.remove();
28
+ }
37
29
 
38
- const jsxSpreadIdentifierPropertyCollection =
39
- getJSXSpreadIdentifierAttributesByName(
40
- j,
41
- collection,
42
- jsxElementPath,
43
- propName,
44
- );
45
- if (jsxSpreadIdentifierPropertyCollection) {
46
- jsxSpreadIdentifierPropertyCollection.remove();
47
- }
30
+ const jsxSpreadIdentifierPropertyCollection = getJSXSpreadIdentifierAttributesByName(
31
+ j,
32
+ collection,
33
+ jsxElementPath,
34
+ propName,
35
+ );
36
+ if (jsxSpreadIdentifierPropertyCollection) {
37
+ jsxSpreadIdentifierPropertyCollection.remove();
38
+ }
48
39
 
49
- const jsxSpreadExpressionPropertyCollection =
50
- getJSXSpreadObjectExpressionAttributesByName(j, jsxElementPath, propName);
51
- if (jsxSpreadExpressionPropertyCollection) {
52
- jsxSpreadExpressionPropertyCollection.remove();
53
- }
54
- });
40
+ const jsxSpreadExpressionPropertyCollection = getJSXSpreadObjectExpressionAttributesByName(
41
+ j,
42
+ jsxElementPath,
43
+ propName,
44
+ );
45
+ if (jsxSpreadExpressionPropertyCollection) {
46
+ jsxSpreadExpressionPropertyCollection.remove();
47
+ }
48
+ });
55
49
  }
56
50
 
57
51
  function removePropsForImportSpecifiers(
58
- j: JSCodeshift,
59
- collection: Collection<any>,
60
- propName: string,
52
+ j: JSCodeshift,
53
+ collection: Collection<any>,
54
+ propName: string,
61
55
  ) {
62
- const importDeclarationCollection = getImportDeclarationCollection(
63
- j,
64
- collection,
65
- importPath,
66
- );
67
- const importSpecifierCollection = getImportSpecifierCollection(
68
- j,
69
- importDeclarationCollection,
70
- importName,
71
- );
72
- const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
56
+ const importDeclarationCollection = getImportDeclarationCollection(j, collection, importPath);
57
+ const importSpecifierCollection = getImportSpecifierCollection(
58
+ j,
59
+ importDeclarationCollection,
60
+ importName,
61
+ );
62
+ const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
73
63
 
74
- if (importSpecifierName === null) {
75
- return;
76
- }
64
+ if (importSpecifierName === null) {
65
+ return;
66
+ }
77
67
 
78
- removeProps(j, collection, importSpecifierName, propName);
68
+ removeProps(j, collection, importSpecifierName, propName);
79
69
  }
80
70
 
81
- export default function transformer(
82
- fileInfo: FileInfo,
83
- { jscodeshift: j }: API,
84
- options: Options,
85
- ) {
86
- const { source } = fileInfo;
87
- const collection = j(source);
71
+ export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
72
+ const { source } = fileInfo;
73
+ const collection = j(source);
88
74
 
89
- if (!hasImportDeclaration(j, collection, importPath)) {
90
- return source;
91
- }
75
+ if (!hasImportDeclaration(j, collection, importPath)) {
76
+ return source;
77
+ }
92
78
 
93
- propsToBeRemoved.forEach((propToRemove) => {
94
- removePropsForImportSpecifiers(j, collection, propToRemove);
95
- });
79
+ propsToBeRemoved.forEach((propToRemove) => {
80
+ removePropsForImportSpecifiers(j, collection, propToRemove);
81
+ });
96
82
 
97
- return collection.toSource(options.printOptions || { quote: 'single' });
83
+ return collection.toSource(options.printOptions || { quote: 'single' });
98
84
  }