Skip to content

Commit

Permalink
add deprecation codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
lhilgert9 committed Feb 21, 2024
1 parent e661f7f commit f59094e
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,33 @@ Here's how to migrate:
},
},
```

## Slider

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#slider-props) below to migrate the code as described in the following sections:

```bash
npx @mui/codemod@latest deprecations/slider-props <path>
```

### components

The Slider's `components` was deprecated in favor of `slots`:

```diff
<Slider
- components={{ Track: CustomTrack }}
+ slots={{ track: CustomTrack }}
/>
```

### componentsProps

The Slider's `componentsProps` was deprecated in favor of `slotProps`:

```diff
<Slider
- componentsProps={{ track: { testid: 'test-id' } }}
+ slotProps={{ track: { testid: 'test-id' } }}
/>
```
26 changes: 26 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,32 @@ CSS transforms:
npx @mui/codemod@latest deprecations/pagination-item-classes <path>
```

#### `slider-props`

```diff
<Slider
- components={{ Track: CustomTrack }}
+ slots={{ track: CustomTrack }}
- componentsProps={{ track: { testid: 'test-id' } }}
+ slotProps={{ track: { testid: 'test-id' } }}
/>
```

```diff
MuiSlider: {
defaultProps: {
- components: { Track: CustomTrack }
+ slots: { track: CustomTrack },
- componentsProps: { track: { testid: 'test-id' }}
+ slotProps: { track: { testid: 'test-id' } },
},
},
```

```bash
npx @mui/codemod@latest deprecations/slider-props <path>
```

### v5.0.0

#### `base-use-named-exports`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './slider-props';
15 changes: 15 additions & 0 deletions packages/mui-codemod/src/deprecations/slider-props/slider-props.js
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: 'Slider' });

return root.toSource(printOptions);
}
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 './slider-props';
import readFile from '../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('slider-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] slider-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');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Slider from '@mui/material/Slider';

<Slider
components={{ Track: ComponentsTrack }}
componentsProps={{ track: componentsTrackProps }}
/>;
<Slider
slots={{ rail: SlotsRail }}
components={{ Track: ComponentsTrack }}
slotProps={{ rail: slotsRailProps }}
componentsProps={{ track: componentsTrackProps }}
/>;
<Slider
slots={{ rail: SlotsRail, track: SlotsTrack }}
components={{ Track: ComponentsTrack }}
slotProps={{ rail: slotsRailProps, track: slotsTrackProps }}
componentsProps={{ track: componentsTrackProps }}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Slider from '@mui/material/Slider';

<Slider
slots={{
track: ComponentsTrack
}}
slotProps={{ track: componentsTrackProps }}
/>;
<Slider
slots={{
rail: SlotsRail,
track: ComponentsTrack
}}
slotProps={{
rail: slotsRailProps,
track: componentsTrackProps
}} />;
<Slider
slots={{ rail: SlotsRail, track: SlotsTrack }}
slotProps={{ rail: slotsRailProps, track: slotsTrackProps }} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
fn({
MuiSlider: {
defaultProps: {
components: { Track: ComponentsTrack },
componentsProps: { track: componentsTrackProps },
},
},
});

fn({
MuiSlider: {
defaultProps: {
components: { Track: ComponentsTrack },
slots: { rail: SlotsRail },
componentsProps: { track: componentsTrackProps },
slotProps: { rail: slotsRailProps },
},
},
});

fn({
MuiSlider: {
defaultProps: {
components: { Track: ComponentsTrack },
slots: { rail: SlotsRail, track: SlotsTrack },
componentsProps: { track: componentsTrackProps },
slotProps: { rail: slotsRailProps, track: slotsTrackProps },
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
fn({
MuiSlider: {
defaultProps: {
slots: {
track: ComponentsTrack
},

slotProps: {
track: componentsTrackProps
}
},
},
});

fn({
MuiSlider: {
defaultProps: {
slots: {
track: ComponentsTrack,
rail: SlotsRail
},

slotProps: {
track: componentsTrackProps,
rail: slotsRailProps
}
},
},
});

fn({
MuiSlider: {
defaultProps: {
slots: {
track: SlotsTrack,
rail: SlotsRail
},

slotProps: {
track: slotsTrackProps,
rail: slotsRailProps
}
},
},
});
4 changes: 2 additions & 2 deletions packages/mui-material/src/Slider/Slider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface SliderOwnProps {
/**
* The components used for each slot inside.
*
@deprecated use the `slots` prop instead. This prop will be removed in v7.
* @deprecated use the `slots` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand All @@ -64,7 +64,7 @@ export interface SliderOwnProps {
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
@deprecated use the `slotProps` prop instead. This prop will be removed in v7.
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand Down

0 comments on commit f59094e

Please sign in to comment.