Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Bring back *Component and *Props codemods and deprecation messages #44383

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ You can also manually update your theme as shown in the snippet below:

This reduces the API surface and lets you define variants in other slots of the component.

## Accordion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page could become confusing. If we plan to continue to add these sections here, we should include the version in which the new API was introduced. Otherwise people may run the codemod while installing an older version (e.g. 6.0.0).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into how to do this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnajdova what do you think about this approach:

  • For APIs introduced in 6.0.0, we don't add any callout
  • For APIs introduced after 6.0.0, we add a warning callout specifying the version in which the API was added

If you agree, this PR doesn't need any change, as these APIs were introduced in 6.0.0. The deprecation messages were omitted while we discussed the direction of the slot pattern, which is why we are bringing them back now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, ok I see, I thought the APIs were introduced later.


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

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

### TransitionComponent

The Accordion's `TransitionComponent` prop was deprecated in favor of `slots.transition`:

```diff
<Accordion
- TransitionComponent={CustomTransition}
+ slots={{ transition: CustomTransition }}
/>
```

### TransitionProps

The Accordion's `TransitionProps` prop was deprecated in favor of `slotProps.transition`:

```diff
<Accordion
- TransitionProps={{ unmountOnExit: true }}
+ slotProps={{ transition: { unmountOnExit: true } }}
/>
```

## AccordionSummary

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#accordion-summary-classes) below to migrate the code as described in the following sections:
Expand Down Expand Up @@ -251,6 +281,47 @@ Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-code
npx @mui/codemod@latest deprecations/autocomplete-props <path>
```

### \*Component props

All of the Autocomplete's slot (`*Component`) props were deprecated in favor of equivalent `slots` and `slotProps` entries:

```diff
<Autocomplete
- PaperComponent={CustomPaperComponent}
- PopperComponent={CustomPopperComponent}
- ListboxComponent={CustomListboxComponent}
+ slots={{
+ paper: CustomPaperComponent,
+ popper: CustomPopperComponent,
+ }}
+ slotProps={{
+ listbox: {
+ component: CustomListboxComponent,
+ },
+ }}
Comment on lines +290 to +301
Copy link
Member

@oliviertassinari oliviertassinari Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct spacing coding style

Suggested change
- PaperComponent={CustomPaperComponent}
- PopperComponent={CustomPopperComponent}
- ListboxComponent={CustomListboxComponent}
+ slots={{
+ paper: CustomPaperComponent,
+ popper: CustomPopperComponent,
+ }}
+ slotProps={{
+ listbox: {
+ component: CustomListboxComponent,
+ },
+ }}
- PaperComponent={CustomPaperComponent}
- PopperComponent={CustomPopperComponent}
- ListboxComponent={CustomListboxComponent}
+ slots={{
+ paper: CustomPaperComponent,
+ popper: CustomPopperComponent,
+ }}
+ slotProps={{
+ listbox: {
+ component: CustomListboxComponent,
+ },
+ }}

/>
```

:::warning
The listbox slot is a special case because `ListboxComponent` was implemented differently from the other `*Component` props, behaving similar to the `component` and `as` props.
The `slots.listbox` entry exists and you can use it to replace the component entirely, but if you want to keep `ListboxComponent`'s behavior which maintains the original listbox styles, you should use the `slotProps.listbox.component` entry.
:::

### \*Props props

All of the Autocomplete's slot props (`*Props`) props were deprecated in favor of equivalent `slotProps` entries:

```diff
<Autocomplete
- ChipProps={CustomChipProps}
- ListboxProps={CustomListboxProps}
+ slotProps={{
+ chip: CustomChipProps,
+ listbox: CustomListboxProps,
+ }}
Comment on lines +316 to +321
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ChipProps={CustomChipProps}
- ListboxProps={CustomListboxProps}
+ slotProps={{
+ chip: CustomChipProps,
+ listbox: CustomListboxProps,
+ }}
- ChipProps={CustomChipProps}
- ListboxProps={CustomListboxProps}
+ slotProps={{
+ chip: CustomChipProps,
+ listbox: CustomListboxProps,
+ }}

/>
```

### componentsProps

The Autocomplete's `componentsProps` prop was deprecated in favor of `slotProps`:
Expand All @@ -271,6 +342,32 @@ The Autocomplete's `componentsProps` prop was deprecated in favor of `slotProps`
/>
```

