@mui/codemod 6.0.0-alpha.1 → 6.0.0-alpha.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.
Files changed (56) hide show
  1. package/README.md +153 -2
  2. package/node/deprecations/accordion-props/accordion-props.js +11 -71
  3. package/node/deprecations/accordion-props/test-cases/actual.js +16 -0
  4. package/node/deprecations/accordion-props/test-cases/expected.js +14 -0
  5. package/node/deprecations/accordion-props/test-cases/theme.actual.js +24 -0
  6. package/node/deprecations/accordion-props/test-cases/theme.expected.js +24 -0
  7. package/node/deprecations/all/deprecations-all.js +4 -0
  8. package/node/deprecations/all/postcss.config.js +7 -1
  9. package/node/deprecations/avatar-props/avatar-props.js +5 -39
  10. package/node/deprecations/avatar-props/test-cases/actual.js +10 -0
  11. package/node/deprecations/avatar-props/test-cases/expected.js +10 -0
  12. package/node/deprecations/avatar-props/test-cases/theme.actual.js +14 -0
  13. package/node/deprecations/avatar-props/test-cases/theme.expected.js +15 -0
  14. package/node/deprecations/backdrop-props/backdrop-props.js +5 -61
  15. package/node/deprecations/backdrop-props/test-cases/actual.js +8 -7
  16. package/node/deprecations/backdrop-props/test-cases/expected.js +7 -7
  17. package/node/deprecations/backdrop-props/test-cases/theme.actual.js +11 -0
  18. package/node/deprecations/backdrop-props/test-cases/theme.expected.js +12 -2
  19. package/node/deprecations/step-connector-classes/index.js +13 -0
  20. package/node/deprecations/step-connector-classes/postcss-plugin.js +33 -0
  21. package/node/deprecations/step-connector-classes/postcss.config.js +8 -0
  22. package/node/deprecations/step-connector-classes/step-connector-classes.js +77 -0
  23. package/node/deprecations/step-connector-classes/test-cases/actual.js +7 -0
  24. package/node/deprecations/step-connector-classes/test-cases/expected.js +7 -0
  25. package/node/deprecations/step-label-props/step-label-props.js +14 -0
  26. package/node/deprecations/step-label-props/test-cases/actual.js +23 -0
  27. package/node/deprecations/step-label-props/test-cases/expected.js +24 -0
  28. package/node/deprecations/step-label-props/test-cases/theme.actual.js +22 -0
  29. package/node/deprecations/step-label-props/test-cases/theme.expected.js +25 -0
  30. package/node/deprecations/toggle-button-group-classes/index.js +13 -0
  31. package/node/deprecations/toggle-button-group-classes/postcss-plugin.js +33 -0
  32. package/node/deprecations/toggle-button-group-classes/postcss.config.js +8 -0
  33. package/node/deprecations/toggle-button-group-classes/test-cases/actual.js +7 -0
  34. package/node/deprecations/toggle-button-group-classes/test-cases/expected.js +7 -0
  35. package/node/deprecations/toggle-button-group-classes/toggle-button-group-classes.js +77 -0
  36. package/node/deprecations/utils/movePropIntoSlotProps.js +111 -0
  37. package/node/deprecations/utils/movePropIntoSlots.js +101 -0
  38. package/node/v5.0.0/base-remove-unstyled-suffix.js +4 -4
  39. package/node/v5.0.0/styled-engine-provider.test/theme-provider.expected.js +3 -3
  40. package/node/v6.0.0/styled/index.js +13 -0
  41. package/node/v6.0.0/styled/styled-v6.js +478 -0
  42. package/node/v6.0.0/styled/test-cases/BasicStyled.actual.js +54 -0
  43. package/node/v6.0.0/styled/test-cases/BasicStyled.expected.js +104 -0
  44. package/node/v6.0.0/styled/test-cases/ConditionalStyled.actual.js +115 -0
  45. package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +206 -0
  46. package/node/v6.0.0/styled/test-cases/LogicalStyled.actual.js +28 -0
  47. package/node/v6.0.0/styled/test-cases/LogicalStyled.expected.js +52 -0
  48. package/node/v6.0.0/styled/test-cases/NestedSpread.actual.js +42 -0
  49. package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +85 -0
  50. package/node/v6.0.0/styled/test-cases/ObjectMap.actual.js +36 -0
  51. package/node/v6.0.0/styled/test-cases/ObjectMap.expected.js +109 -0
  52. package/node/v6.0.0/styled/test-cases/ThemePaletteMode.actual.js +62 -0
  53. package/node/v6.0.0/styled/test-cases/ThemePaletteMode.expected.js +76 -0
  54. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.actual.js +11 -0
  55. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.expected.js +19 -0
  56. package/package.json +3 -3
