-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Alert] Deprecate components and componentsProps props (#…
- Loading branch information
1 parent
e0e722d
commit 1077906
Showing
17 changed files
with
532 additions
and
71 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/alert-props/alert-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: 'Alert' }); | ||
|
||
return root.toSource(printOptions); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/alert-props/alert-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 './alert-props'; | ||
import readFile from '../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describe('alert-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] alert-props', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform( | ||
{ source: read('./test-cases/theme.actual.js') }, | ||
{ jscodeshift }, | ||
{ printOptions: { trailingComma: true } }, | ||
); | ||
|
||
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 './alert-props'; |
18 changes: 18 additions & 0 deletions
18
packages/mui-codemod/src/deprecations/alert-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,18 @@ | ||
import Alert from '@mui/material/Alert'; | ||
|
||
<Alert | ||
components={{ CloseButton: ComponentsButton }} | ||
componentsProps={{ closeButton: componentsButtonProps }} | ||
/>; | ||
<Alert | ||
slots={{ closeIcon: SlotsIcon }} | ||
components={{ CloseButton: ComponentsButton }} | ||
slotProps={{ closeIcon: slotsIconProps }} | ||
componentsProps={{ closeButton: componentsButtonProps }} | ||
/>; | ||
<Alert | ||
slots={{ closeIcon: SlotsIcon, closeButton: SlotsButton }} | ||
components={{ CloseButton: ComponentsButton }} | ||
slotProps={{ closeIcon: slotsIconProps, closeButton: slotsButtonProps }} | ||
componentsProps={{ closeButton: componentsButtonProps }} | ||
/>; |
20 changes: 20 additions & 0 deletions
20
packages/mui-codemod/src/deprecations/alert-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,20 @@ | ||
import Alert from '@mui/material/Alert'; | ||
|
||
<Alert | ||
slots={{ | ||
closeButton: ComponentsButton | ||
}} | ||
slotProps={{ closeButton: componentsButtonProps }} | ||
/>; | ||
<Alert | ||
slots={{ | ||
closeIcon: SlotsIcon, | ||
closeButton: ComponentsButton | ||
}} | ||
slotProps={{ | ||
closeIcon: slotsIconProps, | ||
closeButton: componentsButtonProps | ||
}} />; | ||
<Alert | ||
slots={{ closeIcon: SlotsIcon, closeButton: SlotsButton }} | ||
slotProps={{ closeIcon: slotsIconProps, closeButton: slotsButtonProps }} />; |
30 changes: 30 additions & 0 deletions
30
packages/mui-codemod/src/deprecations/alert-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,30 @@ | ||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
components: { CloseButton: ComponentsButton }, | ||
componentsProps: { closeButton: componentsButtonProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
components: { CloseButton: ComponentsButton }, | ||
slots: { closeIcon: SlotsIcon }, | ||
componentsProps: { closeButton: componentsButtonProps }, | ||
slotProps: { closeIcon: slotsIconProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
components: { CloseButton: ComponentsButton }, | ||
slots: { closeIcon: SlotsIcon, closeButton: SlotsButton }, | ||
componentsProps: { closeButton: componentsButtonProps }, | ||
slotProps: { closeIcon: slotsIconProps, closeButton: slotsButtonProps }, | ||
}, | ||
}, | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/mui-codemod/src/deprecations/alert-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,45 @@ | ||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
slots: { | ||
closeButton: ComponentsButton, | ||
}, | ||
|
||
slotProps: { | ||
closeButton: componentsButtonProps, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
slots: { | ||
closeButton: ComponentsButton, | ||
closeIcon: SlotsIcon, | ||
}, | ||
|
||
slotProps: { | ||
closeButton: componentsButtonProps, | ||
closeIcon: slotsIconProps, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiAlert: { | ||
defaultProps: { | ||
slots: { | ||
closeButton: SlotsButton, | ||
closeIcon: SlotsIcon, | ||
}, | ||
|
||
slotProps: { | ||
closeButton: slotsButtonProps, | ||
closeIcon: slotsIconProps, | ||
}, | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.