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][SpeedDial] Deprecate TransitionComponent (mui#40698)
- Loading branch information
1 parent
75e8f4a
commit 24a604e
Showing
15 changed files
with
355 additions
and
12 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
1 change: 1 addition & 0 deletions
1
packages/mui-codemod/src/deprecations/speed-dial-props/index.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 @@ | ||
export { default } from './speed-dial-props'; |
28 changes: 28 additions & 0 deletions
28
packages/mui-codemod/src/deprecations/speed-dial-props/speed-dial-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,28 @@ | ||
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: 'SpeedDial', | ||
propName: 'TransitionComponent', | ||
slotName: 'transition', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'SpeedDial', | ||
propName: 'TransitionProps', | ||
slotName: 'transition', | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/speed-dial-props/speed-dial-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 './speed-dial-props'; | ||
import readFile from '../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describe('speed-dial-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] speed-dial-props', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform( | ||
{ source: read('./test-cases/theme.actual.js') }, | ||
{ jscodeshift }, | ||
{}, | ||
); | ||
|
||
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'); | ||
}); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/mui-codemod/src/deprecations/speed-dial-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,29 @@ | ||
import SpeedDial from '@mui/material/SpeedDial'; | ||
import { SpeedDial as MySpeedDial } from '@mui/material'; | ||
|
||
<SpeedDial TransitionComponent={CustomTransition} TransitionProps={CustomTransitionProps} />; | ||
<MySpeedDial TransitionComponent={CustomTransition} TransitionProps={CustomTransitionProps} />; | ||
<SpeedDial | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
root: 'div', | ||
}} | ||
/>; | ||
<MySpeedDial | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
...outerSlots, | ||
}} | ||
/>; | ||
<SpeedDial | ||
TransitionComponent={ComponentTransition} | ||
TransitionProps={CustomTransitionProps} | ||
slots={{ | ||
root: 'div', | ||
transition: SlotTransition, | ||
}} | ||
/>; | ||
// should skip non MUI components | ||
<NonMuiSpeedDial TransitionComponent={CustomTransition} TransitionProps={CustomTransitionProps} />; |
39 changes: 39 additions & 0 deletions
39
packages/mui-codemod/src/deprecations/speed-dial-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,39 @@ | ||
import SpeedDial from '@mui/material/SpeedDial'; | ||
import { SpeedDial as MySpeedDial } from '@mui/material'; | ||
|
||
<SpeedDial slots={{ | ||
transition: CustomTransition | ||
}} slotProps={{ | ||
transition: CustomTransitionProps | ||
}} />; | ||
<MySpeedDial slots={{ | ||
transition: CustomTransition | ||
}} slotProps={{ | ||
transition: CustomTransitionProps | ||
}} />; | ||
<SpeedDial | ||
slots={{ | ||
root: 'div', | ||
transition: CustomTransition | ||
}} | ||
slotProps={{ | ||
transition: CustomTransitionProps | ||
}} />; | ||
<MySpeedDial | ||
slots={{ | ||
...outerSlots, | ||
transition: CustomTransition | ||
}} | ||
slotProps={{ | ||
transition: CustomTransitionProps | ||
}} />; | ||
<SpeedDial | ||
slots={{ | ||
root: 'div', | ||
transition: SlotTransition, | ||
}} | ||
slotProps={{ | ||
transition: CustomTransitionProps | ||
}} />; | ||
// should skip non MUI components | ||
<NonMuiSpeedDial TransitionComponent={CustomTransition} TransitionProps={CustomTransitionProps} />; |
33 changes: 33 additions & 0 deletions
33
packages/mui-codemod/src/deprecations/speed-dial-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,33 @@ | ||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
TransitionComponent: CustomTransition, | ||
TransitionProps: CustomTransitionProps, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
TransitionComponent: CustomTransition, | ||
TransitionProps: CustomTransitionProps, | ||
slots: { | ||
root: 'div', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
TransitionComponent: ComponentTransition, | ||
TransitionProps: CustomTransitionProps, | ||
slots: { | ||
root: 'div', | ||
transition: SlotTransition, | ||
}, | ||
}, | ||
}, | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/mui-codemod/src/deprecations/speed-dial-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,43 @@ | ||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
slots: { | ||
transition: CustomTransition | ||
}, | ||
|
||
slotProps: { | ||
transition: CustomTransitionProps | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
slots: { | ||
root: 'div', | ||
transition: CustomTransition | ||
}, | ||
|
||
slotProps: { | ||
transition: CustomTransitionProps | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSpeedDial: { | ||
defaultProps: { | ||
slots: { | ||
root: 'div', | ||
transition: SlotTransition, | ||
}, | ||
|
||
slotProps: { | ||
transition: CustomTransitionProps | ||
} | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.