-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
/
OverridableComponent.d.ts
67 lines (61 loc) · 2.09 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<TypeMap 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
// (for example SelectType, OptionType, etc.).
<RootComponent extends React.ElementType>(
props: {
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: RootComponent;
} & OverrideProps<TypeMap, RootComponent>,
): React.JSX.Element | null;
(props: DefaultComponentProps<TypeMap>): React.JSX.Element | null;
}
/**
* Props of the component if `component={Component}` is used.
*/
// prettier-ignore
export type OverrideProps<
TypeMap extends OverridableTypeMap,
RootComponent extends React.ElementType
> = (
& BaseProps<TypeMap>
& DistributiveOmit<React.ComponentPropsWithRef<RootComponent>, keyof BaseProps<TypeMap>>
);
/**
* Props if `component={Component}` is NOT used.
*/
// prettier-ignore
export type DefaultComponentProps<TypeMap extends OverridableTypeMap> =
& BaseProps<TypeMap>
& DistributiveOmit<React.ComponentPropsWithRef<TypeMap['defaultComponent']>, keyof BaseProps<TypeMap>>;
/**
* Props defined on the component (+ common material-ui props).
*/
// prettier-ignore
export type BaseProps<TypeMap extends OverridableTypeMap> =
& TypeMap['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;
}