forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Offer alternative to
OverridableComponent
via module augment…
…ation for better performance (mui#32735)
- Loading branch information
Showing
5 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/mui-material/src/OverridableComponentAugmentation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react'; | ||
import { DistributiveOmit } from '@mui/types'; | ||
|
||
declare module '@mui/material/OverridableComponent' { | ||
/** | ||
* A component whose root component can be controlled via a `component` prop. | ||
* | ||
* Adjusts valid props based on the type of `component`. | ||
*/ | ||
interface OverridableComponent<M extends OverridableTypeMap> { | ||
<C extends React.ElementType>( | ||
props: { | ||
/** | ||
* The component used for the root node. | ||
* Either a string to use a HTML element or a component. | ||
*/ | ||
component: C; | ||
} & OverridePropsVer2<M, C>, | ||
): JSX.Element; | ||
(props: DefaultComponentPropsVer2<M>): JSX.Element; | ||
} | ||
|
||
/** | ||
* Props of the component if `component={Component}` is used. | ||
*/ | ||
// prettier-ignore | ||
type OverridePropsVer2< | ||
M extends OverridableTypeMap, | ||
C extends React.ElementType, | ||
> = ( | ||
& BaseProps<M> | ||
& DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof BaseProps<M>> | ||
& { ref?: React.Ref<Element> } | ||
); | ||
|
||
/** | ||
* Props if `component={Component}` is NOT used. | ||
*/ | ||
// prettier-ignore | ||
type DefaultComponentPropsVer2<M extends OverridableTypeMap> = | ||
& BaseProps<M> | ||
& DistributiveOmit<React.ComponentPropsWithoutRef<M['defaultComponent']>, keyof BaseProps<M>> | ||
& { ref?: React.Ref<Element> }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"include": ["src/**/*", "test/**/*"], | ||
"exclude": ["test/typescript/moduleAugmentation"] | ||
"exclude": ["test/typescript/moduleAugmentation", "src/OverridableComponentAugmentation.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react'; | ||
|
||
declare module '@mui/types' { | ||
/** | ||
* A component whose root component can be controlled via a `component` prop. | ||
* | ||
* Adjusts valid props based on the type of `component`. | ||
*/ | ||
interface OverridableComponent<M extends OverridableTypeMap> { | ||
<C extends React.ElementType>( | ||
props: { | ||
/** | ||
* The component used for the root node. | ||
* Either a string to use a HTML element or a component. | ||
*/ | ||
component: C; | ||
} & OverridePropsVer2<M, C>, | ||
): JSX.Element; | ||
(props: DefaultComponentPropsVer2<M>): JSX.Element; | ||
propTypes?: any; | ||
} | ||
|
||
/** | ||
* Props of the component if `component={Component}` is used. | ||
*/ | ||
// prettier-ignore | ||
type OverridePropsVer2< | ||
M extends OverridableTypeMap, | ||
C extends React.ElementType | ||
> = ( | ||
& BaseProps<M> | ||
& DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof BaseProps<M>> | ||
& { ref?: React.Ref<Element> } | ||
); | ||
|
||
/** | ||
* Props if `component={Component}` is NOT used. | ||
*/ | ||
// prettier-ignore | ||
type DefaultComponentPropsVer2<M extends OverridableTypeMap> = | ||
& BaseProps<M> | ||
& DistributiveOmit<React.ComponentPropsWithoutRef<M['defaultComponent']>, keyof BaseProps<M>> | ||
& { ref?: React.Ref<Element> }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig" | ||
"extends": "../../tsconfig", | ||
"exclude": ["OverridableComponentAugmentation.ts"] | ||
} |