forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Badge] Deprecate components and componentsProps (mui#41655
- Loading branch information
1 parent
7c3089d
commit dd86820
Showing
13 changed files
with
308 additions
and
14 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
15 changes: 15 additions & 0 deletions
15
packages/mui-codemod/src/deprecations/badge-props/badge-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,15 @@ | ||
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); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/badge-props/badge-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,53 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
import { jscodeshift } from '../../../testUtils'; | ||
import transform from './badge-props'; | ||
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 }, {}); | ||
|
||
const expected = read('./test-cases/expected.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent', () => { | ||
const actual = transform({ source: read('./test-cases/expected.js') }, { jscodeshift }, {}); | ||
|
||
const expected = read('./test-cases/expected.js'); | ||
expect(actual).to.equal(expected, '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'); | ||
}); | ||
}); | ||
}); | ||
}); |
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 './badge-props'; |
24 changes: 24 additions & 0 deletions
24
packages/mui-codemod/src/deprecations/badge-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,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 }} | ||
/>; |
32 changes: 32 additions & 0 deletions
32
packages/mui-codemod/src/deprecations/badge-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,32 @@ | ||
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 | ||
} }} />; |
42 changes: 42 additions & 0 deletions
42
packages/mui-codemod/src/deprecations/badge-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,42 @@ | ||
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 }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
components: { root: ComponentsRoot }, | ||
slots: { badge: SlotsBadge, root: SlotsRoot }, | ||
componentsProps: { root: componentsRootProps, badge: componentsBadgeProps }, | ||
slotProps: { badge: slotsBadgeProps, root: slotsRootProps }, | ||
}, | ||
}, | ||
}); | ||
|
73 changes: 73 additions & 0 deletions
73
packages/mui-codemod/src/deprecations/badge-props/test-cases/theme.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,73 @@ | ||
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 | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiBadge: { | ||
defaultProps: { | ||
slots: { | ||
root: SlotsRoot, | ||
badge: SlotsBadge | ||
}, | ||
|
||
slotProps: { | ||
root: { | ||
...componentsRootProps, | ||
...slotsRootProps | ||
}, | ||
|
||
badge: { | ||
...componentsBadgeProps, | ||
...slotsBadgeProps | ||
} | ||
} | ||
}, | ||
}, | ||
}); | ||
|
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