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

[CardHeader] Deprecate *TypographyProps and complete slots, slotProps #44729

Merged
merged 7 commits into from
Jan 10, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add card-header-props codemod
siriwatknp committed Dec 11, 2024

Unverified

No user is associated with the committer email.
commit 9ef20798ab6add142b91d828c0f4845d2d2fc45e
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
@@ -27,6 +27,7 @@ import transformTextFieldProps from '../text-field-props';
import transformTabClasses from '../tab-classes';
import transformToggleButtonGroupClasses from '../toggle-button-group-classes';
import transformTooltipProps from '../tooltip-props';
import transformCardHeaderProps from '../card-header-props';

/**
* @param {import('jscodeshift').FileInfo} file
@@ -62,6 +63,7 @@ export default function deprecationsAll(file, api, options) {
file.source = transformTabClasses(file, api, options);
file.source = transformToggleButtonGroupClasses(file, api, options);
file.source = transformTooltipProps(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' }}
/>;