forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Rating] Deprecate *Props and complete
slots
, `slotPro…
…ps` (mui#45295)
- Loading branch information
1 parent
3bfa70e
commit 5d7e0d5
Showing
15 changed files
with
510 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './rating-props'; |
21 changes: 21 additions & 0 deletions
21
packages/mui-codemod/src/deprecations/rating-props/rating-props.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import movePropIntoSlotProps from '../utils/movePropIntoSlotProps'; | ||
|
||
/** | ||
* @param {import('jscodeshift').FileInfo} file | ||
* @param {import('jscodeshift').API} api | ||
*/ | ||
export default function transformer(file, api, options) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
const printOptions = options.printOptions; | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'Rating', | ||
propName: 'IconContainerComponent', | ||
slotName: 'icon', | ||
slotPropName: 'component', | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/mui-codemod/src/deprecations/rating-props/rating-props.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describeJscodeshiftTransform } from '../../../testUtils'; | ||
import transform from './rating-props'; | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describeJscodeshiftTransform({ | ||
transform, | ||
transformName: 'rating-props', | ||
dirname: __dirname, | ||
testCases: [ | ||
{ actual: '/test-cases/actual.js', expected: '/test-cases/expected.js' }, | ||
{ actual: '/test-cases/theme.actual.js', expected: '/test-cases/theme.expected.js' }, | ||
], | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/mui-codemod/src/deprecations/rating-props/test-cases/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Rating from '@mui/material/Rating'; | ||
import { Rating as MyRating } from '@mui/material'; | ||
|
||
<Rating IconContainerComponent={CustomIconContainer} />; | ||
<MyRating IconContainerComponent={CustomIconContainer} />; | ||
<Rating | ||
IconContainerComponent={CustomIconContainer} | ||
slots={{ | ||
root: 'div', | ||
}} | ||
/>; | ||
<MyRating | ||
IconContainerComponent={CustomIconContainer} | ||
slots={{ | ||
...outerSlots, | ||
}} | ||
/>; | ||
<Rating | ||
IconContainerComponent={CustomIconContainer} | ||
slotProps={{ | ||
icon: { | ||
id: 'my-rating-icon', | ||
}, | ||
}} | ||
/>; | ||
|
||
// should skip non MUI components | ||
<NonMuiRating IconContainerComponent={CustomIconContainer} />; |
43 changes: 43 additions & 0 deletions
43
packages/mui-codemod/src/deprecations/rating-props/test-cases/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Rating from '@mui/material/Rating'; | ||
import { Rating as MyRating } from '@mui/material'; | ||
|
||
<Rating slotProps={{ | ||
icon: { | ||
component: CustomIconContainer | ||
} | ||
}} />; | ||
<MyRating slotProps={{ | ||
icon: { | ||
component: CustomIconContainer | ||
} | ||
}} />; | ||
<Rating | ||
slots={{ | ||
root: 'div', | ||
}} | ||
slotProps={{ | ||
icon: { | ||
component: CustomIconContainer | ||
} | ||
}} | ||
/>; | ||
<MyRating | ||
slots={{ | ||
...outerSlots, | ||
}} | ||
slotProps={{ | ||
icon: { | ||
component: CustomIconContainer | ||
} | ||
}} | ||
/>; | ||
<Rating | ||
slotProps={{ | ||
icon: { | ||
id: 'my-rating-icon', | ||
component: CustomIconContainer | ||
}, | ||
}} />; | ||
|
||
// should skip non MUI components | ||
<NonMuiRating IconContainerComponent={CustomIconContainer} />; |
31 changes: 31 additions & 0 deletions
31
packages/mui-codemod/src/deprecations/rating-props/test-cases/theme.actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
fn({ | ||
MuiRating: { | ||
defaultProps: { | ||
IconContainerComponent: CustomContainer, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiRating: { | ||
defaultProps: { | ||
IconContainerComponent: CustomContainer, | ||
slotProps: { | ||
root: {}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiRating: { | ||
defaultProps: { | ||
IconContainerComponent: CustomContainer, | ||
slotProps: { | ||
icon: { | ||
id: 'my-rating-icon', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.