-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Snackbar] Add Slots and SlotProps (#45103)
- Loading branch information
1 parent
c490d7b
commit 4b74f87
Showing
22 changed files
with
650 additions
and
52 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
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 './snackbar-props'; |
42 changes: 42 additions & 0 deletions
42
packages/mui-codemod/src/deprecations/snackbar-props/snackbar-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,42 @@ | ||
import movePropIntoSlots from '../utils/movePropIntoSlots'; | ||
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; | ||
|
||
movePropIntoSlots(j, { | ||
root, | ||
componentName: 'Snackbar', | ||
propName: 'TransitionComponent', | ||
slotName: 'transition', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'Snackbar', | ||
propName: 'TransitionProps', | ||
slotName: 'transition', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'Snackbar', | ||
propName: 'ContentProps', | ||
slotName: 'content', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'Snackbar', | ||
propName: 'ClickAwayListenerProps', | ||
slotName: 'clickAwayListener', | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/mui-codemod/src/deprecations/snackbar-props/snackbar-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 './snackbar-props'; | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describeJscodeshiftTransform({ | ||
transform, | ||
transformName: 'snackbar-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' }, | ||
], | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/mui-codemod/src/deprecations/snackbar-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,51 @@ | ||
import Snackbar from '@mui/material/Snackbar'; | ||
import { Snackbar as MySnackbar } from '@mui/material'; | ||
|
||
<Snackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
/>; | ||
<MySnackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
/>; | ||
<Snackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
root: 'div', | ||
}} | ||
/>; | ||
<MySnackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
...outerSlots, | ||
}} | ||
/>; | ||
<Snackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={ComponentTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
root: 'div', | ||
transition: SlotTransition, | ||
}} | ||
/>; | ||
|
||
// should skip non MUI components | ||
<NonMuiSnackbar | ||
ClickAwayListenerProps={CustomListenerProps} | ||
ContentProps={CustomContentProps} | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
/>; |
Oops, something went wrong.