package/README.md CHANGED
@@ -948,20 +948,65 @@ npx @mui/codemod@next deprecations/pagination-item-classes <path>
948
948
  npx @mui/codemod@next deprecations/slider-props <path>
949
949
  ```
950
950
 
951
+ #### `toggle-button-group-classes`
952
+
953
+ JS transforms:
954
+
955
+ ```diff
956
+ import { toggleButtonGroupClasses } from '@mui/material/ToggleButtonGroup';
957
+
958
+ MuiToggleButtonGroup: {
959
+ styleOverrides: {
960
+ root: {
961
+ - [`& .${toggleButtonGroupClasses.groupedHorizontal}`]: {
962
+ + [`&.${toggleButtonGroupClasses.horizontal} > .${toggleButtonGroupClasses.grouped}`]: {
963
+ color: 'red',
964
+ },
965
+ - [`& .${toggleButtonGroupClasses.groupedVertical}`]: {
966
+ + [`&.${toggleButtonGroupClasses.vertical} > .${toggleButtonGroupClasses.grouped}`]: {
967
+ color: 'red',
968
+ },
969
+ },
970
+ },
971
+ },
972
+ ```
973
+
974
+ CSS transforms:
975
+
976
+ ```diff
977
+ -.MuiToggleButtonGroup-root .MuiToggleButtonGroup-groupedHorizontal
978
+ +.MuiToggleButtonGroup-root.MuiToggleButtonGroup-horizontal > .MuiToggleButtonGroup-grouped
979
+ -.MuiToggleButtonGroup-root .MuiToggleButtonGroup-groupedVertical
980
+ +.MuiToggleButtonGroup-root.MuiToggleButtonGroup-vertical > .MuiToggleButtonGroup-grouped
981
+ />
982
+ ```
983
+
984
+ ```bash
985
+ npx @mui/codemod@latest deprecations/toggle-button-group-classes <path>
986
+ ```
987
+
951
988
  #### `step-label-props`
952
989
 
953
990
  ```diff
954
991
  <StepLabel
955
992
  - componentsProps={{ label: labelProps }}
956
993
  + slotProps={{ label: labelProps }}
994
+ - StepIconComponent={StepIconComponent}
995
+ + slots={{ stepIcon: StepIconComponent }}
996
+ - StepIconProps={StepIconProps}
997
+ + slotProps={{ stepIcon: StepIconProps }}
957
998
  />
958
999
  ```
959
1000
 
960
1001
  ```diff
961
1002
  MuiStepLabel: {
962
1003
  defaultProps: {
963
- - componentsProps={{ label: labelProps }}
964
- + slotProps={{ label: labelProps }}
1004
+ - componentsProps:{ label: labelProps }
1005
+ + slotProps:{ label: labelProps }
1006
+ - StepIconComponent:StepIconComponent
1007
+ + slots:{ stepIcon: StepIconComponent }
1008
+ - StepIconProps:StepIconProps
1009
+ + slotProps:{ stepIcon: StepIconProps }
965
1010
  },
966
1011
  },
967
1012
  ```
@@ -971,8 +1016,114 @@ npx @mui/codemod@latest deprecations/step-label-props <path>
971
1016
 
972
1017
  ```
973
1018
 
1019
+ #### `step-connector-classes`
1020
+
1021
+ JS transforms:
1022
+
1023
+ ```diff
1024
+ import { stepConnectorClasses } from '@mui/material/StepConnector';
1025
+
1026
+ MuiStepConnector: {
1027
+ styleOverrides: {
1028
+ root: {
1029
+ - [`& .${stepConnectorClasses.lineHorizontal}`]: {
1030
+ + [`&.${stepConnectorClasses.horizontal} > .${stepConnectorClasses.line}`]: {
1031
+ color: 'red',
1032
+ },
1033
+ - [`& .${stepConnectorClasses.lineVertical}`]: {
1034
+ + [`&.${stepConnectorClasses.vertical} > .${stepConnectorClasses.line}`]: {
1035
+ color: 'red',
1036
+ },
1037
+ },
1038
+ },
1039
+ },
1040
+ ```
1041
+
1042
+ CSS transforms:
1043
+
1044
+ ```diff
1045
+ - .MuiStepConnector-lineHorizontal
1046
+ +.MuiStepConnector-horizontal > .MuiStepConnector-line
1047
+ - .MuiStepConnector-lineVertical
1048
+ +.MuiStepConnector-vertical > .MuiStepConnector-line
1049
+ ```
1050
+
1051
+ ```bash
1052
+ npx @mui/codemod@next deprecations/step-connector-classes <path>
1053
+ ```
1054
+
974
1055
  ### v6.0.0
975
1056
 
1057
+ #### `styled-v6`
1058
+
1059
+ Updates the usage of `styled` from `@mui/system@v5` to be compatible with `@pigment-css/react`.
1060
+
1061
+ This codemod transforms the styles based on props to `variants` by looking for `styled` calls:
1062
+
1063
+ ```diff
1064
+ styled('div')(({ theme, disabled }) => ({
1065
+ color: theme.palette.primary.main,
1066
+ - ...(disabled && {
1067
+ - opacity: 0.5,
1068
+ - }),
1069
+ + variants: [
1070
+ + {
1071
+ + prop: 'disabled',
1072
+ + style: {
1073
+ + opacity: 0.5,
1074
+ + },
1075
+ + },
1076
+ + ],
1077
+ }));
1078
+ ```
1079
+
1080
+ This codemod can handle complex styles with spread operators, ternary operators, and nested objects.
1081
+
1082
+ However, it has some **limitations**:
1083
+
1084
+ - It does not transform dynamic values as shown below:
1085
+
1086
+ ```js
1087
+ const ResizableContainer = styled('div')(({ ownerState, theme }) => ({
1088
+ width: ownerState.width ?? '100%',
1089
+ height: ownerState.height ?? '100%',
1090
+ }));
1091
+ ```
1092
+
1093
+ You need to manually declare a CSS variable and set the values using inline styles:
1094
+
1095
+ ```js
1096
+ // ✅ Recommended way
1097
+ const ResizableContainer = styled('div')({
1098
+ width: 'var(--ResizableContainer-width, 100%)',
1099
+ height: 'var(--ResizableContainer-height, 100%)',
1100
+ });
1101
+ ```
1102
+
1103
+ - It does not transform dynamic reference from the theme, for example color palette.
1104
+
1105
+ ```js
1106
+ const Test = styled('div')(({ ownerState, theme }) => ({
1107
+ backgroundColor: (theme.vars || theme).palette[ownerState.color]?.main,
1108
+ }));
1109
+ ```
1110
+
1111
+ You need to manually iterate the theme object and create `variants` for each color.
1112
+
1113
+ ```js
1114
+ // ✅ Recommended way
1115
+ const Test = styled('div')(({ theme }) => ({
1116
+ variants: Object.entries(theme.palette)
1117
+ .filter(([color, value]) => value.main)
1118
+ .map(([color, value]) => ({
1119
+ props: { color },
1120
+ style: {
1121
+ backgroundColor: value.main,
1122
+ },
1123
+ })),
1124
+ }));
1125
+ ```
1126
+
976
1127
  ### v5.0.0
977
1128
 
978
1129
  #### `base-use-named-exports`
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
- var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
9
- var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
- var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
8
+ var _movePropIntoSlots = _interopRequireDefault(require("../utils/movePropIntoSlots"));
9
+ var _movePropIntoSlotProps = _interopRequireDefault(require("../utils/movePropIntoSlotProps"));
11
10
  /**
12
11
  * @param {import('jscodeshift').FileInfo} file
13
12
  * @param {import('jscodeshift').API} api
@@ -16,76 +15,17 @@ function transformer(file, api, options) {
16
15
  const j = api.jscodeshift;
17
16
  const root = j(file.source);
18
17
  const printOptions = options.printOptions;
19
- (0, _findComponentJSX.default)(j, {
18
+ (0, _movePropIntoSlots.default)(j, {
20
19
  root,
21
- componentName: 'Accordion'
22
- }, elementPath => {
23
- let index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'TransitionComponent');
24
- if (index !== -1) {
25
- const removed = elementPath.node.openingElement.attributes.splice(index, 1);
26
- let hasNode = false;
27
- elementPath.node.openingElement.attributes.forEach(attr => {
28
- var _attr$name;
29
- if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slots') {
30
- hasNode = true;
31
- (0, _assignObject.default)(j, {
32
- target: attr,
33
- key: 'transition',
34
- expression: removed[0].value.expression
35
- });
36
- }
37
- });
38
- if (!hasNode) {
39
- (0, _appendAttribute.default)(j, {
40
- target: elementPath.node,
41
- attributeName: 'slots',
42
- expression: j.objectExpression([j.objectProperty(j.identifier('transition'), removed[0].value.expression)])
43
- });
44
- }
45
- }
46
- index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'TransitionProps');
47
- if (index !== -1) {
48
- const removed = elementPath.node.openingElement.attributes.splice(index, 1);
49
- let hasNode = false;
50
- elementPath.node.openingElement.attributes.forEach(attr => {
51
- var _attr$name2;
52
- if (((_attr$name2 = attr.name) == null ? void 0 : _attr$name2.name) === 'slotProps') {
53
- hasNode = true;
54
- (0, _assignObject.default)(j, {
55
- target: attr,
56
- key: 'transition',
57
- expression: removed[0].value.expression
58
- });
59
- }
60
- });
61
- if (!hasNode) {
62
- (0, _appendAttribute.default)(j, {
63
- target: elementPath.node,
64
- attributeName: 'slotProps',
65
- expression: j.objectExpression([j.objectProperty(j.identifier('transition'), removed[0].value.expression)])
66
- });
67
- }
68
- }
20
+ componentName: 'Accordion',
21
+ propName: 'TransitionComponent',
22
+ slotName: 'transition'
69
23
  });
70
- root.find(j.ObjectProperty, {
71
- key: {
72
- name: 'TransitionComponent'
73
- }
74
- }).forEach(path => {
75
- var _path$parent;
76
- if (((_path$parent = path.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.node.key) == null ? void 0 : _path$parent.name) === 'MuiAccordion') {
77
- path.replace(j.property('init', j.identifier('slots'), j.objectExpression([j.objectProperty(j.identifier('transition'), path.node.value)])));
78
- }
79
- });
80
- root.find(j.ObjectProperty, {
81
- key: {
82
- name: 'TransitionProps'
83
- }
84
- }).forEach(path => {
85
- var _path$parent2;
86
- if (((_path$parent2 = path.parent) == null || (_path$parent2 = _path$parent2.parent) == null || (_path$parent2 = _path$parent2.parent) == null || (_path$parent2 = _path$parent2.parent) == null || (_path$parent2 = _path$parent2.node.key) == null ? void 0 : _path$parent2.name) === 'MuiAccordion') {
87
- path.replace(j.property('init', j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier('transition'), path.node.value)])));
88
- }
24
+ (0, _movePropIntoSlotProps.default)(j, {
25
+ root,
26
+ componentName: 'Accordion',
27
+ propName: 'TransitionProps',
28
+ slotName: 'transition'
89
29
  });
90
30
  return root.toSource(printOptions);
91
31
  }
@@ -37,6 +37,22 @@ var _jsxRuntime = require("react/jsx-runtime");
37
37
  slots: (0, _extends2.default)({}, outerSlots),
38
38
  slotProps: (0, _extends2.default)({}, outerSlotProps)
39
39
  });
40
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.default, {
41
+ TransitionComponent: ComponentTransition,
42
+ slots: {
43
+ transition: SlotTransition
44
+ }
45
+ });
46
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.default, {
47
+ TransitionProps: {
48
+ unmountOnExit: true
49
+ },
50
+ slotProps: {
51
+ transition: {
52
+ id: 'test'
53
+ }
54
+ }
55
+ });
40
56
  // should skip non MUI components
41
57
  /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAccordion, {
42
58
  TransitionComponent: CustomTransition,
@@ -47,6 +47,20 @@ var _jsxRuntime = require("react/jsx-runtime");
47
47
  }
48
48
  })
49
49
  });
50
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.default, {
51
+ slots: {
52
+ transition: SlotTransition
53
+ }
54
+ });
55
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.default, {
56
+ slotProps: {
57
+ transition: (0, _extends2.default)({}, {
58
+ unmountOnExit: true
59
+ }, {
60
+ id: 'test'
61
+ })
62
+ }
63
+ });
50
64
  // should skip non MUI components
51
65
  /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAccordion, {
52
66
  TransitionComponent: CustomTransition,
@@ -9,4 +9,28 @@ fn({
9
9
  }
10
10
  }
11
11
  }
12
+ });
13
+ fn({
14
+ MuiAccordion: {
15
+ defaultProps: {
16
+ TransitionComponent: ComponentTransition,
17
+ slots: {
18
+ transition: SlotTransition
19
+ }
20
+ }
21
+ }
22
+ });
23
+ fn({
24
+ MuiAccordion: {
25
+ defaultProps: {
26
+ slotProps: {
27
+ transition: {
28
+ id: 'test'
29
+ }
30
+ },
31
+ TransitionProps: {
32
+ unmountOnExit: true
33
+ }
34
+ }
35
+ }
12
36
  });
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
3
5
  fn({
4
6
  MuiAccordion: {
5
7
  defaultProps: {
@@ -13,4 +15,26 @@ fn({
13
15
  }
14
16
  }
15
17
  }
18
+ });
19
+ fn({
20
+ MuiAccordion: {
21
+ defaultProps: {
22
+ slots: {
23
+ transition: SlotTransition
24
+ }
25
+ }
26
+ }
27
+ });
28
+ fn({
29
+ MuiAccordion: {
30
+ defaultProps: {
31
+ slotProps: {
32
+ transition: (0, _extends2.default)({}, {
33
+ unmountOnExit: true
34
+ }, {
35
+ id: 'test'
36
+ })
37
+ }
38
+ }
39
+ }
16
40
  });
@@ -14,8 +14,10 @@ var _buttonGroupClasses = _interopRequireDefault(require("../button-group-classe
14
14
  var _chipClasses = _interopRequireDefault(require("../chip-classes"));
15
15
  var _paginationItemClasses = _interopRequireDefault(require("../pagination-item-classes"));
16
16
  var _alertClasses = _interopRequireDefault(require("../alert-classes"));
17
+ var _toggleButtonGroupClasses = _interopRequireDefault(require("../toggle-button-group-classes"));
17
18
  var _stepLabelProps = _interopRequireDefault(require("../step-label-props"));
18
19
  var _backdropProps = _interopRequireDefault(require("../backdrop-props"));
20
+ var _stepConnectorClasses = _interopRequireDefault(require("../step-connector-classes"));
19
21
  /**
20
22
  * @param {import('jscodeshift').FileInfo} file
21
23
  * @param {import('jscodeshift').API} api
@@ -30,7 +32,9 @@ function deprecationsAll(file, api, options) {
30
32
  file.source = (0, _chipClasses.default)(file, api, options);
31
33
  file.source = (0, _paginationItemClasses.default)(file, api, options);
32
34
  file.source = (0, _alertClasses.default)(file, api, options);
35
+ file.source = (0, _toggleButtonGroupClasses.default)(file, api, options);
33
36
  file.source = (0, _stepLabelProps.default)(file, api, options);
34
37
  file.source = (0, _backdropProps.default)(file, api, options);
38
+ file.source = (0, _stepConnectorClasses.default)(file, api, options);
35
39
  return file.source;
36
40
  }
@@ -18,6 +18,12 @@ const {
18
18
  const {
19
19
  plugin: paginationItemClassesPlugin
20
20
  } = require('../pagination-item-classes/postcss-plugin');
21
+ const {
22
+ plugin: stepConnectorClassesPlugin
23
+ } = require('../step-connector-classes/postcss-plugin');
24
+ const {
25
+ plugin: toggleButtonGroupClassesPlugin
26
+ } = require('../toggle-button-group-classes/postcss-plugin');
21
27
  module.exports = {
22
- plugins: [accordionSummaryClassesPlugin, alertClassesPlugin, buttonClassesPlugin, buttonGroupClassesPlugin, chipClassesPlugin, paginationItemClassesPlugin]
28
+ plugins: [accordionSummaryClassesPlugin, alertClassesPlugin, buttonClassesPlugin, buttonGroupClassesPlugin, chipClassesPlugin, paginationItemClassesPlugin, stepConnectorClassesPlugin, toggleButtonGroupClassesPlugin]
23
29
  };
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
- var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
9
- var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
- var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
8
+ var _movePropIntoSlotProps = _interopRequireDefault(require("../utils/movePropIntoSlotProps"));
11
9
  /**
12
10
  * @param {import('jscodeshift').FileInfo} file
13
11
  * @param {import('jscodeshift').API} api
@@ -16,43 +14,11 @@ function transformer(file, api, options) {
16
14
  const j = api.jscodeshift;
17
15
  const root = j(file.source);
18
16
  const printOptions = options.printOptions;
19
- (0, _findComponentJSX.default)(j, {
17
+ (0, _movePropIntoSlotProps.default)(j, {
20
18
  root,
21
- componentName: 'Avatar'
22
- }, elementPath => {
23
- const index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'imgProps');
24
- if (index !== -1) {
25
- const removed = elementPath.node.openingElement.attributes.splice(index, 1);
26
- let hasNode = false;
27
- elementPath.node.openingElement.attributes.forEach(attr => {
28
- var _attr$name;
29
- if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slotProps') {
30
- hasNode = true;
31
- (0, _assignObject.default)(j, {
32
- target: attr,
33
- key: 'img',
34
- expression: removed[0].value.expression
35
- });
36
- }
37
- });
38
- if (!hasNode) {
39
- (0, _appendAttribute.default)(j, {
40
- target: elementPath.node,
41
- attributeName: 'slotProps',
42
- expression: j.objectExpression([j.objectProperty(j.identifier('img'), removed[0].value.expression)])
43
- });
44
- }
45
- }
46
- });
47
- root.find(j.ObjectProperty, {
48
- key: {
49
- name: 'imgProps'
50
- }
51
- }).forEach(path => {
52
- var _path$parent;
53
- if (((_path$parent = path.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.node.key) == null ? void 0 : _path$parent.name) === 'MuiAvatar') {
54
- path.replace(j.property('init', j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier('img'), path.node.value)])));
55
- }
19
+ componentName: 'Avatar',
20
+ propName: 'imgProps',
21
+ slotName: 'img'
56
22
  });
57
23
  return root.toSource(printOptions);
58
24
  }
@@ -16,6 +16,16 @@ var _jsxRuntime = require("react/jsx-runtime");
16
16
  onLoad: () => {}
17
17
  }
18
18
  });
19
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
20
+ imgProps: {
21
+ onLoad: () => {}
22
+ },
23
+ slotProps: {
24
+ img: {
25
+ onError: () => {}
26
+ }
27
+ }
28
+ });
19
29
 
20
30
  // should skip non MUI components
21
31
  /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
4
5
  var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
5
6
  var _material = require("@mui/material");
6
7
  var _jsxRuntime = require("react/jsx-runtime");
@@ -20,6 +21,15 @@ var _jsxRuntime = require("react/jsx-runtime");
20
21
  }
21
22
  }
22
23
  });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
25
+ slotProps: {
26
+ img: (0, _extends2.default)({}, {
27
+ onLoad: () => {}
28
+ }, {
29
+ onError: () => {}
30
+ })
31
+ }
32
+ });
23
33
 
24
34
  // should skip non MUI components
25
35
  /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
@@ -9,4 +9,18 @@ fn({
9
9
  }
10
10
  }
11
11
  }
12
+ });
13
+ fn({
14
+ MuiAvatar: {
15
+ defaultProps: {
16
+ imgProps: {
17
+ onLoad: () => {}
18
+ },
19
+ slotProps: {
20
+ img: {
21
+ onError: () => {}
22
+ }
23
+ }
24
+ }
25
+ }
12
26
  });
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
3
5
  fn({
4
6
  MuiAvatar: {
5
7
  defaultProps: {
@@ -11,4 +13,17 @@ fn({
11
13
  }
12
14
  }
13
15
  }
16
+ });
17
+ fn({
18
+ MuiAvatar: {
19
+ defaultProps: {
20
+ slotProps: {
21
+ img: (0, _extends2.default)({}, {
22
+ onLoad: () => {}
23
+ }, {
24
+ onError: () => {}
25
+ })
26
+ }
27
+ }
28
+ }
14
29
  });
@@ -5,10 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = transformer;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
10
- var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
11
- var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
8
+ var _movePropIntoSlots = _interopRequireDefault(require("../utils/movePropIntoSlots"));
12
9
  /**
13
10
  * @param {import('jscodeshift').FileInfo} file
14
11
  * @param {import('jscodeshift').API} api
@@ -17,64 +14,11 @@ function transformer(file, api, options) {
17
14
  const j = api.jscodeshift;
18
15
  const root = j(file.source);
19
16
  const printOptions = options.printOptions;
20
- (0, _findComponentJSX.default)(j, {
17
+ (0, _movePropIntoSlots.default)(j, {
21
18
  root,
22
- componentName: 'Backdrop'
23
- }, elementPath => {
24
- const index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'TransitionComponent');
25
- if (index !== -1) {
26
- const removed = elementPath.node.openingElement.attributes.splice(index, 1);
27
- let hasNode = false;
28
- elementPath.node.openingElement.attributes.forEach(attr => {
29
- var _attr$name;
30
- if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slots') {
31
- hasNode = true;
32
- (0, _assignObject.default)(j, {
33
- target: attr,
34
- key: 'transition',
35
- expression: removed[0].value.expression
36
- });
37
- }
38
- });
39
- if (!hasNode) {
40
- (0, _appendAttribute.default)(j, {
41
- target: elementPath.node,
42
- attributeName: 'slots',
43
- expression: j.objectExpression([j.objectProperty(j.identifier('transition'), removed[0].value.expression)])
44
- });
45
- }
46
- }
47
- });
48
- root.find(j.ObjectProperty, {
49
- key: {
50
- name: 'TransitionComponent'
51
- }
52
- }).forEach(path => {
53
- var _path$parent;
54
- if (((_path$parent = path.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.node.key) == null ? void 0 : _path$parent.name) === 'MuiBackdrop') {
55
- var _defaultPropsProperti;
56
- const {
57
- properties: defaultPropsProperties
58
- } = path.parent.value;
59
- const existingSlots = defaultPropsProperties.find(prop => prop.key.name === 'slots');
60
- const slots = existingSlots ? existingSlots.value.properties.reduce((acc, prop) => {
61
- return (0, _extends2.default)({}, acc, {
62
- [prop.key.name]: prop.value
63
- });
64
- }, {}) : {};
65
- const transitionComponent = (_defaultPropsProperti = defaultPropsProperties.find(prop => prop.key.name === 'TransitionComponent')) != null ? _defaultPropsProperti : {};
66
- const updatedSlots = j.objectExpression(Object.entries((0, _extends2.default)({
67
- transition: transitionComponent == null ? void 0 : transitionComponent.value
68
- }, slots)).map(([slot, value]) => {
69
- return j.objectProperty(j.identifier(slot), value);
70
- }));
71
- if (existingSlots) {
72
- existingSlots.value = updatedSlots;
73
- path.prune();
74
- } else {
75
- path.replace(j.property('init', j.identifier('slots'), j.objectExpression([j.objectProperty(j.identifier('transition'), path.node.value)])));
76
- }
77
- }
19
+ componentName: 'Backdrop',
20
+ propName: 'TransitionComponent',
21
+ slotName: 'transition'
78
22
  });
79
23
  return root.toSource(printOptions);
80
24
  }
@@ -15,17 +15,18 @@ var _jsxRuntime = require("react/jsx-runtime");
15
15
  TransitionComponent: CustomTransition,
16
16
  slots: {
17
17
  root: 'div'
18
- },
19
- slotProps: {
20
- root: {
21
- className: 'foo'
22
- }
23
18
  }
24
19
  });
25
20
  /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Backdrop, {
26
21
  TransitionComponent: CustomTransition,
27
- slots: (0, _extends2.default)({}, outerSlots),
28
- slotProps: (0, _extends2.default)({}, outerSlotProps)
22
+ slots: (0, _extends2.default)({}, outerSlots)
23
+ });
24
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Backdrop.default, {
25
+ TransitionComponent: ComponentTransition,
26
+ slots: {
27
+ root: 'div',
28
+ transition: SlotTransition
29
+ }
29
30
  });
30
31
  // should skip non MUI components
31
32
  /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiBackdrop, {