@atlaskit/icon 22.13.0 → 22.14.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 +8 -0
- package/codemods/22.14.0-new-icon-migrate-color-prop.tsx +119 -0
- package/codemods/__tests__/next-new-icon-migrate-color-prop.test.tsx +64 -0
- package/dist/cjs/components/icon.js +1 -0
- package/dist/es2019/components/icon.js +1 -0
- package/dist/esm/components/icon.js +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/icon
|
|
2
2
|
|
|
3
|
+
## 22.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#131906](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/131906)
|
|
8
|
+
[`9fd3fdb9e3b02`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9fd3fdb9e3b02) -
|
|
9
|
+
Adding 'data-vc' attribute to icon for instrumenting TTVC (go/ttvc).
|
|
10
|
+
|
|
3
11
|
## 22.13.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasImportDeclaration,
|
|
3
|
+
hasJSXAttributes,
|
|
4
|
+
insertCommentToStartOfFile,
|
|
5
|
+
} from '@codeshift/utils';
|
|
6
|
+
import type { API, Collection, default as core, FileInfo } from 'jscodeshift';
|
|
7
|
+
|
|
8
|
+
function insertTokenImport(j: core.JSCodeshift, source: Collection<any>) {
|
|
9
|
+
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const newImport = j.importDeclaration(
|
|
14
|
+
[j.importSpecifier(j.identifier('token'))],
|
|
15
|
+
j.stringLiteral('@atlaskit/tokens'),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
source.get().node.program.body.unshift(newImport);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getPartialImportDeclaration(
|
|
22
|
+
j: core.JSCodeshift,
|
|
23
|
+
source: Collection<any>,
|
|
24
|
+
sourcePath: string,
|
|
25
|
+
): Collection<any> {
|
|
26
|
+
return source
|
|
27
|
+
.find(j.ImportDeclaration)
|
|
28
|
+
.filter(
|
|
29
|
+
(path) =>
|
|
30
|
+
typeof path.node.source.value === 'string' && path.node.source.value.includes(sourcePath),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function buildToken(j: core.JSCodeshift, tokenId: string = '', fallback: string) {
|
|
35
|
+
const callExpr = j.callExpression(
|
|
36
|
+
j.identifier('token'),
|
|
37
|
+
[j.stringLiteral(tokenId), j.stringLiteral(fallback)].filter(Boolean),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return callExpr;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default function transformer(file: FileInfo, api: API) {
|
|
44
|
+
const j = api.jscodeshift;
|
|
45
|
+
const source = j(file.source);
|
|
46
|
+
|
|
47
|
+
// Find all new icon imports
|
|
48
|
+
const coreIconImportDeclarations = getPartialImportDeclaration(j, source, '@atlaskit/icon/core');
|
|
49
|
+
const utilityIconImportDeclarations = getPartialImportDeclaration(
|
|
50
|
+
j,
|
|
51
|
+
source,
|
|
52
|
+
'@atlaskit/icon/utility',
|
|
53
|
+
);
|
|
54
|
+
const iconLabIconImportDeclarations = getPartialImportDeclaration(
|
|
55
|
+
j,
|
|
56
|
+
source,
|
|
57
|
+
'@atlassian/icon-lab/core',
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Get all the specifier names
|
|
61
|
+
const newIconSpecifiers: string[] = [];
|
|
62
|
+
[
|
|
63
|
+
coreIconImportDeclarations,
|
|
64
|
+
utilityIconImportDeclarations,
|
|
65
|
+
iconLabIconImportDeclarations,
|
|
66
|
+
].forEach((newIconImportDeclaration) => {
|
|
67
|
+
newIconImportDeclaration.forEach((newIconImport) => {
|
|
68
|
+
if (!newIconImport.value.specifiers) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
newIconImport.value.specifiers.map((specifier: any) => {
|
|
72
|
+
if (specifier.local && specifier.local.name) {
|
|
73
|
+
newIconSpecifiers.push(specifier.local.name);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// No imports for new button found, exit early
|
|
80
|
+
if (!newIconSpecifiers.length) {
|
|
81
|
+
return source.toSource();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Find all new icon JSX elements that don't have a `color` prop set
|
|
85
|
+
const newIconJSXElements = source
|
|
86
|
+
.find(j.JSXElement)
|
|
87
|
+
// is a new icon?
|
|
88
|
+
.filter(
|
|
89
|
+
(path) =>
|
|
90
|
+
path.value.openingElement.name.type === 'JSXIdentifier' &&
|
|
91
|
+
newIconSpecifiers.includes(path.value.openingElement.name.name),
|
|
92
|
+
)
|
|
93
|
+
// has no color prop?
|
|
94
|
+
.filter((path) => !hasJSXAttributes(j, path, 'color'));
|
|
95
|
+
|
|
96
|
+
newIconJSXElements.forEach((newIconJSXElement) => {
|
|
97
|
+
const newIconJSXElementValue = newIconJSXElement.value;
|
|
98
|
+
const newIconJSXElementOpeningElement = newIconJSXElementValue.openingElement;
|
|
99
|
+
|
|
100
|
+
// If spread props exist, add a comment and skip
|
|
101
|
+
if (
|
|
102
|
+
newIconJSXElementOpeningElement.attributes?.some((attr) => attr.type === 'JSXSpreadAttribute')
|
|
103
|
+
) {
|
|
104
|
+
insertCommentToStartOfFile(j, source, 'Migrate color prop');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Insert the `color` prop
|
|
109
|
+
newIconJSXElementOpeningElement.attributes?.push(
|
|
110
|
+
j.jsxAttribute(
|
|
111
|
+
j.jsxIdentifier('color'),
|
|
112
|
+
j.jsxExpressionContainer(buildToken(j, 'color.icon', '#44546F')),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
insertTokenImport(j, source);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return source.toSource();
|
|
119
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import transformer from '../22.14.0-new-icon-migrate-color-prop';
|
|
2
|
+
|
|
3
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
4
|
+
|
|
5
|
+
describe('Migrate color API', () => {
|
|
6
|
+
defineInlineTest(
|
|
7
|
+
{ default: transformer, parser: 'tsx' },
|
|
8
|
+
{},
|
|
9
|
+
`
|
|
10
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
11
|
+
import ChevronDownIcon from '@atlaskit/icon/utility/add';
|
|
12
|
+
import BitbucketBranchIcon from '@atlassian/icon-lab/core/bitbucket-branch';
|
|
13
|
+
|
|
14
|
+
const App = () => (
|
|
15
|
+
<>
|
|
16
|
+
<AddIcon label=""/>
|
|
17
|
+
<ChevronDownIcon label=""/>
|
|
18
|
+
<BitbucketBranchIcon label=""/>
|
|
19
|
+
<Button iconAfter={AddIcon}/>
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
`,
|
|
23
|
+
`
|
|
24
|
+
import { token } from "@atlaskit/tokens";
|
|
25
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
26
|
+
import ChevronDownIcon from '@atlaskit/icon/utility/add';
|
|
27
|
+
import BitbucketBranchIcon from '@atlassian/icon-lab/core/bitbucket-branch';
|
|
28
|
+
|
|
29
|
+
const App = () => (
|
|
30
|
+
<>
|
|
31
|
+
<AddIcon label="" color={token("color.icon", "#44546F")} />
|
|
32
|
+
<ChevronDownIcon label="" color={token("color.icon", "#44546F")} />
|
|
33
|
+
<BitbucketBranchIcon label="" color={token("color.icon", "#44546F")} />
|
|
34
|
+
<Button iconAfter={AddIcon}/>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
`,
|
|
38
|
+
'should add color prop to icons',
|
|
39
|
+
);
|
|
40
|
+
defineInlineTest(
|
|
41
|
+
{ default: transformer, parser: 'tsx' },
|
|
42
|
+
{},
|
|
43
|
+
`
|
|
44
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
45
|
+
|
|
46
|
+
const App = (props: any) => (
|
|
47
|
+
<>
|
|
48
|
+
<AddIcon {...props} label=""/>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
`,
|
|
52
|
+
`
|
|
53
|
+
/* TODO: (@codeshift) Migrate color prop */
|
|
54
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
55
|
+
|
|
56
|
+
const App = (props: any) => (
|
|
57
|
+
<>
|
|
58
|
+
<AddIcon {...props} label=""/>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
`,
|
|
62
|
+
'should handle spread props',
|
|
63
|
+
);
|
|
64
|
+
});
|
|
@@ -105,6 +105,7 @@ var Icon = exports.Icon = /*#__PURE__*/(0, _react.memo)(function Icon(props) {
|
|
|
105
105
|
});
|
|
106
106
|
return (0, _react2.jsx)("span", (0, _extends2.default)({
|
|
107
107
|
"data-testid": testId,
|
|
108
|
+
"data-vc": "icon-".concat(testId),
|
|
108
109
|
role: label ? 'img' : undefined,
|
|
109
110
|
"aria-label": label ? label : undefined,
|
|
110
111
|
"aria-hidden": label ? undefined : true
|
|
@@ -101,6 +101,7 @@ export const Icon = /*#__PURE__*/memo(function Icon(props) {
|
|
|
101
101
|
});
|
|
102
102
|
return jsx("span", _extends({
|
|
103
103
|
"data-testid": testId,
|
|
104
|
+
"data-vc": `icon-${testId}`,
|
|
104
105
|
role: label ? 'img' : undefined,
|
|
105
106
|
"aria-label": label ? label : undefined,
|
|
106
107
|
"aria-hidden": label ? undefined : true
|
|
@@ -102,6 +102,7 @@ export var Icon = /*#__PURE__*/memo(function Icon(props) {
|
|
|
102
102
|
});
|
|
103
103
|
return jsx("span", _extends({
|
|
104
104
|
"data-testid": testId,
|
|
105
|
+
"data-vc": "icon-".concat(testId),
|
|
105
106
|
role: label ? 'img' : undefined,
|
|
106
107
|
"aria-label": label ? label : undefined,
|
|
107
108
|
"aria-hidden": label ? undefined : true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/icon",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.14.0",
|
|
4
4
|
"description": "An icon is a visual representation of a command, device, directory, or common action.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
34
|
-
"@atlaskit/tokens": "^1.
|
|
34
|
+
"@atlaskit/tokens": "^1.59.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
36
|
"@emotion/react": "^11.7.1"
|
|
37
37
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@af/icon-build-process": "^2.1.0",
|
|
44
44
|
"@af/visual-regression": "*",
|
|
45
45
|
"@atlaskit/code": "^15.5.0",
|
|
46
|
-
"@atlaskit/ds-lib": "^2.
|
|
46
|
+
"@atlaskit/ds-lib": "^2.5.0",
|
|
47
47
|
"@atlaskit/logo": "^14.2.0",
|
|
48
48
|
"@atlaskit/primitives": "^12.0.0",
|
|
49
49
|
"@atlaskit/ssr": "*",
|