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][AvatarGroup] deprecate componentsProps for v6 #42122

Merged
merged 23 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
97dbf29
deprecate componentsProps prop
lhilgert9 May 4, 2024
1f4d3d1
add codemod
lhilgert9 May 4, 2024
63f3ea4
add docs for deprecation
lhilgert9 May 4, 2024
288c58b
fix undefined type error
lhilgert9 May 4, 2024
9174052
migrate avatar group tests to not use deprecated apis
lhilgert9 May 4, 2024
8b95211
Revert "migrate avatar group tests to not use deprecated apis"
lhilgert9 May 7, 2024
39c3f40
fix branch on migrate-from-deprecated-apis
lhilgert9 May 8, 2024
309d58b
Merge remote-tracking branch 'upstream/next' into deprecate-avatarGro…
lhilgert9 May 8, 2024
596cd4a
fix missing npx statement
lhilgert9 May 9, 2024
378858a
fix deprecation warning
lhilgert9 May 9, 2024
c997f46
pnpm proptypes
lhilgert9 May 9, 2024
5737aed
implement surplus slots and slotProps
lhilgert9 May 9, 2024
7b3d31a
fix ownerState of surplus that background-color is set
lhilgert9 May 10, 2024
30184a0
improve ownerState fix
lhilgert9 May 10, 2024
7d0c9fd
deprecate additionalAvatar in favor of surplus slotProp and add to co…
lhilgert9 May 12, 2024
1ba9d58
update docs
lhilgert9 May 12, 2024
4ea5878
add comments to codemod
lhilgert9 May 14, 2024
de5c77b
fix surplus slotProps type
lhilgert9 May 14, 2024
fff3076
add tests for new slots and slotProps props
lhilgert9 May 14, 2024
88703af
pnpm prettier
lhilgert9 May 14, 2024
5c395e1
fix surplus ownerState propagation
lhilgert9 May 15, 2024
e8a1512
pnpm prettier
lhilgert9 May 15, 2024
a4fdeb4
Merge remote-tracking branch 'upstream/next' into deprecate-avatarGro…
lhilgert9 May 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,28 @@ The Avatar's `imgProps` was deprecated in favor of `slotProps.img`:
/>;
```

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

```bash
npx @mui/codemod@latest deprecations/avatar-group-props <path>
lhilgert9 marked this conversation as resolved.
Show resolved Hide resolved
```

### componentsProps

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

```diff
<AvatarGroup
- componentsProps={{
- additionalAvatar: {color: "red"}
+ slotProps={{
+ additionalAvatar: {color: "red"}
}}
/>;
```

## Backdrop

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#backdrop-props) below to migrate the code as described in the following sections:
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/material-ui/api/avatar-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"component": { "type": { "name": "elementType" } },
"componentsProps": {
"type": { "name": "shape", "description": "{ additionalAvatar?: object }" },
"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>."
},
"max": { "type": { "name": "custom", "description": "number" }, "default": "5" },
"renderSurplus": {
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/avatar-group/avatar-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"description": "The component used for the root node. Either a string to use a HTML element or a component."
},
"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.<br>This prop is an alias for the <code>slotProps</code> prop."
},
"max": { "description": "Max avatars to show before +x." },
"renderSurplus": {
Expand Down
12 changes: 12 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ npx @mui/codemod@next deprecations/alert-classes <path>
npx @mui/codemod@next deprecations/alert-props <path>
```

#### `avatar-group-props`

```diff
<AvatarGroup
- componentsProps={{
- additionalAvatar: {color: "red"}
+ slotProps={{
+ additionalAvatar: {color: "red"}
}}
/>;
```

lhilgert9 marked this conversation as resolved.
Show resolved Hide resolved
#### `avatar-props`

```diff
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-codemod/src/deprecations/all/deprecations-all.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import transformAccordionProps from '../accordion-props';
import transformFormControlLabelProps from '../form-control-label-props';
import transformAvatarGroupProps from '../avatar-group-props';
import transformAvatarProps from '../avatar-props';
import transformDividerProps from '../divider-props';
import transformAccordionClasses from '../accordion-summary-classes';
Expand All @@ -21,6 +22,7 @@ import transformSpeedDialProps from '../speed-dial-props';
export default function deprecationsAll(file, api, options) {
file.source = transformAccordionProps(file, api, options);
file.source = transformFormControlLabelProps(file, api, options);
file.source = transformAvatarGroupProps(file, api, options);
file.source = transformAvatarProps(file, api, options);
file.source = transformDividerProps(file, api, options);
file.source = transformAccordionClasses(file, api, options);
Expand Down
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: 'AvatarGroup' });

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 './avatar-group-props';
import readFile from '../../util/readFile';

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

describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('avatar-group-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] avatar-group-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');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './avatar-group-props';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import AvatarGroup from '@mui/material/AvatarGroup';
import { AvatarGroup as MyAvatarGroup } from '@mui/material';

<AvatarGroup
componentsProps={{
additionalAvatar: {color: "red"}
}}
/>;
<MyAvatarGroup
componentsProps={{
additionalAvatar: {color: "red"}
}}
/>;
<MyAvatarGroup
componentsProps={{
additionalAvatar: {color: "red"}
}}
slotProps={{
additionalAvatar: {color: "blue"}
}}
/>;

// should skip non MUI components
<NonMuiAvatarGroup
componentsProps={{
additionalAvatar: {color: "red"}
}}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import AvatarGroup from '@mui/material/AvatarGroup';
import { AvatarGroup as MyAvatarGroup } from '@mui/material';

<AvatarGroup
slotProps={{
additionalAvatar: {color: "red"}
}}
/>;
<MyAvatarGroup
slotProps={{
additionalAvatar: {color: "red"}
}}
/>;
<MyAvatarGroup
slotProps={{
additionalAvatar: {
...{color: "red"},
...{color: "blue"}
}
}} />;

// should skip non MUI components
<NonMuiAvatarGroup
componentsProps={{
additionalAvatar: {color: "red"}
}}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
fn({
MuiAvatarGroup: {
defaultProps: {
componentsProps: {
additionalAvatar: {color: "red"}
},
},
},
});

fn({
MuiAvatarGroup: {
defaultProps: {
componentsProps: {
additionalAvatar: {color: "red"}
},
slotProps: {
additionalAvatar: {color: "blue"}
}
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
fn({
MuiAvatarGroup: {
defaultProps: {
slotProps: {
additionalAvatar: {color: "red"}
}
},
},
});

fn({
MuiAvatarGroup: {
defaultProps: {
slotProps: {
additionalAvatar: {
...{color: "red"},
...{color: "blue"}
}
}
},
},
});
3 changes: 1 addition & 2 deletions packages/mui-material/src/AvatarGroup/AvatarGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export interface AvatarGroupProps extends StandardProps<React.HTMLAttributes<HTM
* You can override the existing props or add new ones.
*
* 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.
*
* @default {}
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
lhilgert9 marked this conversation as resolved.
Show resolved Hide resolved
*/
componentsProps?: {
additionalAvatar?: React.ComponentPropsWithRef<typeof Avatar> &
Expand Down
7 changes: 3 additions & 4 deletions packages/mui-material/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {
children: childrenProp,
className,
component = 'div',
componentsProps = {},
componentsProps,
max = 5,
renderSurplus,
slotProps = {},
Expand Down Expand Up @@ -105,7 +105,7 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {
const extraAvatars = Math.max(totalAvatars - clampedMax, totalAvatars - maxAvatars, 0);
const extraAvatarsElement = renderSurplus ? renderSurplus(extraAvatars) : `+${extraAvatars}`;

const additionalAvatarSlotProps = slotProps.additionalAvatar ?? componentsProps.additionalAvatar;
const additionalAvatarSlotProps = slotProps.additionalAvatar ?? componentsProps?.additionalAvatar;
Copy link
Member

Choose a reason for hiding this comment

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

Should we implement the additionalAvatar slot properly? I think surplus is a better name. This would mean:

  • Providing slots.surplus and slotProps.surplus
  • Using useSlot hook
  • Adding tests for the slot

What do you think @lhilgert9?

@mnajdova tagging you as the owner of the Avatar component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds logical to me and would also ensure uniformity for all components and offer the end user more customization options.👍🏼

Copy link
Member

Choose a reason for hiding this comment

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

Let's implement it 🙌🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DiegoAndai I have added surplus as slots and slotProps prop. I have marked slotProps.additionalAvatar as @deprecated. I also modified the codemod to change additionalAvatar to surplus. I just didn't know which tests you wanted to implement. If you tell me which ones we need there, I'll implement them too.


const marginValue =
ownerState.spacing && SPACINGS[ownerState.spacing] !== undefined
Expand Down Expand Up @@ -173,9 +173,8 @@ AvatarGroup.propTypes /* remove-proptypes */ = {
* You can override the existing props or add new ones.
*
* 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.
*
* @default {}
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
*/
componentsProps: PropTypes.shape({
additionalAvatar: PropTypes.object,
Expand Down