Skip to content

Commit

Permalink
[CardHeader] Deprecate *TypographyProps and complete slots, `slot…
Browse files Browse the repository at this point in the history
…Props` (#44729)
  • Loading branch information
siriwatknp authored Jan 10, 2025
1 parent 088bfa8 commit 11b3889
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,36 @@ Here's how to migrate:
},
```

## CardHeader

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

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

### titleTypographyProps

The CardHeader's `titleTypographyProps` props were deprecated in favor of `slotProps.title`:

```diff
<CardHeader
- titleTypographyProps={titleTypographyProps}
+ slotProps={{ title: titleTypographyProps }}
/>
```

### subheaderTypographyProps

The CardHeader's `subheaderTypographyProps` props were deprecated in favor of `slotProps.subheader`:

```diff
<CardHeader
- subheaderTypographyProps={subheaderTypographyProps}
+ slotProps={{ subheader: subheaderTypographyProps }}
/>
```

## Chip

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#chip-classes) below to migrate the code as described in the following sections:
Expand Down
77 changes: 50 additions & 27 deletions docs/pages/material-ui/api/card-header.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"component": { "type": { "name": "elementType" } },
"disableTypography": { "type": { "name": "bool" }, "default": "false" },
"slotProps": {
"type": {
"name": "shape",
"description": "{ action?: func<br>&#124;&nbsp;object, avatar?: func<br>&#124;&nbsp;object, content?: func<br>&#124;&nbsp;object, root?: func<br>&#124;&nbsp;object, subheader?: func<br>&#124;&nbsp;object, title?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": {
"name": "shape",
"description": "{ action?: elementType, avatar?: elementType, content?: elementType, root?: elementType, subheader?: elementType, title?: elementType }"
},
"default": "{}"
},
"subheader": { "type": { "name": "node" } },
"subheaderTypographyProps": { "type": { "name": "object" } },
"subheaderTypographyProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.subheader</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 All @@ -15,51 +33,56 @@
"additionalInfo": { "sx": true }
},
"title": { "type": { "name": "node" } },
"titleTypographyProps": { "type": { "name": "object" } }
"titleTypographyProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.title</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": "CardHeader",
"imports": [
"import CardHeader from '@mui/material/CardHeader';",
"import { CardHeader } from '@mui/material';"
],
"classes": [
"slots": [
{
"key": "action",
"className": "MuiCardHeader-action",
"description": "Styles applied to the action element.",
"isGlobal": false
"name": "root",
"description": "The component that renders the root slot.",
"default": "'div'",
"class": "MuiCardHeader-root"
},
{
"key": "avatar",
"className": "MuiCardHeader-avatar",
"description": "Styles applied to the avatar element.",
"isGlobal": false
"name": "avatar",
"description": "The component that renders the avatar slot.",
"default": "'div'",
"class": "MuiCardHeader-avatar"
},
{
"key": "content",
"className": "MuiCardHeader-content",
"description": "Styles applied to the content wrapper element.",
"isGlobal": false
"name": "action",
"description": "The component that renders the action slot.",
"default": "'div'",
"class": "MuiCardHeader-action"
},
{
"key": "root",
"className": "MuiCardHeader-root",
"description": "Styles applied to the root element.",
"isGlobal": false
"name": "content",
"description": "The component that renders the content slot.",
"default": "'div'",
"class": "MuiCardHeader-content"
},
{
"key": "subheader",
"className": "MuiCardHeader-subheader",
"description": "Styles applied to the subheader Typography element.",
"isGlobal": false
"name": "title",
"description": "The component that renders the title slot (as long as disableTypography is not `true`).\n[Follow this guide](https://mui.com/material-ui/api/typography/#props) to learn more about the requirements for this component.",
"default": "Typography",
"class": "MuiCardHeader-title"
},
{
"key": "title",
"className": "MuiCardHeader-title",
"description": "Styles applied to the title Typography element.",
"isGlobal": false
"name": "subheader",
"description": "The component that renders the subheader slot (as long as disableTypography is not `true`).\n[Follow this guide](https://mui.com/material-ui/api/typography/#props) to learn more about the requirements for this component.",
"default": "Typography",
"class": "MuiCardHeader-subheader"
}
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "MuiCardHeader",
Expand Down
32 changes: 10 additions & 22 deletions docs/translations/api-docs/card-header/card-header.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"disableTypography": {
"description": "If <code>true</code>, <code>subheader</code> and <code>title</code> won&#39;t be wrapped by a Typography component. This can be useful to render an alternative Typography variant by wrapping the <code>title</code> text, and optional <code>subheader</code> text with the Typography component."
},
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"subheader": { "description": "The content of the component." },
"subheaderTypographyProps": {
"description": "These props will be forwarded to the subheader (as long as disableTypography is not <code>true</code>)."
Expand All @@ -22,27 +24,13 @@
"description": "These props will be forwarded to the title (as long as disableTypography is not <code>true</code>)."
}
},
"classDescriptions": {
"action": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the action element"
},
"avatar": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the avatar element"
},
"content": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the content wrapper element"
},
"root": { "description": "Styles applied to the root element." },
"subheader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the subheader Typography element"
},
"title": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the title Typography element"
}
"classDescriptions": {},
"slotDescriptions": {
"action": "The component that renders the action slot.",
"avatar": "The component that renders the avatar slot.",
"content": "The component that renders the content slot.",
"root": "The component that renders the root slot.",
"subheader": "The component that renders the subheader slot (as long as disableTypography is not <code>true</code>). <a href=\"https://mui.com/material-ui/api/typography/#props\">Follow this guide</a> to learn more about the requirements for this component.",
"title": "The component that renders the title slot (as long as disableTypography is not <code>true</code>). <a href=\"https://mui.com/material-ui/api/typography/#props\">Follow this guide</a> to learn more about the requirements for this component."
}
}
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
Expand Up @@ -31,6 +31,7 @@ import transformTabClasses from '../tab-classes';
import transformToggleButtonGroupClasses from '../toggle-button-group-classes';
import transformTooltipProps from '../tooltip-props';
import transformTablePaginationProps from '../table-pagination-props';
import transformCardHeaderProps from '../card-header-props';

/**
* @param {import('jscodeshift').FileInfo} file
Expand Down Expand Up @@ -70,6 +71,7 @@ export default function deprecationsAll(file, api, options) {
file.source = transformToggleButtonGroupClasses(file, api, options);
file.source = transformTooltipProps(file, api, options);
file.source = transformTablePaginationProps(file, api, options);
file.source = transformCardHeaderProps(file, api, options);

return file.source;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import movePropIntoSlotProps from '../utils/movePropIntoSlotProps';

/**
* @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;

movePropIntoSlotProps(j, {
root,
componentName: 'CardHeader',
propName: 'titleTypographyProps',
slotName: 'title',
});

movePropIntoSlotProps(j, {
root,
componentName: 'CardHeader',
propName: 'subheaderTypographyProps',
slotName: 'subheader',
});

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

describe('@mui/codemod', () => {
describe('deprecations', () => {
describeJscodeshiftTransform({
transform,
transformName: 'tooltip-props',
dirname: __dirname,
testCases: [{ actual: '/test-cases/actual.js', expected: '/test-cases/expected.js' }],
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './card-header-props';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import CardHeader from '@mui/material/CardHeader';
import { CardHeader as MyCardHeader } from '@mui/material';

<CardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
/>;
<CardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
slotProps={{ title: { variant: 'h1' }, subheader: { variant: 'h2' } }}
/>;
<CardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
slotProps={{ title: { sx: { color: 'red' } }, subheader: { sx: { color: 'red' } } }}
/>;
<MyCardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
/>;

<CustomCardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import CardHeader from '@mui/material/CardHeader';
import { CardHeader as MyCardHeader } from '@mui/material';

<CardHeader
slotProps={{
title: { variant: 'h6' },
subheader: { variant: 'body2' }
}} />;
<CardHeader
slotProps={{ title: {
...{ variant: 'h6' },
...{ variant: 'h1' }
}, subheader: {
...{ variant: 'body2' },
...{ variant: 'h2' }
} }} />;
<CardHeader
slotProps={{ title: {
...{ variant: 'h6' },
...{ sx: { color: 'red' } }
}, subheader: {
...{ variant: 'body2' },
...{ sx: { color: 'red' } }
} }} />;
<MyCardHeader
slotProps={{
title: { variant: 'h6' },
subheader: { variant: 'body2' }
}} />;

<CustomCardHeader
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'body2' }}
/>;
Loading

0 comments on commit 11b3889

Please sign in to comment.