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

[material-ui][Badge] Deprecated components and componentsProps props for v6 #41399

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4a29139
badge.json
skmanoj322 Feb 20, 2024
d3cee36
badge test where added
skmanoj322 Feb 20, 2024
d0fc9ab
modified - badge folder
skmanoj322 Feb 22, 2024
a637de5
codemod update
skmanoj322 Feb 23, 2024
e2c5f06
codemod changes
skmanoj322 Feb 23, 2024
763a2d9
minnor changes
skmanoj322 Mar 4, 2024
f816919
final-commit-1115
skmanoj322 Mar 4, 2024
1959307
codemod-changes
skmanoj322 Mar 4, 2024
06ece7a
badge correction
skmanoj322 Mar 4, 2024
c7d9c3e
adjusted codemon code
skmanoj322 Mar 5, 2024
d3cb8d2
Merge branch 'master' of https://github.com/mui/material-ui into mano…
skmanoj322 Mar 5, 2024
d36a63a
removed autocomplete from md
skmanoj322 Mar 5, 2024
9a7e6b8
Merge branch 'master' into manoj/badge-v6-deprecations
skmanoj322 Mar 12, 2024
2526e56
added theme test
skmanoj322 Mar 12, 2024
ddc381f
updated expected.js
skmanoj322 Mar 12, 2024
1b85030
restored the test cases
skmanoj322 Mar 12, 2024
44c33b1
updated theme.expected.js
skmanoj322 Mar 12, 2024
5525e7f
modified actual.js
skmanoj322 Mar 13, 2024
f025c7f
modified expected.js
skmanoj322 Mar 13, 2024
2e65e81
modified readme
skmanoj322 Mar 14, 2024
ddcf911
changed test file
skmanoj322 Mar 14, 2024
c8dfeb0
[docs] Update the versions dropdown to show v6 (#41557)
mnajdova Mar 20, 2024
deb7a6d
[blog] Add post about remote (#41565)
danilo-leal Mar 20, 2024
6888897
[blog] Blog post with MUI X v7.0.0 annoucement (#41563) (#41604)
cherniavskii Mar 22, 2024
39fe215
[docs] Add notification for MUI X v7 blog post (#41587) (#41605)
cherniavskii Mar 22, 2024
bd8ced4
[website] Update pricing table (#41606)
cherniavskii Mar 22, 2024
168604e
Merge branch 'master' into manoj/badge-v6-deprecations
skmanoj322 Mar 22, 2024
71992c1
correct test cases
skmanoj322 Mar 25, 2024
1f419af
ran pnpm docs:api
skmanoj322 Mar 25, 2024
4a9e8c2
updated readme codemod
skmanoj322 Mar 25, 2024
1b9818b
Revert "updated readme codemod"
skmanoj322 Mar 25, 2024
ad0fbd7
Revert "ran pnpm docs:api"
skmanoj322 Mar 25, 2024
0583e74
Revert "correct test cases"
skmanoj322 Mar 25, 2024
c56b396
Revert "Merge branch 'master' into manoj/badge-v6-deprecations"
skmanoj322 Mar 25, 2024
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 @@ -239,6 +239,36 @@ The Avatar's `imgProps` was deprecated in favor of `slotProps.img`:
/>;
```

## 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:

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

### components

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

```diff
<Badge
- components={{ Badge: CustomBadge }}
+ slots={{ badge: CustomBadge }}
/>
```

### componentsProps

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

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

## Button

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#button-classes) below to migrate the code as described in the following sections:
Expand Down
22 changes: 20 additions & 2 deletions docs/pages/material-ui/api/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
"component": { "type": { "name": "elementType" } },
"components": {
"type": { "name": "shape", "description": "{ Badge?: elementType, Root?: elementType }" },
"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>."
},
"componentsProps": {
"type": {
"name": "shape",
"description": "{ badge?: func<br>&#124;&nbsp;object, 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>."
},
"invisible": { "type": { "name": "bool" }, "default": "false" },
"max": { "type": { "name": "number" }, "default": "99" },
Expand Down Expand Up @@ -64,6 +68,20 @@
},
"name": "Badge",
"imports": ["import Badge from '@mui/material/Badge';", "import { Badge } from '@mui/material';"],
"slots": [
{
"name": "badge",
"description": "",
"default": "",
"class": null
},
{
"name": "root",
"description": "",
"default": "",
"class": null
}
],
"classes": [
{
"key": "anchorOriginBottomLeft",
Expand Down
12 changes: 8 additions & 4 deletions docs/translations/api-docs/badge/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"description": "The component used for the root node. Either a string to use a HTML element or a component."
},
"components": {
"description": "The components used for each slot inside.<br>This prop is an alias for the <code>slots</code> prop. It&#39;s recommended to use the <code>slots</code> prop instead."
"description": "The components used for each slot inside."
},
"componentsProps": {
"description": "The extra props for the slot components. You can override the existing props or add new ones.<br>This prop is an alias for the <code>slotProps</code> prop. It&#39;s recommended to use the <code>slotProps</code> prop instead, as <code>componentsProps</code> will be deprecated in the future."
"description": "The extra props for the slot components. You can override the existing props or add new ones."
},
"invisible": { "description": "If <code>true</code>, the badge is invisible." },
"max": { "description": "Max count to show." },
"overlap": { "description": "Wrapped shape the badge should overlap." },
"showZero": {
"description": "Controls whether the badge is hidden when <code>badgeContent</code> is zero."
},
"slotProps": { "description": "The props used for each slot inside the Badge." },
"slotProps": { "description": "The props used for each slot inside." },
"slots": {
"description": "The components used for each slot inside the Badge. Either a string to use a HTML element or a component."
"description": "The components used for each slot inside."
},
"sx": {
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
Expand Down Expand Up @@ -153,5 +153,9 @@
"nodeName": "the badge <code>span</code> element",
"conditions": "<code>variant=\"standard\"</code>"
}
},
"slotDescriptions": {
"badge": "",
"root": ""
}
}
13 changes: 13 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ npx @mui/codemod@latest deprecations/alert-props <path>
/>;
```

#### `badge-props`

```diff
<Badge
- components={{Badge:CustomBadge}}
- componentsProps={{ badge: { testid: 'test-id' } }}
+ slots={{badge:CustomBadge}}
+ slotsProps={{ badge:{ testid:'test-id'} }}
/>
```

```bash
npx @mui/codemod@latest deprecations/badge-props <path>
#### `button-classes`

JS transforms:
Expand Down
14 changes: 14 additions & 0 deletions packages/mui-codemod/src/deprecations/badge-props/badge-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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: 'Badge' });
return root.toSource(printOptions);
}
Copy link
Member

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import path from 'path';
import { expect } from 'chai';
import transform from './badge-props';
import { jscodeshift } from '../../../testUtils';
import readFile from '../../util/readFile';

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

describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('badge-props', () => {
it('transforms props as needed', () => {
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {});
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
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {});
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, { printOptions: { trailingComma: true } });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these is missing in slider any specific reason why?


const expected = read('./test-cases/excepted.js');
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
const expected = read('./test-cases/excepted.js');
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/actual.js') }, { jscodeshift }, {});

const excepted = read('./test-cases/excepted.js');
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
const excepted = read('./test-cases/excepted.js');
const excepted = read('./test-cases/expected.js');

expect(actual).to.equal(excepted, 'The transformed version should be correct');
});
});

describe('[theme] badge-props', () => {
it('transforms props as needed', () => {
const actual = transform(
{ source: read('./test-cases/theme.actual.js') },
{ jscodeshift },
{ printOptions: { trailingComma: false } },
);

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');
});
});
});
});
1 change: 1 addition & 0 deletions packages/mui-codemod/src/deprecations/badge-props/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './badge-props';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Badge } from '@mui/material';

<Badge components={{ root: ComponentsRoot }} componentsProps={{ root: componentsProps }} />;

<Badge
slots={{ root: SlotsRoot, badge: SlotsBadge }}
components={{ root: ComponentsRoot, badge: ComponentsBadge }}
slotProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
componentsProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
skmanoj322 marked this conversation as resolved.
Show resolved Hide resolved
/>;

<Badge
slots={{ root: SlotsRoot, badge: SlotsBadge }}
components={{ root: ComponentsRoot, badge: ComponentsBadge }}
slotsProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
componentsProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
skmanoj322 marked this conversation as resolved.
Show resolved Hide resolved
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Badge } from '@mui/material';

<Badge
slots={{
root: ComponentsRoot,
}}
slotProps={{ root: componentsProps }}
/>;

<Badge
slots={{ root: SlotsRoot, badge: SlotsBadge }}
slotProps={{
root: {
...slotsRootProps,
skmanoj322 marked this conversation as resolved.
Show resolved Hide resolved
...slotsRootProps,
},
badge: {
...slotsBadgeProps,
skmanoj322 marked this conversation as resolved.
Show resolved Hide resolved
...slotsBadgeProps,
},
}}
/>;

<Badge
slots={{ root: SlotsRoot, badge: SlotsBadge }}
slotsProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
slotProps={{ root: slotsRootProps, badge: slotsBadgeProps }}
skmanoj322 marked this conversation as resolved.
Show resolved Hide resolved
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
fn({
MuiBadge: {
defaultProps: {
components: { root: ComponentsRoot },
componentsProps: { root: componentsRootProps },
},
},
});

fn({
MuiBadge: {
defaultProps: {
components: { root: ComponentsRoot },
slots: { badge: SlotsBadge },
componentsProps: { root: componentsRootProps },
slotProps: { badge: slotsBadgeProps },
},
},
});

fn({
MuiBadge: {
defaultProps: {
components: { root: ComponentsRoot },
slots: { badge: SlotsBadge, root: SlotsRoot },
componentsProps: { root: componentsRootProps },
slotProps: { root: slotsRootProps, badge: slotsBadgeProps },
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
fn({
MuiBadge: {
defaultProps: {
slots: {
root: ComponentsRoot,
},

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

fn({
MuiBadge: {
defaultProps: {
slots: {
root: ComponentsRoot,
badge: SlotsBadge,
},

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

fn({
MuiBadge: {
defaultProps: {
slots: {
root: SlotsRoot,
badge: SlotsBadge,
},

slotProps: {
root: {
...componentsRootProps,
...slotsRootProps,
},

badge: slotsBadgeProps,
},
},
},
});
3 changes: 2 additions & 1 deletion packages/mui-material/src/Badge/Badge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface BadgeOwnProps {
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
*
* @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?: BadgeOwnProps['slotProps'];
Expand All @@ -83,7 +84,7 @@ export interface BadgeOwnProps {
*
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
*
* @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?: {
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material/src/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ Badge.propTypes /* remove-proptypes */ = {
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
*
* @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({
Expand All @@ -413,7 +414,7 @@ Badge.propTypes /* remove-proptypes */ = {
*
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
*
* @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
1 change: 0 additions & 1 deletion packages/mui-material/src/Badge/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use client';
export { default } from './Badge';

export { default as badgeClasses } from './badgeClasses';
export * from './badgeClasses';
Loading