-
-
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][StepContent] Add slots and slotProps (#44742)
Signed-off-by: sai chand <[email protected]> Co-authored-by: Diego Andai <[email protected]>
- Loading branch information
1 parent
e165016
commit 7f04342
Showing
15 changed files
with
369 additions
and
25 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
1 change: 1 addition & 0 deletions
1
packages/mui-codemod/src/deprecations/step-content-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 './step-content-props'; |
28 changes: 28 additions & 0 deletions
28
packages/mui-codemod/src/deprecations/step-content-props/step-content-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: 'StepContent', | ||
propName: 'TransitionComponent', | ||
slotName: 'transition', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'StepContent', | ||
propName: 'TransitionProps', | ||
slotName: 'transition', | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/step-content-props/step-content-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 './step-content-props'; | ||
import readFile from '../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describe('step-content-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] step-content-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'); | ||
}); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/mui-codemod/src/deprecations/step-content-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,32 @@ | ||
import StepContent from '@mui/material/StepContent'; | ||
import { StepContent as MyStepContent } from '@mui/material'; | ||
|
||
<StepContent TransitionComponent={CustomTransition} TransitionProps={{ unmountOnExit: true }} />; | ||
<MyStepContent TransitionComponent={CustomTransition} TransitionProps={transitionVars} />; | ||
<StepContent | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={{ unmountOnExit: true }} | ||
slots={{ | ||
root: 'div', | ||
}} | ||
slotProps={{ | ||
root: { className: 'foo' }, | ||
}} | ||
/>; | ||
<MyStepContent | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={{ unmountOnExit: true }} | ||
slots={{ | ||
...outerSlots, | ||
}} | ||
slotProps={{ | ||
...outerSlotProps, | ||
}} | ||
/>; | ||
<StepContent TransitionComponent={ComponentTransition} slots={{ transition: SlotTransition }} />; | ||
<StepContent TransitionProps={{ unmountOnExit: true }} slotProps={{ transition: { id: 'test' } }} />; | ||
// should skip non MUI components | ||
<NonMuiStepContent | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={{ unmountOnExit: true }} | ||
/>; |
42 changes: 42 additions & 0 deletions
42
packages/mui-codemod/src/deprecations/step-content-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,42 @@ | ||
import StepContent from '@mui/material/StepContent'; | ||
import { StepContent as MyStepContent } from '@mui/material'; | ||
|
||
<StepContent slots={{ | ||
transition: CustomTransition | ||
}} slotProps={{ | ||
transition: { unmountOnExit: true } | ||
}} />; | ||
<MyStepContent slots={{ | ||
transition: CustomTransition | ||
}} slotProps={{ | ||
transition: transitionVars | ||
}} />; | ||
<StepContent | ||
slots={{ | ||
root: 'div', | ||
transition: CustomTransition | ||
}} | ||
slotProps={{ | ||
root: { className: 'foo' }, | ||
transition: { unmountOnExit: true } | ||
}} />; | ||
<MyStepContent | ||
slots={{ | ||
...outerSlots, | ||
transition: CustomTransition | ||
}} | ||
slotProps={{ | ||
...outerSlotProps, | ||
transition: { unmountOnExit: true } | ||
}} />; | ||
<StepContent slots={{ transition: SlotTransition }} />; | ||
<StepContent | ||
slotProps={{ transition: { | ||
...{ unmountOnExit: true }, | ||
...{ id: 'test' } | ||
} }} />; | ||
// should skip non MUI components | ||
<NonMuiStepContent | ||
TransitionComponent={CustomTransition} | ||
TransitionProps={{ unmountOnExit: true }} | ||
/>; |
26 changes: 26 additions & 0 deletions
26
packages/mui-codemod/src/deprecations/step-content-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,26 @@ | ||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
TransitionComponent: CustomTransition, | ||
TransitionProps: { unmountOnExit: true }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
TransitionComponent: ComponentTransition, | ||
slots: { transition: SlotTransition }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
slotProps: { transition: { id: 'test' } }, | ||
TransitionProps: { unmountOnExit: true }, | ||
}, | ||
}, | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/mui-codemod/src/deprecations/step-content-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,32 @@ | ||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
slots: { | ||
transition: CustomTransition | ||
}, | ||
|
||
slotProps: { | ||
transition: { unmountOnExit: true } | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
slots: { transition: SlotTransition } | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiStepContent: { | ||
defaultProps: { | ||
slotProps: { transition: { | ||
...{ unmountOnExit: true }, | ||
...{ id: 'test' } | ||
} } | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.