@atlaskit/menu 2.14.2 → 2.14.3
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/package.json +9 -6
- package/codemods/0.7.0-change-css-fn-prop.tsx +0 -149
- package/codemods/2.1.0-invalid-link-item-to-button-item.tsx +0 -146
- package/codemods/__tests__/0.7.0-change-css-fn-prop.tsx +0 -360
- package/codemods/__tests__/next-invalid-link-item-to-button-item.tsx +0 -308
- package/codemods/helpers/generic.tsx +0 -637
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/menu
|
|
2
2
|
|
|
3
|
+
## 2.14.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#113256](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/113256)
|
|
8
|
+
[`ae6561e3b5b1e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ae6561e3b5b1e) -
|
|
9
|
+
Update dependencies and remove old codemods.
|
|
10
|
+
|
|
3
11
|
## 2.14.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/menu",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.3",
|
|
4
4
|
"description": "A list of options to help users navigate, or perform actions.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@atlaskit/focus-ring": "^2.1.0",
|
|
47
47
|
"@atlaskit/interaction-context": "^2.6.0",
|
|
48
48
|
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
49
|
-
"@atlaskit/primitives": "^13.
|
|
49
|
+
"@atlaskit/primitives": "^13.5.0",
|
|
50
50
|
"@atlaskit/theme": "^15.0.0",
|
|
51
51
|
"@atlaskit/tokens": "^3.3.0",
|
|
52
52
|
"@babel/runtime": "^7.0.0",
|
|
@@ -60,15 +60,19 @@
|
|
|
60
60
|
"@af/accessibility-testing": "*",
|
|
61
61
|
"@af/integration-testing": "*",
|
|
62
62
|
"@af/visual-regression": "*",
|
|
63
|
+
"@atlaskit/button": "^20.5.1",
|
|
64
|
+
"@atlaskit/docs": "*",
|
|
65
|
+
"@atlaskit/icon": "^23.8.0",
|
|
66
|
+
"@atlaskit/icon-file-type": "^6.9.0",
|
|
67
|
+
"@atlaskit/icon-object": "^6.10.1",
|
|
68
|
+
"@atlaskit/link": "*",
|
|
69
|
+
"@atlaskit/section-message": "*",
|
|
63
70
|
"@atlaskit/visual-regression": "*",
|
|
64
71
|
"@atlassian/feature-flags-test-utils": "*",
|
|
65
72
|
"@emotion/jest": "^11.8.0",
|
|
66
|
-
"@testing-library/dom": "^10.1.0",
|
|
67
73
|
"@testing-library/react": "^13.4.0",
|
|
68
74
|
"ast-types": "^0.13.3",
|
|
69
|
-
"bind-event-listener": "^3.0.0",
|
|
70
75
|
"jscodeshift": "^0.13.0",
|
|
71
|
-
"storybook-addon-performance": "^0.17.3",
|
|
72
76
|
"typescript": "~5.4.2"
|
|
73
77
|
},
|
|
74
78
|
"keywords": [
|
|
@@ -81,7 +85,6 @@
|
|
|
81
85
|
"import-structure": "atlassian-conventions"
|
|
82
86
|
},
|
|
83
87
|
"@repo/internal": {
|
|
84
|
-
"dom-events": "use-bind-event-listener",
|
|
85
88
|
"ui-components": "lite-mode",
|
|
86
89
|
"design-system": "v1",
|
|
87
90
|
"styling": [
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { type NodePath } from 'ast-types/lib/node-path';
|
|
2
|
-
import type {
|
|
3
|
-
API,
|
|
4
|
-
ASTPath,
|
|
5
|
-
default as core,
|
|
6
|
-
FileInfo,
|
|
7
|
-
ImportDeclaration,
|
|
8
|
-
ImportSpecifier,
|
|
9
|
-
Options,
|
|
10
|
-
} from 'jscodeshift';
|
|
11
|
-
|
|
12
|
-
import { addCommentBeforeJSX, getDefaultSpecifierName } from './helpers/generic';
|
|
13
|
-
|
|
14
|
-
function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
|
|
15
|
-
return j(element)
|
|
16
|
-
.find(j.JSXOpeningElement)
|
|
17
|
-
.find(j.JSXAttribute)
|
|
18
|
-
.filter((attribute) => {
|
|
19
|
-
const matches = j(attribute)
|
|
20
|
-
.find(j.JSXIdentifier)
|
|
21
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
22
|
-
return Boolean(matches.length);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function getImportSpecifier(
|
|
27
|
-
j: core.JSCodeshift,
|
|
28
|
-
source: ReturnType<typeof j>,
|
|
29
|
-
specifier: string,
|
|
30
|
-
imported: string,
|
|
31
|
-
) {
|
|
32
|
-
const specifiers = source
|
|
33
|
-
.find(j.ImportDeclaration)
|
|
34
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
35
|
-
.find(j.ImportSpecifier)
|
|
36
|
-
.filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
|
|
37
|
-
|
|
38
|
-
if (!specifiers.length) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function updateCssFnProp(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
46
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
47
|
-
const cssFnPropCollection = getJSXAttributesByName(j, element, 'cssFn');
|
|
48
|
-
|
|
49
|
-
// no cssProp usage for this element
|
|
50
|
-
if (!cssFnPropCollection.length) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const cssFnProp = cssFnPropCollection.get();
|
|
55
|
-
|
|
56
|
-
const cssFnExpression: NodePath = j(cssFnProp)
|
|
57
|
-
.find(j.JSXExpressionContainer)
|
|
58
|
-
.find(j.Expression)
|
|
59
|
-
.get();
|
|
60
|
-
|
|
61
|
-
if (cssFnExpression) {
|
|
62
|
-
// just remove the state styles param
|
|
63
|
-
try {
|
|
64
|
-
const [stylePropName] = cssFnExpression!.value.params;
|
|
65
|
-
j(cssFnExpression)
|
|
66
|
-
.find(j.SpreadElement)
|
|
67
|
-
.forEach((n) => {
|
|
68
|
-
// discerns whether there are multiple identifiers here
|
|
69
|
-
const isComplexIdentifier = j(n).find(j.Identifier).length > 1;
|
|
70
|
-
|
|
71
|
-
if (isComplexIdentifier) {
|
|
72
|
-
throw new Error('CSSFn Prop codemod: Unable to parse spread element');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const hasStyleProp = !!j(n)
|
|
76
|
-
.find(j.Identifier)
|
|
77
|
-
.filter((node) => node.value.name === stylePropName.name).length;
|
|
78
|
-
if (hasStyleProp) {
|
|
79
|
-
j(n).remove();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
cssFnExpression!.value.params.shift();
|
|
84
|
-
} catch (e) {
|
|
85
|
-
addCommentBeforeJSX(
|
|
86
|
-
j,
|
|
87
|
-
cssFnProp,
|
|
88
|
-
`
|
|
89
|
-
The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
90
|
-
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
91
|
-
For more info please reach out to #help-design-system-code.
|
|
92
|
-
`,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function hasImportDeclaration(
|
|
100
|
-
j: core.JSCodeshift,
|
|
101
|
-
source: ReturnType<typeof j>,
|
|
102
|
-
importPath: string,
|
|
103
|
-
) {
|
|
104
|
-
return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
|
|
105
|
-
.length;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
109
|
-
const source = j(fileInfo.source);
|
|
110
|
-
|
|
111
|
-
if (hasImportDeclaration(j, source, '@atlaskit/menu')) {
|
|
112
|
-
const defaultSpecifier = getDefaultSpecifierName({
|
|
113
|
-
j,
|
|
114
|
-
base: source,
|
|
115
|
-
packageName: '@atlaskit/menu',
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (defaultSpecifier != null) {
|
|
119
|
-
updateCssFnProp(j, source, defaultSpecifier);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
[
|
|
123
|
-
'ButtonItem',
|
|
124
|
-
'LinkItem',
|
|
125
|
-
'CustomItem',
|
|
126
|
-
'HeadingItem',
|
|
127
|
-
'SkeletonItem',
|
|
128
|
-
'SkeletonHeadingItem',
|
|
129
|
-
'MenuGroup',
|
|
130
|
-
'PopupMenuGroup',
|
|
131
|
-
'Section',
|
|
132
|
-
].forEach((pkg) => {
|
|
133
|
-
const importSpecifier = getImportSpecifier(j, source, '@atlaskit/menu', pkg);
|
|
134
|
-
|
|
135
|
-
if (importSpecifier != null) {
|
|
136
|
-
updateCssFnProp(j, source, importSpecifier);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return source.toSource(
|
|
141
|
-
options.printOptions || {
|
|
142
|
-
quote: 'single',
|
|
143
|
-
trailingComma: true,
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return fileInfo.source;
|
|
149
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
API,
|
|
3
|
-
ASTPath,
|
|
4
|
-
default as core,
|
|
5
|
-
FileInfo,
|
|
6
|
-
ImportDeclaration,
|
|
7
|
-
ImportSpecifier,
|
|
8
|
-
Options,
|
|
9
|
-
} from 'jscodeshift';
|
|
10
|
-
|
|
11
|
-
const invalidHrefValues = ['', '#'];
|
|
12
|
-
const pkg = '@atlaskit/menu';
|
|
13
|
-
|
|
14
|
-
function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
|
|
15
|
-
return j(element)
|
|
16
|
-
.find(j.JSXOpeningElement)
|
|
17
|
-
.find(j.JSXAttribute)
|
|
18
|
-
.filter((attribute) => {
|
|
19
|
-
const matches = j(attribute)
|
|
20
|
-
.find(j.JSXIdentifier)
|
|
21
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
22
|
-
return Boolean(matches.length);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function getImportSpecifier(
|
|
27
|
-
j: core.JSCodeshift,
|
|
28
|
-
source: ReturnType<typeof j>,
|
|
29
|
-
specifier: string,
|
|
30
|
-
imported: string,
|
|
31
|
-
) {
|
|
32
|
-
const specifiers = source
|
|
33
|
-
.find(j.ImportDeclaration)
|
|
34
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
35
|
-
.find(j.ImportSpecifier)
|
|
36
|
-
.filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
|
|
37
|
-
|
|
38
|
-
if (!specifiers.length) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function convertInvalidLinkItemsToButtonItems(
|
|
46
|
-
j: core.JSCodeshift,
|
|
47
|
-
source: ReturnType<typeof j>,
|
|
48
|
-
specifier: string,
|
|
49
|
-
) {
|
|
50
|
-
// For each instance of LinkItem
|
|
51
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
52
|
-
const hrefPropCollection = getJSXAttributesByName(j, element, 'href');
|
|
53
|
-
|
|
54
|
-
// base case: no `href` prop exists, it is invalid
|
|
55
|
-
let validHref = false;
|
|
56
|
-
|
|
57
|
-
// if `href` exists
|
|
58
|
-
if (hrefPropCollection.length > 0) {
|
|
59
|
-
const hrefProp = hrefPropCollection.get();
|
|
60
|
-
|
|
61
|
-
const hrefStringLiteral = j(hrefProp).find(j.StringLiteral);
|
|
62
|
-
const hrefExpressionContainer = j(hrefProp).find(j.JSXExpressionContainer).find(j.Expression);
|
|
63
|
-
|
|
64
|
-
// This is tin foil hattery. Can something be neither a string literal
|
|
65
|
-
// nor an expression container? Don't know but gonna cover that
|
|
66
|
-
if (hrefStringLiteral.length === 0 && hrefExpressionContainer.length === 0) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (hrefStringLiteral.length > 0) {
|
|
71
|
-
const hrefValue = hrefStringLiteral.get().value.value;
|
|
72
|
-
if (invalidHrefValues.includes(hrefValue)) {
|
|
73
|
-
j(hrefProp).forEach((el) => j(el).remove());
|
|
74
|
-
} else {
|
|
75
|
-
validHref = true;
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
// It seems foolish to try and resolve variables, so we will assume it
|
|
79
|
-
// is valid
|
|
80
|
-
validHref = true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (!validHref) {
|
|
85
|
-
const pkgImport = source
|
|
86
|
-
.find(j.ImportDeclaration)
|
|
87
|
-
.filter((path) => path.node.source.value === pkg);
|
|
88
|
-
const buttonItemIsImported =
|
|
89
|
-
pkgImport
|
|
90
|
-
.find(j.ImportSpecifier)
|
|
91
|
-
.nodes()
|
|
92
|
-
.filter((node) => node.imported.name === 'ButtonItem').length > 0;
|
|
93
|
-
if (!buttonItemIsImported) {
|
|
94
|
-
// Add ButtonItem to imports
|
|
95
|
-
const newSpecifier = j.importSpecifier(j.identifier('ButtonItem'));
|
|
96
|
-
pkgImport.forEach((moduleImport) => {
|
|
97
|
-
const specifiers = moduleImport.node.specifiers ? [...moduleImport.node.specifiers] : [];
|
|
98
|
-
j(moduleImport).replaceWith(
|
|
99
|
-
j.importDeclaration(specifiers.concat([newSpecifier]), moduleImport.node.source),
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Replace existing LinkItem with ButtonItem, while maintaining the same props
|
|
105
|
-
if (element.value.openingElement.name.type === 'JSXIdentifier') {
|
|
106
|
-
element.value.openingElement.name.name = 'ButtonItem';
|
|
107
|
-
if (
|
|
108
|
-
element.value.closingElement &&
|
|
109
|
-
element.value.closingElement.name.type === 'JSXIdentifier'
|
|
110
|
-
) {
|
|
111
|
-
element.value.closingElement.name.name = 'ButtonItem';
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function hasImportDeclaration(
|
|
119
|
-
j: core.JSCodeshift,
|
|
120
|
-
source: ReturnType<typeof j>,
|
|
121
|
-
importPath: string,
|
|
122
|
-
) {
|
|
123
|
-
return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
|
|
124
|
-
.length;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
128
|
-
const source = j(fileInfo.source);
|
|
129
|
-
|
|
130
|
-
if (hasImportDeclaration(j, source, pkg)) {
|
|
131
|
-
const importSpecifier = getImportSpecifier(j, source, pkg, 'LinkItem');
|
|
132
|
-
|
|
133
|
-
if (importSpecifier != null) {
|
|
134
|
-
convertInvalidLinkItemsToButtonItems(j, source, importSpecifier);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return source.toSource(
|
|
138
|
-
options.printOptions || {
|
|
139
|
-
quote: 'single',
|
|
140
|
-
trailingComma: true,
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return fileInfo.source;
|
|
146
|
-
}
|
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
jest.autoMockOff();
|
|
2
|
-
|
|
3
|
-
import * as transformer from '../0.7.0-change-css-fn-prop';
|
|
4
|
-
|
|
5
|
-
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
6
|
-
|
|
7
|
-
describe('Updates and removes current inline styles', () => {
|
|
8
|
-
defineInlineTest(
|
|
9
|
-
{ ...transformer, parser: 'tsx' },
|
|
10
|
-
{},
|
|
11
|
-
`
|
|
12
|
-
import { ButtonItem } from '@atlaskit/something';
|
|
13
|
-
|
|
14
|
-
const App = () => {
|
|
15
|
-
return <ButtonItem />;
|
|
16
|
-
}
|
|
17
|
-
`,
|
|
18
|
-
`
|
|
19
|
-
import { ButtonItem } from '@atlaskit/something';
|
|
20
|
-
|
|
21
|
-
const App = () => {
|
|
22
|
-
return <ButtonItem />;
|
|
23
|
-
}
|
|
24
|
-
`,
|
|
25
|
-
'leaves unrelated code untouched',
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
defineInlineTest(
|
|
29
|
-
{ ...transformer, parser: 'tsx' },
|
|
30
|
-
{},
|
|
31
|
-
`
|
|
32
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
33
|
-
|
|
34
|
-
const App = () => {
|
|
35
|
-
return <ButtonItem cssFn={(styles, state) => ({
|
|
36
|
-
|
|
37
|
-
})} />;
|
|
38
|
-
}
|
|
39
|
-
`,
|
|
40
|
-
`
|
|
41
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
42
|
-
|
|
43
|
-
const App = () => {
|
|
44
|
-
return (
|
|
45
|
-
<ButtonItem cssFn={state => {
|
|
46
|
-
|
|
47
|
-
}} />
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
`,
|
|
51
|
-
'should remove current styles from inline function',
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
defineInlineTest(
|
|
55
|
-
{ ...transformer, parser: 'tsx' },
|
|
56
|
-
{},
|
|
57
|
-
`
|
|
58
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
59
|
-
|
|
60
|
-
const App = () => {
|
|
61
|
-
return (
|
|
62
|
-
<div cssFn={(styles, state) => ({
|
|
63
|
-
...styles,
|
|
64
|
-
})}>
|
|
65
|
-
<ButtonItem
|
|
66
|
-
cssFn={(styles, state) => ({
|
|
67
|
-
...styles,
|
|
68
|
-
})}
|
|
69
|
-
/>
|
|
70
|
-
</div>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
`,
|
|
75
|
-
`
|
|
76
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
77
|
-
|
|
78
|
-
const App = () => {
|
|
79
|
-
return (
|
|
80
|
-
<div cssFn={(styles, state) => ({
|
|
81
|
-
...styles,
|
|
82
|
-
})}>
|
|
83
|
-
<ButtonItem
|
|
84
|
-
cssFn={state => ({})}
|
|
85
|
-
/>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
`,
|
|
90
|
-
'should remove current styles from scope',
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
defineInlineTest(
|
|
94
|
-
{ ...transformer, parser: 'tsx' },
|
|
95
|
-
{},
|
|
96
|
-
`
|
|
97
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
98
|
-
|
|
99
|
-
const App = () => {
|
|
100
|
-
return <ButtonItem cssFn={(styles, state) => ({
|
|
101
|
-
...styles,
|
|
102
|
-
color: 'red',
|
|
103
|
-
})} />;
|
|
104
|
-
}
|
|
105
|
-
`,
|
|
106
|
-
`
|
|
107
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
108
|
-
|
|
109
|
-
const App = () => {
|
|
110
|
-
return (
|
|
111
|
-
<ButtonItem cssFn={state => ({
|
|
112
|
-
color: 'red',
|
|
113
|
-
})} />
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
`,
|
|
117
|
-
'correctly removes spread styles',
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
defineInlineTest(
|
|
121
|
-
{ ...transformer, parser: 'tsx' },
|
|
122
|
-
{},
|
|
123
|
-
`
|
|
124
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
125
|
-
|
|
126
|
-
const App = () => {
|
|
127
|
-
return <ButtonItem cssFn={(styles, state) => ({
|
|
128
|
-
...styles,
|
|
129
|
-
color: 'red',
|
|
130
|
-
':hover': {
|
|
131
|
-
...styles[':hover'],
|
|
132
|
-
color: 'blue',
|
|
133
|
-
}
|
|
134
|
-
})} />;
|
|
135
|
-
}
|
|
136
|
-
`,
|
|
137
|
-
`
|
|
138
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
139
|
-
|
|
140
|
-
const App = () => {
|
|
141
|
-
return (
|
|
142
|
-
<ButtonItem cssFn={state => ({
|
|
143
|
-
color: 'red',
|
|
144
|
-
|
|
145
|
-
':hover': {
|
|
146
|
-
color: 'blue',
|
|
147
|
-
},
|
|
148
|
-
})} />
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
`,
|
|
152
|
-
'correctly removes spread styles with pseudo-selector access',
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
defineInlineTest(
|
|
156
|
-
{ ...transformer, parser: 'tsx' },
|
|
157
|
-
{},
|
|
158
|
-
`
|
|
159
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
160
|
-
|
|
161
|
-
const App = () => {
|
|
162
|
-
return (
|
|
163
|
-
<ButtonItem cssFn={(styles, state) => ({
|
|
164
|
-
...(state.x ? styles : {}),
|
|
165
|
-
color: 'red',
|
|
166
|
-
})} />
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
`,
|
|
170
|
-
`
|
|
171
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
172
|
-
|
|
173
|
-
const App = () => {
|
|
174
|
-
return (
|
|
175
|
-
<ButtonItem
|
|
176
|
-
/*
|
|
177
|
-
TODO: (from codemod) The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
178
|
-
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
179
|
-
For more info please reach out to #help-design-system-code.
|
|
180
|
-
*/
|
|
181
|
-
cssFn={(styles, state) => ({
|
|
182
|
-
...(state.x ? styles : {}),
|
|
183
|
-
color: 'red',
|
|
184
|
-
})} />
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
`,
|
|
188
|
-
'fail smoothly if the current styles are being used in a non-trivial way',
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
defineInlineTest(
|
|
192
|
-
{ ...transformer, parser: 'tsx' },
|
|
193
|
-
{},
|
|
194
|
-
`
|
|
195
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
196
|
-
|
|
197
|
-
const App = () => {
|
|
198
|
-
return <ButtonItem cssFn={() => ({
|
|
199
|
-
color: 'red',
|
|
200
|
-
})} />;
|
|
201
|
-
}
|
|
202
|
-
`,
|
|
203
|
-
`
|
|
204
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
205
|
-
|
|
206
|
-
const App = () => {
|
|
207
|
-
return <ButtonItem cssFn={() => ({
|
|
208
|
-
color: 'red',
|
|
209
|
-
})} />;
|
|
210
|
-
}
|
|
211
|
-
`,
|
|
212
|
-
'not change anything if user is not using the current state or styles',
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
defineInlineTest(
|
|
216
|
-
{ ...transformer, parser: 'tsx' },
|
|
217
|
-
{},
|
|
218
|
-
`
|
|
219
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
220
|
-
|
|
221
|
-
const App = () => {
|
|
222
|
-
return <ButtonItem cssFn={(styles, state) => ({
|
|
223
|
-
...styles,
|
|
224
|
-
color: 'red',
|
|
225
|
-
})}>
|
|
226
|
-
<ButtonItem cssFn={(styles, state) => ({
|
|
227
|
-
...styles,
|
|
228
|
-
color: 'red',
|
|
229
|
-
})}/>
|
|
230
|
-
</ButtonItem>;
|
|
231
|
-
}
|
|
232
|
-
`,
|
|
233
|
-
`
|
|
234
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
235
|
-
|
|
236
|
-
const App = () => {
|
|
237
|
-
return (
|
|
238
|
-
<ButtonItem cssFn={state => ({
|
|
239
|
-
color: 'red',
|
|
240
|
-
})}>
|
|
241
|
-
<ButtonItem cssFn={state => ({
|
|
242
|
-
color: 'red',
|
|
243
|
-
})}/>
|
|
244
|
-
</ButtonItem>
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
`,
|
|
248
|
-
'should remove styles in nested children',
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
defineInlineTest(
|
|
252
|
-
{ ...transformer, parser: 'tsx' },
|
|
253
|
-
{},
|
|
254
|
-
`
|
|
255
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
256
|
-
|
|
257
|
-
const App = () => {
|
|
258
|
-
return <ButtonItem />;
|
|
259
|
-
}
|
|
260
|
-
`,
|
|
261
|
-
`
|
|
262
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
263
|
-
|
|
264
|
-
const App = () => {
|
|
265
|
-
return <ButtonItem />;
|
|
266
|
-
}
|
|
267
|
-
`,
|
|
268
|
-
'should leave affected items with no use of cssFn untouched',
|
|
269
|
-
);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe('Updates and removes current styles', () => {
|
|
273
|
-
defineInlineTest(
|
|
274
|
-
{ ...transformer, parser: 'tsx' },
|
|
275
|
-
{},
|
|
276
|
-
`
|
|
277
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
278
|
-
|
|
279
|
-
const cssFn = (styles, state) => ({
|
|
280
|
-
...styles,
|
|
281
|
-
color: 'red',
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
const App = () => {
|
|
285
|
-
return <ButtonItem cssFn={cssFn} />;
|
|
286
|
-
}
|
|
287
|
-
`,
|
|
288
|
-
`
|
|
289
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
290
|
-
|
|
291
|
-
const cssFn = (styles, state) => ({
|
|
292
|
-
...styles,
|
|
293
|
-
color: 'red',
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
const App = () => {
|
|
297
|
-
return (
|
|
298
|
-
<ButtonItem
|
|
299
|
-
/*
|
|
300
|
-
TODO: (from codemod) The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
301
|
-
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
302
|
-
For more info please reach out to #help-design-system-code.
|
|
303
|
-
*/
|
|
304
|
-
cssFn={cssFn} />
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
`,
|
|
308
|
-
'should add prompt for non-inline function',
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
defineInlineTest(
|
|
312
|
-
{ ...transformer, parser: 'tsx' },
|
|
313
|
-
{},
|
|
314
|
-
`
|
|
315
|
-
import { ButtonItem, LinkItem } from '@atlaskit/menu';
|
|
316
|
-
|
|
317
|
-
const cssFunction = (styles, state) => ({
|
|
318
|
-
...styles,
|
|
319
|
-
color: 'red',
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
const App = () => {
|
|
323
|
-
return (
|
|
324
|
-
<ButtonItem cssFn={cssFunction}>
|
|
325
|
-
<LinkItem cssFn={cssFunction} />
|
|
326
|
-
</ButtonItem>
|
|
327
|
-
);
|
|
328
|
-
};
|
|
329
|
-
`,
|
|
330
|
-
`
|
|
331
|
-
import { ButtonItem, LinkItem } from '@atlaskit/menu';
|
|
332
|
-
|
|
333
|
-
const cssFunction = (styles, state) => ({
|
|
334
|
-
...styles,
|
|
335
|
-
color: 'red',
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
const App = () => {
|
|
339
|
-
return (
|
|
340
|
-
<ButtonItem
|
|
341
|
-
/*
|
|
342
|
-
TODO: (from codemod) The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
343
|
-
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
344
|
-
For more info please reach out to #help-design-system-code.
|
|
345
|
-
*/
|
|
346
|
-
cssFn={cssFunction}>
|
|
347
|
-
<LinkItem
|
|
348
|
-
/*
|
|
349
|
-
TODO: (from codemod) The usage of the 'cssFn' prop in this component could not be transformed and requires manual intervention.
|
|
350
|
-
The 'cssFn' prop has been simplified so that users no longer need to merge the inherited styles with their own overrides.
|
|
351
|
-
For more info please reach out to #help-design-system-code.
|
|
352
|
-
*/
|
|
353
|
-
cssFn={cssFunction} />
|
|
354
|
-
</ButtonItem>
|
|
355
|
-
);
|
|
356
|
-
};
|
|
357
|
-
`,
|
|
358
|
-
'should add prompt for non-inline function to multiple instances',
|
|
359
|
-
);
|
|
360
|
-
});
|