## Avatar

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

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

### imgProps

The Avatar's `imgProps` prop was deprecated in favor of `slotProps.img`:

```diff
<Avatar
- imgProps={{
- onError: () => {},
- onLoad: () => {},
+ slotProps={{
+ img: {
+ onError: () => {},
+ onLoad: () => {},
+ }
}}
/>;
```

## AvatarGroup

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#avatar-group-props) below to migrate the code as described in the following sections:
Expand Down Expand Up @@ -359,6 +456,16 @@ The Backdrop's `componentsProps` prop was deprecated in favor of `slotProps`:
/>
```

### TransitionComponent

The Backdrop's `TransitionComponent` prop was deprecated in favor of `slots.transition`:

```diff
<Slider
- TransitionComponent={CustomTransition}
+ slots={{ transition: CustomTransition }}
```

## Badge

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#badge-props) below to migrate the code as described in the following sections:
Expand Down Expand Up @@ -1625,6 +1732,28 @@ The StepLabel's `componentsProps` prop was deprecated in favor of `slotProps`:
/>
```

### StepIconComponent

The StepLabel's `StepIconComponent` prop was deprecated in favor of `slots.stepIcon`:

```diff
<StepLabel
- StepIconComponent={StepIconComponent}
+ slots={{ stepIcon: StepIconComponent }}
/>
```

### StepIconProps

The StepLabel's `StepIconProps` prop was deprecated in favor of `slotProps.stepIcon`:

```diff
<StepLabel
- StepIconProps={StepIconProps}
+ slotProps={{ stepIcon: StepIconProps }}
/>
```

