Skip to content

Commit

Permalink
[material-ui][Popper] Deprecate components and componentProps props f…
Browse files Browse the repository at this point in the history
…or v6 (#42111)
  • Loading branch information
ChronicusUA authored May 24, 2024
1 parent 78d723b commit 7e361e5
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,36 @@ The PaginationItems's `components` prop was deprecated in favor of `slots`:
/>
```

## Popper

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

```bash
npx @mui/codemod@next deprecations/popper-props <path>
```

### components

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

```diff
<Popper
- components={{ Root: CustomRoot }}
+ slots={{ root: CustomRoot }}
/>
```

### componentsProps

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

```diff
<Popper
- componentsProps={{ root: { testid: 'test-id' } }}
+ slotProps={{ root: { testid: 'test-id' } }}
/>
```

## 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:
Expand Down
8 changes: 6 additions & 2 deletions docs/pages/material-ui/api/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
"component": { "type": { "name": "elementType" } },
"components": {
"type": { "name": "shape", "description": "{ Root?: elementType }" },
"default": "{}"
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slots</code> prop instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"componentsProps": {
"type": { "name": "shape", "description": "{ root?: func<br>&#124;&nbsp;object }" },
"default": "{}"
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slotProps</code> prop instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"container": { "type": { "name": "union", "description": "HTML element<br>&#124;&nbsp;func" } },
"disablePortal": { "type": { "name": "bool" }, "default": "false" },
Expand Down
26 changes: 26 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,32 @@ npx @mui/codemod@next deprecations/pagination-item-classes <path>
npx @mui/codemod@next deprecations/pagination-item-props <path>
```

#### `popper-props`

```diff
<Popper
- components={{ Root: CustomRoot }}
+ slots={{ root: CustomRoot }}
- componentsProps={{ root: { testid: 'test-id' } }}
+ slotProps={{ root: { testid: 'test-id' } }}
/>
```

```diff
MuiPopper: {
defaultProps: {
- components: { Root: CustomRoot }
+ slots: { root: CustomRoot },
- componentsProps: { root: { testid: 'test-id' }}
+ slotProps: { root: { testid: 'test-id' } },
},
},
```

```bash
npx @mui/codemod@next deprecations/popper-props <path>
```

#### `slider-props`

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

return root.toSource(printOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describeJscodeshiftTransform } from '../../../testUtils';
import transform from './popper-props';

describe('@mui/codemod', () => {
describe('deprecations', () => {
describeJscodeshiftTransform({
transform,
transformName: 'popper-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' },
],
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Popper from '@mui/material/Popper';

<Popper
components={{ Root: ComponentsRoot }}
componentsProps={{ root: componentsRootProps }}
/>;
<Popper
slots={{ root: SlotsRoot }}
components={{ Root: ComponentsRoot }}
slotProps={{ root: slotsRootProps }}
componentsProps={{ root: componentsRootProps }}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Popper from '@mui/material/Popper';

<Popper
slots={{
root: ComponentsRoot
}}
slotProps={{ root: componentsRootProps }}
/>;
<Popper
slots={{ root: SlotsRoot }}
slotProps={{ root: {
...componentsRootProps,
...slotsRootProps
} }} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn({
MuiPopper: {
defaultProps: {
components: { Root: ComponentsRoot },
componentsProps: { root: componentsRootProps },
},
},
});

fn({
MuiPopper: {
defaultProps: {
components: { Root: ComponentsRoot },
slots: { root: SlotsRoot },
componentsProps: { root: componentsRootProps },
slotProps: { root: slotsRootProps },
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
fn({
MuiPopper: {
defaultProps: {
slots: {
root: ComponentsRoot
},

slotProps: {
root: componentsRootProps
}
},
},
});

fn({
MuiPopper: {
defaultProps: {
slots: {
root: SlotsRoot
},

slotProps: {
root: {
...componentsRootProps,
...slotsRootProps
}
}
},
},
});
8 changes: 8 additions & 0 deletions packages/mui-material/src/Popper/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ export interface PopperProps extends Omit<BasePopperProps, 'direction'> {
/**
* The components used for each slot inside the Popper.
* Either a string to use a HTML element or a component.
*
* @deprecated use the `slots` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
* @default {}
*/
components?: {
Root?: React.ElementType;
};
/**
* The props used for each slot inside the Popper.
*
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
* @default {}
*/
componentsProps?: BasePopperProps['slotProps'];
Expand Down Expand Up @@ -137,13 +141,17 @@ Popper.propTypes /* remove-proptypes */ = {
/**
* The components used for each slot inside the Popper.
* Either a string to use a HTML element or a component.
*
* @deprecated use the `slots` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
* @default {}
*/
components: PropTypes.shape({
Root: PropTypes.elementType,
}),
/**
* The props used for each slot inside the Popper.
*
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
* @default {}
*/
componentsProps: PropTypes.shape({
Expand Down

0 comments on commit 7e361e5

Please sign in to comment.