Skip to content

Commit

Permalink
Revert "[core] Adds component prop to OverrideProps type (mui#35924
Browse files Browse the repository at this point in the history
…)"

This reverts commit 1b9c8ab.
  • Loading branch information
michaldudak committed Jul 21, 2023
1 parent 33c231a commit 3ed335d
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 540 deletions.
4 changes: 2 additions & 2 deletions docs/data/material/guides/routing/LinkRouterWithTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { StaticRouter } from 'react-router-dom/server';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import Button from '@mui/material/Button';
import Stack from '@mui/material/Stack';
import Link from '@mui/material/Link';
import Link, { LinkProps } from '@mui/material/Link';

const LinkBehavior = React.forwardRef<
HTMLAnchorElement,
Expand All @@ -33,7 +33,7 @@ const theme = createTheme({
MuiLink: {
defaultProps: {
component: LinkBehavior,
},
} as LinkProps,
},
MuiButtonBase: {
defaultProps: {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/guides/routing/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const theme = createTheme({
MuiLink: {
defaultProps: {
component: LinkBehavior,
},
} as LinkProps,
},
MuiButtonBase: {
defaultProps: {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type LinkProps = {
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
noLinkStyle?: boolean;
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
Omit<MuiLinkProps, 'href' | 'component'>;
Omit<MuiLinkProps, 'href'>;

// A styled version of the Next.js Link component:
// https://nextjs.org/docs/api-reference/next/link
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ Button.propTypes /* remove-proptypes */ = {
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes /* @typescript-to-proptypes-ignore */.elementType,
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* @default false
Expand Down
33 changes: 0 additions & 33 deletions packages/mui-material/src/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,6 @@ function FakeIcon() {
return <div>Icon</div>;
}

const props1: ButtonProps<'div'> = {
component: 'div',
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props2: ButtonProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLButtonElement>, typeof event>(event);
},
};

const props3: ButtonProps<'span'> = {
// @ts-expect-error
component: 'div',
};

const props4: ButtonProps<typeof TestOverride> = {
component: TestOverride,
x: 2,
};

const props5: ButtonProps<typeof TestOverride> = {
component: TestOverride,
// @ts-expect-error
inCorrectProp: 3,
};

const props6: ButtonProps<typeof TestOverride> = {
component: TestOverride,
};

const buttonTest = () => (
<div>
<Button>I am a button!</Button>
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/Card/Card.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { SxProps } from '@mui/system';
import { DistributiveOmit } from '@mui/types';
import { OverridableComponent, OverrideProps } from '@mui/material/OverridableComponent';
import { Theme } from '..';
import { PaperOwnProps } from '../Paper';
import { PaperProps } from '../Paper';
import { CardClasses } from './cardClasses';

// TODO: v6 remove this interface, it is not used
export interface CardPropsColorOverrides {}

export interface CardTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P &
DistributiveOmit<PaperOwnProps, 'classes'> & {
DistributiveOmit<PaperProps, 'classes'> & {
/**
* Override or extend the styles applied to the component.
*/
Expand Down
33 changes: 0 additions & 33 deletions packages/mui-material/src/Card/Card.spec.tsx

This file was deleted.

13 changes: 4 additions & 9 deletions packages/mui-material/src/CardHeader/CardHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ interface ComponentProp {
component?: React.ElementType;
}

<CardHeader component={CustomComponent} stringProp="s" numberProp={2} />;

function createElementBasePropMixedTest() {
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader);
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader, {
component: 'div',
});
// ExpectError: type system should be demanding the required props of "CustomComponent"
// @ts-expect-error
React.createElement<CardHeaderProps<typeof CustomComponent>>(CardHeader, {
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader, {
component: CustomComponent,
stringProp: '2',
numberProp: 3,
incorrectProp: 3,
});

React.createElement<CardHeaderProps<typeof CustomComponent>>(CardHeader, {
// @ts-expect-error
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader, {
// This test shouldn't fail but does; stringProp & numberProp are required props of CustomComponent
component: CustomComponent,
stringProp: '',
numberProp: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Dialog/Dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface DialogProps extends StandardProps<ModalProps, 'children'> {
* Props applied to the [`Paper`](/material-ui/api/paper/) element.
* @default {}
*/
PaperProps?: Partial<PaperProps<React.ElementType>>;
PaperProps?: Partial<PaperProps>;
/**
* Determine the container for scrolling the dialog.
* @default 'paper'
Expand Down
19 changes: 3 additions & 16 deletions packages/mui-material/src/Dialog/Dialog.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import * as React from 'react';
import Dialog from '@mui/material/Dialog';
import { PaperProps } from '@mui/material/Paper';
import { expectType } from '@mui/types';
import { Dialog } from '@mui/material';

const paperProps: PaperProps<'span'> = {
component: 'span',
onClick: (event) => {
expectType<React.MouseEvent<HTMLSpanElement, MouseEvent>, typeof event>(event);
},
};
function Test() {
return (
<React.Fragment>
<Dialog open />;
<Dialog open PaperProps={paperProps} />;
</React.Fragment>
);
function optionalChildrenTest() {
<Dialog open />;
}
2 changes: 1 addition & 1 deletion packages/mui-material/src/Drawer/Drawer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface DrawerProps extends StandardProps<ModalProps, 'open' | 'childre
* Props applied to the [`Paper`](/material-ui/api/paper/) element.
* @default {}
*/
PaperProps?: Partial<PaperProps<React.ElementType>>;
PaperProps?: Partial<PaperProps>;
/**
* Props applied to the [`Slide`](/material-ui/api/slide/) element.
*/
Expand Down
19 changes: 0 additions & 19 deletions packages/mui-material/src/Drawer/Drawer.spec.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/mui-material/src/Fab/Fab.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Fab.propTypes /* remove-proptypes */ = {
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes /* @typescript-to-proptypes-ignore */.elementType,
component: PropTypes.elementType,
/**
* If `true`, the component is disabled.
* @default false
Expand Down
66 changes: 0 additions & 66 deletions packages/mui-material/src/FormHelperText/FormHelperText.spec.tsx

This file was deleted.

65 changes: 2 additions & 63 deletions packages/mui-material/src/Grid/Grid.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,7 @@
import * as React from 'react';
import Paper from '@mui/material/Paper';
import Grid, { GridProps } from '@mui/material/Grid';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props: GridProps<'span'> = {
component: 'span',
onChange: (event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
},
};

const props2: GridProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props3: GridProps<'span'> = {
// @ts-expect-error
component: 'div',
};

const props4: GridProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
};

const props5: GridProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: GridProps<typeof CustomComponent> = {
component: CustomComponent,
};
import Grid from '@mui/material/Grid';

function ResponsiveTest() {
return (
<React.Fragment>
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square />
<Grid item component={'a'} href="/test" />

<Grid item component={CustomComponent} stringProp="s" numberProp={1} />
{
// @ts-expect-error
<Grid item component={CustomComponent} />
}
<Grid
item
component="span"
onChange={(event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
}}
/>
</React.Fragment>
);
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square />;
}

0 comments on commit 3ed335d

Please sign in to comment.