-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
/
OverridableComponent.d.ts
67 lines (61 loc) · 1.96 KB
/
OverridableComponent.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as React from 'react';
import { DistributiveOmit } from '@mui/types';
import { StyledComponentProps } from './styles';
/**
* A component whose root component can be controlled via a `component` prop.
*
* Adjusts valid props based on the type of `component`.
*/
export interface OverridableComponent<M extends OverridableTypeMap> {
// If you make any changes to this interface, please make sure to update the
// `OverridableComponent` type in `mui-types/index.d.ts` as well.
// Also, there are types in Base UI that have a similar shape to this interface
// (e.g. SelectUnstyledType, OptionUnstyledType, etc.).
<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;
} & OverrideProps<M, C>,
): JSX.Element | null;
(props: DefaultComponentProps<M>): JSX.Element | null;
}
/**
* Props of the component if `component={Component}` is used.
*/
// prettier-ignore
export type OverrideProps<
M extends OverridableTypeMap,
C extends React.ElementType
> = (
& BaseProps<M>
& DistributiveOmit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
);
/**
* Props if `component={Component}` is NOT used.
*/
// prettier-ignore
export type DefaultComponentProps<M extends OverridableTypeMap> =
& BaseProps<M>
& DistributiveOmit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;
/**
* Props defined on the component (+ common material-ui props).
*/
// prettier-ignore
export type BaseProps<M extends OverridableTypeMap> =
& M['props']
& CommonProps;
/**
* Props that are valid for material-ui components.
*/
// each component declares it's classes in a separate interface for proper JSDoc.
export interface CommonProps extends StyledComponentProps<never> {
className?: string;
style?: React.CSSProperties;
}
export interface OverridableTypeMap {
props: {};
defaultComponent: React.ElementType;
}