Skip to content

Commit

Permalink
removal of transition duration from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Whorlow committed Mar 6, 2024
1 parent dfe5e0d commit cd51367
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 70 deletions.
2 changes: 0 additions & 2 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ npx @mui/codemod@latest deprecations/divider-props <path>
```diff
<Backdrop
- TransitionComponent={CustomTransition}
- TransitionProps={{ unmountOnExit: true }}
+ slots={{ transition: CustomTransition }}
+ slotProps={{ transition: { unmountOnExit: true } }}
/>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function transformer(file, api, options) {
const printOptions = options.printOptions;

findComponentJSX(j, { root, componentName: 'Backdrop' }, (elementPath) => {
let index = elementPath.node.openingElement.attributes.findIndex(
const index = elementPath.node.openingElement.attributes.findIndex(
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'TransitionComponent',
);
if (index !== -1) {
Expand All @@ -38,41 +38,6 @@ export default function transformer(file, api, options) {
});
}
}

index = elementPath.node.openingElement.attributes.findIndex(
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'transitionDuration',
);

if (index !== -1) {
const removed = elementPath.node.openingElement.attributes.splice(index, 1);
const updated = j.objectExpression([
j.objectProperty(
j.identifier('transition'),
j.objectExpression([
j.objectProperty(j.identifier('timeout'), removed[0].value.expression),
]),
),
]);

let hasNode = false;
elementPath.node.openingElement.attributes.forEach((attr) => {
if (attr.name?.name === 'slotProps') {
hasNode = true;
assignObject(j, {
target: attr,
key: 'transition',
expression: updated,
});
}
});
if (!hasNode) {
appendAttribute(j, {
target: elementPath.node,
attributeName: 'slotProps',
expression: updated,
});
}
}
});

root.find(j.ObjectProperty, { key: { name: 'TransitionComponent' } }).forEach((path) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Backdrop from '@mui/material/Backdrop';
import { Backdrop as MyBackdrop } from '@mui/material';

<Backdrop TransitionComponent={CustomTransition} transitionDuration={100} />;
<MyBackdrop TransitionComponent={CustomTransition} transitionDuration={100} />;
<Backdrop TransitionComponent={CustomTransition} />;
<MyBackdrop TransitionComponent={CustomTransition} />;
<Backdrop
TransitionComponent={CustomTransition}
transitionDuration={100}
slots={{
root: 'div',
}}
Expand All @@ -15,7 +14,6 @@ import { Backdrop as MyBackdrop } from '@mui/material';
/>;
<MyBackdrop
TransitionComponent={CustomTransition}
transitionDuration={100}
slots={{
...outerSlots,
}}
Expand All @@ -24,4 +22,4 @@ import { Backdrop as MyBackdrop } from '@mui/material';
}}
/>;
// should skip non MUI components
<NonMuiBackdrop TransitionComponent={CustomTransition} transitionDuration={100} />;
<NonMuiBackdrop TransitionComponent={CustomTransition} />;
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ import { Backdrop as MyBackdrop } from '@mui/material';

<Backdrop slots={{
transition: CustomTransition
}} slotProps={{
transition: {
timeout: 100
}
}} />;
<MyBackdrop slots={{
transition: CustomTransition
}} slotProps={{
transition: {
timeout: 100
}
}} />;
<Backdrop
slots={{
Expand All @@ -22,12 +14,6 @@ import { Backdrop as MyBackdrop } from '@mui/material';
}}
slotProps={{
root: { className: 'foo' },

transition: {
transition: {
timeout: 100
}
}
}} />;
<MyBackdrop
slots={{
Expand All @@ -36,12 +22,6 @@ import { Backdrop as MyBackdrop } from '@mui/material';
}}
slotProps={{
...outerSlotProps,

transition: {
transition: {
timeout: 100
}
}
}} />;
// should skip non MUI components
<NonMuiBackdrop TransitionComponent={CustomTransition} transitionDuration={100} />;
<NonMuiBackdrop TransitionComponent={CustomTransition} />;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fn({
MuiBackdrop: {
defaultProps: {
TransitionComponent: CustomTransition,
TransitionProps: { unmountOnExit: true },
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ fn({
defaultProps: {
slots: {
transition: CustomTransition
},

TransitionProps: { unmountOnExit: true }
}
},
},
});
6 changes: 4 additions & 2 deletions packages/mui-material/src/Backdrop/Backdrop.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export type BackdropSlotsAndSlotProps = CreateSlotsAndSlotProps<
}
>;

export interface BackdropOwnProps extends Partial<Omit<FadeProps, 'children'>> {
export interface BackdropOwnProps
extends Partial<Omit<FadeProps, 'children'>>,
BackdropSlotsAndSlotProps {
/**
* The content of the component.
*/
Expand Down Expand Up @@ -110,7 +112,7 @@ export interface BackdropTypeMap<
AdditionalProps = {},
RootComponent extends React.ElementType = 'div',
> {
props: AdditionalProps & BackdropOwnProps & BackdropSlotsAndSlotProps;
props: AdditionalProps & BackdropOwnProps;
defaultComponent: RootComponent;
}

Expand Down

0 comments on commit cd51367

Please sign in to comment.