## StepConnector

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#step-connector-classes) below to migrate the code as described in the following sections:
Expand Down Expand Up @@ -1664,3 +1793,32 @@ Here's how to migrate:
},
},
```

## SpeedDial

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

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

### TransitionComponent

The SpeedDial's `TransitionComponent` prop was deprecated in favor of `slots.transition`:

```diff
<SpeedDial
- TransitionComponent={CustomTransition}
+ slots={{ transition: CustomTransition }}
```

### TransitionProps

The SpeedDial's `TransitionProps` prop was deprecated in favor of `slotProps.transition`:

```diff
<SpeedDial
- TransitionProps={{ unmountOnExit: true }}
+ slotProps={{ transition: { unmountOnExit: true } }}
/>
```
12 changes: 10 additions & 2 deletions docs/pages/material-ui/api/accordion.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@
},
"additionalInfo": { "sx": true }
},
"TransitionComponent": { "type": { "name": "elementType" } },
"TransitionProps": { "type": { "name": "object" } }
"TransitionComponent": {
"type": { "name": "elementType" },
"deprecated": true,
"deprecationInfo": "Use <code>slots.transition</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"TransitionProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.transition</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
}
},
"name": "Accordion",
"imports": [
Expand Down
33 changes: 28 additions & 5 deletions docs/pages/material-ui/api/autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
},
"default": "false"
},
"ChipProps": { "type": { "name": "object" } },
"ChipProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.chip</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"clearIcon": { "type": { "name": "node" }, "default": "<ClearIcon fontSize=\"small\" />" },
"clearOnBlur": { "type": { "name": "bool" }, "default": "!props.freeSolo" },
Expand Down Expand Up @@ -93,8 +97,17 @@
}
},
"limitTags": { "type": { "name": "custom", "description": "integer" }, "default": "-1" },
"ListboxComponent": { "type": { "name": "elementType" }, "default": "'ul'" },
"ListboxProps": { "type": { "name": "object" } },
"ListboxComponent": {
"type": { "name": "elementType" },
"default": "'ul'",
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.listbox.component</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"ListboxProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.listbox</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"loading": { "type": { "name": "bool" }, "default": "false" },
"loadingText": { "type": { "name": "node" }, "default": "'Loading…'" },
"multiple": { "type": { "name": "bool" }, "default": "false" },
Expand Down Expand Up @@ -137,8 +150,18 @@
"open": { "type": { "name": "bool" } },
"openOnFocus": { "type": { "name": "bool" }, "default": "false" },
"openText": { "type": { "name": "string" }, "default": "'Open'" },
"PaperComponent": { "type": { "name": "elementType" }, "default": "Paper" },
"PopperComponent": { "type": { "name": "elementType" }, "default": "Popper" },
"PaperComponent": {
"type": { "name": "elementType" },
"default": "Paper",
"deprecated": true,
"deprecationInfo": "Use <code>slots.paper</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"PopperComponent": {
"type": { "name": "elementType" },
"default": "Popper",
"deprecated": true,
"deprecationInfo": "Use <code>slots.popper</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"popupIcon": { "type": { "name": "node" }, "default": "<ArrowDropDownIcon />" },
"readOnly": { "type": { "name": "bool" }, "default": "false" },
"renderGroup": {
Expand Down
6 changes: 5 additions & 1 deletion docs/pages/material-ui/api/avatar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"component": { "type": { "name": "elementType" } },
"imgProps": { "type": { "name": "object" } },
"imgProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.img</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"sizes": { "type": { "name": "string" } },
"slotProps": {
"type": { "name": "shape", "description": "{ img?: func<br>&#124;&nbsp;object }" },
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/material-ui/api/backdrop.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
},
"additionalInfo": { "sx": true }
},
"TransitionComponent": { "type": { "name": "elementType" }, "default": "Fade" },
"TransitionComponent": {
"type": { "name": "elementType" },
"default": "Fade",
"deprecated": true,
"deprecationInfo": "Use <code>slots.transition</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"transitionDuration": {
"type": {
"name": "union",
Expand Down
13 changes: 11 additions & 2 deletions docs/pages/material-ui/api/speed-dial.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,24 @@
},
"additionalInfo": { "sx": true }
},
"TransitionComponent": { "type": { "name": "elementType" }, "default": "Zoom" },
"TransitionComponent": {
"type": { "name": "elementType" },
"default": "Zoom\n* @deprecated Use `slots.transition` instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/)",
"deprecated": true,
"deprecationInfo": "Use <code>slots.transition</code> instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>"
},
"transitionDuration": {
"type": {
"name": "union",
"description": "number<br>&#124;&nbsp;{ appear?: number, enter?: number, exit?: number }"
},
"default": "{\n enter: theme.transitions.duration.enteringScreen,\n exit: theme.transitions.duration.leavingScreen,\n}"
},
"TransitionProps": { "type": { "name": "object" } }
"TransitionProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.transition</code> instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>"
}
},
"name": "SpeedDial",
"imports": [
Expand Down
12 changes: 10 additions & 2 deletions docs/pages/material-ui/api/step-label.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@
"type": { "name": "shape", "description": "{ label?: elementType, stepIcon?: elementType }" },
"default": "{}"
},
"StepIconComponent": { "type": { "name": "elementType" } },
"StepIconProps": { "type": { "name": "object" } },
"StepIconComponent": {
"type": { "name": "elementType" },
"deprecated": true,
"deprecationInfo": "Use <code>slots.stepIcon</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"StepIconProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.stepIcon</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"sx": {
"type": {
"name": "union",
Expand Down
14 changes: 9 additions & 5 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ npx @mui/codemod@latest deprecations/alert-props <path>
- }}
+ slots={{
+ paper: CustomPaper,
+ popper: CustomPopper,
+ listbox: CustomListbox,
+ popper: CustomPopper
+ }}
+ slotProps={{
+ chip: { height: 10 },
+ listbox: { height: 12 },
+ listbox: {
+ component: CustomListbox,
+ ...{ height: 12 },
+ },
+ clearIndicator: { width: 10 },
+ paper: { width: 12 },
+ popper: { width: 14 },
Expand All @@ -306,11 +308,13 @@ npx @mui/codemod@latest deprecations/alert-props <path>
+ slots: {
+ paper: CustomPaper,
+ popper: CustomPopper,
+ listbox: CustomListbox,
+ },
+ slotProps: {
+ chip: { height: 10 },
+ listbox: { height: 12 },
+ listbox: {
+ component: CustomListbox,
+ ...{ height: 12 },
+ },
+ clearIndicator: { width: 10 },
+ paper: { width: 12 },
+ popper: { width: 14 },
Expand Down
Loading