@mui/codemod 5.11.5 → 5.11.7
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/README.md +48 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.js +68 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.test/actual.js +32 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.test/expected.js +32 -0
- package/node/v5.0.0/joy-rename-classname-prefix.js +12 -0
- package/node/v5.0.0/joy-rename-classname-prefix.test/actual.js +13 -0
- package/node/v5.0.0/joy-rename-classname-prefix.test/expected.js +13 -0
- package/node/v5.0.0/joy-rename-row-prop.js +44 -0
- package/node/v5.0.0/joy-rename-row-prop.test/actual.js +21 -0
- package/node/v5.0.0/joy-rename-row-prop.test/expected.js +21 -0
- package/node/v5.0.0/joy-text-field-to-input.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,54 @@ npx @mui/codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"
|
|
|
62
62
|
|
|
63
63
|
### v5.0.0
|
|
64
64
|
|
|
65
|
+
#### `joy-rename-classname-prefix`
|
|
66
|
+
|
|
67
|
+
Renames the classname prefix from `'Joy'` to `'Mui'` for Joy UI components.
|
|
68
|
+
|
|
69
|
+
```diff
|
|
70
|
+
<Button
|
|
71
|
+
- sx={{ '& .JoyButton-root': { '& .JoyButton-button': {} } }}
|
|
72
|
+
+ sx={{ '& .MuiButton-root': { '& .MuiButton-button': {} } }}
|
|
73
|
+
/>;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
npx @mui/codemod v5.0.0/joy-rename-classname-prefix <path>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### `joy-rename-row-prop`
|
|
81
|
+
|
|
82
|
+
Transforms `row` prop to `orientation` prop across `Card`, `List` and `RadioGroup` components.
|
|
83
|
+
|
|
84
|
+
```diff
|
|
85
|
+
<Card
|
|
86
|
+
- row
|
|
87
|
+
+ orientation={"horizontal"}
|
|
88
|
+
/>;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
npx @mui/codemod v5.0.0/joy-rename-row-prop <path>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### `joy-avatar-remove-imgProps`
|
|
96
|
+
|
|
97
|
+
Remove `imgProps` prop by transferring its value into `slotProps.img`
|
|
98
|
+
|
|
99
|
+
This change only affects Joy UI Avatar component.
|
|
100
|
+
|
|
101
|
+
```diff
|
|
102
|
+
<Avatar
|
|
103
|
+
- imgProps={{ ['data-id']: 'imageId' }}
|
|
104
|
+
- slotProps={{ root: { ['data-id']: 'rootId' }}}
|
|
105
|
+
+ slotProps={{ root: { ['data-id']: 'rootId' }, img: { ['data-id']: 'imageId' } }}
|
|
106
|
+
/>;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
npx @mui/codemod v5.0.0/joy-avatar-remove-imgProps <path>
|
|
111
|
+
```
|
|
112
|
+
|
|
65
113
|
#### `joy-text-field-to-input`
|
|
66
114
|
|
|
67
115
|
Replace `<TextField>` with composition of `Input`
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const root = j(file.source);
|
|
14
|
+
const printOptions = options.printOptions;
|
|
15
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
const sourceVal = node.source.value;
|
|
19
|
+
return ['@mui/joy',
|
|
20
|
+
// Process only Joy UI components
|
|
21
|
+
'@mui/joy/Avatar' // Filter default imports of components other than `Avatar`
|
|
22
|
+
].includes(sourceVal);
|
|
23
|
+
}).forEach(path => {
|
|
24
|
+
path.node.specifiers.forEach(elementNode => {
|
|
25
|
+
var _elementNode$imported;
|
|
26
|
+
if (elementNode.type === 'ImportSpecifier' && ((_elementNode$imported = elementNode.imported) == null ? void 0 : _elementNode$imported.name) === 'Avatar' || elementNode.type === 'ImportDefaultSpecifier') {
|
|
27
|
+
// Process only Joy `Avatar` component
|
|
28
|
+
root.findJSXElements(elementNode.local.name).forEach(elementPath => {
|
|
29
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const slotPropsAttributeNode = elementPath.node.openingElement.attributes.find(attributeNode => {
|
|
33
|
+
var _attributeNode$value$;
|
|
34
|
+
return attributeNode.type === 'JSXAttribute' && attributeNode.name.name === 'slotProps' && ((_attributeNode$value$ = attributeNode.value.expression) == null ? void 0 : _attributeNode$value$.type) === 'ObjectExpression';
|
|
35
|
+
});
|
|
36
|
+
const newAttributeNodes = [];
|
|
37
|
+
elementPath.node.openingElement.attributes.forEach(attributeNode => {
|
|
38
|
+
if (attributeNode.type !== 'JSXAttribute') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (attributeNode.name.name !== 'imgProps') {
|
|
42
|
+
newAttributeNodes.push(attributeNode);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const val = attributeNode.value;
|
|
46
|
+
if (!(val != null && val.expression)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (slotPropsAttributeNode) {
|
|
50
|
+
const imgObjInSlotProps = slotPropsAttributeNode.value.expression.properties.find(propNode => propNode.key.name === 'img' && propNode.value.type === 'ObjectExpression');
|
|
51
|
+
if (imgObjInSlotProps) {
|
|
52
|
+
const newProperties = [...imgObjInSlotProps.value.properties, ...attributeNode.value.expression.properties];
|
|
53
|
+
imgObjInSlotProps.value.properties = newProperties;
|
|
54
|
+
} else {
|
|
55
|
+
slotPropsAttributeNode.value.expression.properties.push(j.objectProperty(j.identifier('img'), attributeNode.value));
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
newAttributeNodes.push(j.jsxAttribute(j.jsxIdentifier('slotProps'), j.jsxExpressionContainer(j.objectExpression([j.objectProperty(j.identifier('img'), attributeNode.value.expression)]))));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
elementPath.node.openingElement.attributes = newAttributeNodes;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const transformed = root.findJSXElements();
|
|
67
|
+
return transformed.toSource(printOptions);
|
|
68
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Avatar = _interopRequireDefault(require("@mui/joy/Avatar"));
|
|
6
|
+
var _Avatar2 = _interopRequireDefault(require("@mui/material/Avatar"));
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
// the codemod should transform only Joy UI `Avatar`;
|
|
9
|
+
|
|
10
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
11
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Avatar, {
|
|
12
|
+
imgProps: {
|
|
13
|
+
['aria-hidden']: true
|
|
14
|
+
}
|
|
15
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
|
16
|
+
slotProps: {
|
|
17
|
+
root: {
|
|
18
|
+
['aria-hidden']: false
|
|
19
|
+
},
|
|
20
|
+
img: {
|
|
21
|
+
['aria-label']: 'imgSlot'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
imgProps: {
|
|
25
|
+
['aria-hidden']: true
|
|
26
|
+
}
|
|
27
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar2.default, {
|
|
28
|
+
imgProps: {
|
|
29
|
+
['aria-hidden']: true
|
|
30
|
+
}
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Avatar = _interopRequireDefault(require("@mui/joy/Avatar"));
|
|
6
|
+
var _Avatar2 = _interopRequireDefault(require("@mui/material/Avatar"));
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
// the codemod should transform only Joy UI `Avatar`;
|
|
9
|
+
|
|
10
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
11
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Avatar, {
|
|
12
|
+
slotProps: {
|
|
13
|
+
img: {
|
|
14
|
+
['aria-hidden']: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
|
18
|
+
slotProps: {
|
|
19
|
+
root: {
|
|
20
|
+
['aria-hidden']: false
|
|
21
|
+
},
|
|
22
|
+
img: {
|
|
23
|
+
['aria-label']: 'imgSlot',
|
|
24
|
+
['aria-hidden']: true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar2.default, {
|
|
28
|
+
imgProps: {
|
|
29
|
+
['aria-hidden']: true
|
|
30
|
+
}
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
*/
|
|
10
|
+
function transformer(file) {
|
|
11
|
+
return file.source.replace(/Joy([A-Z]+)/gm, 'Mui$1');
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
5
|
+
className: "JoyButton-button"
|
|
6
|
+
});
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
|
|
8
|
+
sx: {
|
|
9
|
+
'& .JoyButton-root': {
|
|
10
|
+
'& .JoyButton-button': {}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
5
|
+
className: "MuiButton-button"
|
|
6
|
+
});
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
|
|
8
|
+
sx: {
|
|
9
|
+
'& .MuiButton-root': {
|
|
10
|
+
'& .MuiButton-button': {}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const root = j(file.source);
|
|
14
|
+
const printOptions = options.printOptions;
|
|
15
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
return node.source.value.startsWith('@mui/joy');
|
|
19
|
+
}).forEach(path => {
|
|
20
|
+
path.node.specifiers.forEach(node => {
|
|
21
|
+
// Process only Joy UI components
|
|
22
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
23
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
elementPath.node.openingElement.attributes.forEach(attributeNode => {
|
|
27
|
+
if (attributeNode.type !== 'JSXAttribute') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (attributeNode.name.name === 'row') {
|
|
31
|
+
var _val$expression;
|
|
32
|
+
const val = attributeNode.value;
|
|
33
|
+
if (val === null || (val == null ? void 0 : (_val$expression = val.expression) == null ? void 0 : _val$expression.value) === true) {
|
|
34
|
+
attributeNode.name.name = 'orientation';
|
|
35
|
+
attributeNode.value = j.jsxExpressionContainer(j.literal('horizontal'));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const transformed = root.findJSXElements();
|
|
43
|
+
return transformed.toSource(printOptions);
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Card = _interopRequireDefault(require("@mui/joy/Card"));
|
|
6
|
+
var _RadioGroup = _interopRequireDefault(require("@mui/joy/RadioGroup"));
|
|
7
|
+
var _Custom = _interopRequireDefault(require("components/Custom"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
// the codemod should transform only Joy UI components;
|
|
10
|
+
|
|
11
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
12
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.default, {
|
|
13
|
+
row: true
|
|
14
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.List, {
|
|
15
|
+
row: true
|
|
16
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioGroup.default, {
|
|
17
|
+
row: true
|
|
18
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Custom.default, {
|
|
19
|
+
row: true
|
|
20
|
+
})]
|
|
21
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Card = _interopRequireDefault(require("@mui/joy/Card"));
|
|
6
|
+
var _RadioGroup = _interopRequireDefault(require("@mui/joy/RadioGroup"));
|
|
7
|
+
var _Custom = _interopRequireDefault(require("components/Custom"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
// the codemod should transform only Joy UI components;
|
|
10
|
+
|
|
11
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
12
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.default, {
|
|
13
|
+
orientation: "horizontal"
|
|
14
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.List, {
|
|
15
|
+
orientation: "horizontal"
|
|
16
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioGroup.default, {
|
|
17
|
+
orientation: "horizontal"
|
|
18
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Custom.default, {
|
|
19
|
+
row: true
|
|
20
|
+
})]
|
|
21
|
+
});
|
|
@@ -64,7 +64,6 @@ function transformer(file, api, options) {
|
|
|
64
64
|
}
|
|
65
65
|
propNode.value.properties.forEach(prop => {
|
|
66
66
|
const key = prop.key.value;
|
|
67
|
-
// const value = prop.value.value;
|
|
68
67
|
const newAttributeNode = j.jsxAttribute(j.jsxIdentifier(key), j.jsxExpressionContainer(prop.value));
|
|
69
68
|
switch (propNode.key.name) {
|
|
70
69
|
case 'root':
|