-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material-ui][Badge] Deprecated components and componentsProps props for v6 #41399
Changes from 19 commits
4a29139
d3cee36
d0fc9ab
a637de5
e2c5f06
763a2d9
f816919
1959307
06ece7a
c7d9c3e
d3cb8d2
d36a63a
9a7e6b8
2526e56
ddc381f
1b85030
44c33b1
5525e7f
f025c7f
2e65e81
ddcf911
c8dfeb0
deb7a6d
6888897
39fe215
bd8ced4
168604e
71992c1
1f419af
4a9e8c2
1b9818b
ad0fbd7
0583e74
c56b396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import replaceComponentsWithSlots from '../utils/replaceComponentsWithSlots'; | ||
|
||
/** | ||
* @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; | ||
|
||
replaceComponentsWithSlots(j, { root, componentName: 'Badge' }); | ||
return root.toSource(printOptions); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||
import path from 'path'; | ||||||
import { expect } from 'chai'; | ||||||
import transform from './badge-props'; | ||||||
import { jscodeshift } from '../../../testUtils'; | ||||||
import readFile from '../../util/readFile'; | ||||||
|
||||||
function read(fileName) { | ||||||
return readFile(path.join(__dirname, fileName)); | ||||||
} | ||||||
|
||||||
describe('@mui/codemod', () => { | ||||||
describe('deprecations', () => { | ||||||
describe('badge-props', () => { | ||||||
it('transforms props as needed', () => { | ||||||
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these is missing in slider any specific reason why? |
||||||
|
||||||
const expected = read('./test-cases/excepted.js'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||||||
}); | ||||||
|
||||||
it('should be idempotent', () => { | ||||||
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {}); | ||||||
|
||||||
const excepted = read('./test-cases/excepted.js'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
expect(actual).to.equal(excepted, 'The transformed version should be correct'); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('[theme] badge-props', () => { | ||||||
it('transforms props as needed', () => { | ||||||
const actual = transform( | ||||||
{ source: read('./test-cases/theme.actual.js') }, | ||||||
{ jscodeshift }, | ||||||
{ printOptions: { trailingComma: false } }, | ||||||
); | ||||||
|
||||||
const expected = read('./test-cases/theme.expected.js'); | ||||||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||||||
}); | ||||||
|
||||||
it('should be idempotent', () => { | ||||||
const actual = transform( | ||||||
{ source: read('./test-cases/theme.expected.js') }, | ||||||
{ jscodeshift }, | ||||||
{}, | ||||||
); | ||||||
|
||||||
const expected = read('./test-cases/theme.expected.js'); | ||||||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './badge-props'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Badge } from '@mui/material'; | ||
|
||
<Badge components={{ root: ComponentsRoot }} componentsProps={{ root: componentsRootProps }} />; | ||
|
||
<Badge | ||
slots={{ badge: SlotsBadge }} | ||
components={{ root: ComponentsRoot }} | ||
slotProps={{ badge: slotsBadgeProps }} | ||
componentsProps={{ root: componentsRootProps }} | ||
/>; | ||
|
||
<Badge | ||
slots={{ root: SlotsRoot, badge: SlotsBadge }} | ||
components={{ root: ComponentsRoot }} | ||
slotProps={{ root: slotsRootProps, badge: slotsBadgeProps }} | ||
componentsProps={{ root: componentsRootProps }} | ||
/>; | ||
|
||
<Badge | ||
slots={{ root: SlotsRoot, badge: SlotsBadge }} | ||
components={{ root: ComponentsRoot }} | ||
slotProps={{ root: slotsRootProps, badge: slotsBadgeProps }} | ||
componentsProps={{ root: componentsRootProps, badge: componentsBadgeProps }} | ||
/>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Badge } from '@mui/material'; | ||
|
||
<Badge | ||
slots={{ | ||
root: ComponentsRoot, | ||
}} | ||
slotProps={{ root: componentsRootProps }} | ||
/>; | ||
|
||
<Badge | ||
slots={{ | ||
badge: SlotsBadge, | ||
root: ComponentsRoot, | ||
}} | ||
slotProps={{ | ||
badge: slotsBadgeProps, | ||
root: componentsRootProps, | ||
}} | ||
/>; | ||
|
||
<Badge | ||
slots={{ root: SlotsRoot, badge: SlotsBadge }} | ||
slotProps={{ | ||
badge: slotsBadgeProps, | ||
root: { | ||
...componentsRootProps, | ||
...slotsRootProps, | ||
}, | ||
}} | ||
/>; | ||
|
||
<Badge | ||
slots={{ root: SlotsRoot, badge: SlotsBadge }} | ||
slotProps={{ | ||
root: { | ||
...componentsRootProps, | ||
...slotsRootProps, | ||
}, | ||
badge: { | ||
...componentsBadgeProps, | ||
...slotsBadgeProps, | ||
}, | ||
}} | ||
/>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
components: { root: ComponentsRoot }, | ||
componentsProps: { root: componentsRootProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
components: { root: ComponentsRoot }, | ||
slots: { badge: SlotsBadge }, | ||
componentsProps: { root: componentsRootProps }, | ||
slotProps: { badge: slotsBadgeProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
components: { root: ComponentsRoot }, | ||
slots: { badge: SlotsBadge, root: SlotsRoot }, | ||
componentsProps: { root: componentsRootProps }, | ||
slotProps: { root: slotsRootProps, badge: slotsBadgeProps }, | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
slots: { | ||
root: ComponentsRoot, | ||
}, | ||
|
||
slotProps: { | ||
root: componentsRootProps, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
slots: { | ||
root: ComponentsRoot, | ||
badge: SlotsBadge, | ||
}, | ||
|
||
slotProps: { | ||
root: componentsRootProps, | ||
badge: slotsBadgeProps, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
slots: { | ||
root: SlotsRoot, | ||
badge: SlotsBadge, | ||
}, | ||
|
||
slotProps: { | ||
root: { | ||
...componentsRootProps, | ||
...slotsRootProps, | ||
}, | ||
|
||
badge: slotsBadgeProps, | ||
}, | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
'use client'; | ||
export { default } from './Badge'; | ||
|
||
export { default as badgeClasses } from './badgeClasses'; | ||
export * from './badgeClasses'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add the theme tests, like this one: https://github.com/mui/material-ui/blob/master/packages/mui-codemod/src/deprecations/slider-props/slider-props.test.js#L29