/
index.d.ts
317 lines (272 loc) · 9.86 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// allow this here since we want the declarations to be equivalent to declarations
// in their own files
// tslint:disable:strict-export-declare-modifiers
declare module '@material-ui/styles' {
export { default as createGenerateClassName } from '@material-ui/styles/createGenerateClassName';
export { default as createStyles } from '@material-ui/styles/createStyles';
export { default as getThemeProps } from '@material-ui/styles/getThemeProps';
export { default as install } from '@material-ui/styles/install';
export { default as jssPreset } from '@material-ui/styles/jssPreset';
export { default as makeStyles } from '@material-ui/styles/makeStyles';
export { default as styled } from '@material-ui/styles/styled';
export { default as StylesProvider } from '@material-ui/styles/StylesProvider';
export { default as ThemeProvider } from '@material-ui/styles/ThemeProvider';
export { default as useTheme } from '@material-ui/styles/useTheme';
export { default as withStyles, WithStyles } from '@material-ui/styles/withStyles';
export { default as withTheme, WithTheme } from '@material-ui/styles/withTheme';
}
declare module '@material-ui/styles/createGenerateClassName' {
import { GenerateId } from 'jss';
export interface GenerateClassNameOptions {
dangerouslyUseGlobalCSS?: boolean;
productionPrefix?: string;
seed?: string;
}
export default function createGenerateClassName(options?: GenerateClassNameOptions): GenerateId;
}
declare module '@material-ui/styles/createStyles' {
import { CSSProperties, StyleRules, ClassNameMap } from '@material-ui/styles/withStyles';
/**
* This function doesn't really "do anything" at runtime, it's just the identity
* function. Its only purpose is to defeat TypeScript's type widening when providing
* style rules to `withStyles` which are a function of the `Theme`.
*
* @param styles a set of style mappings
* @returns the same styles that were passed in
*/
export default function createStyles<C extends string, P extends object>(
styles: StyleRules<P, C>,
): StyleRules<P, C>;
}
declare module '@material-ui/styles/getThemeProps' {
import { ComponentsPropsList } from '@material-ui/core/styles/props';
import { Theme } from '@material-ui/core';
interface NamedParams<K extends keyof ComponentsPropsList> {
name: K;
props: ComponentsPropsList[K];
theme?: Theme;
}
export default function getThemeProps<Name extends keyof ComponentsPropsList>(
params: NamedParams<Name>,
): ComponentsPropsList[Name];
}
declare module '@material-ui/styles/install' {
export default function install(): void;
}
declare module '@material-ui/styles/jssPreset' {
import { JssOptions } from 'jss';
export default function jssPreset(): JssOptions;
}
declare module '@material-ui/styles/makeStyles' {
import {
ClassKeyOfStyles,
ClassNameMap,
PropsOfStyles,
Styles,
WithStylesOptions,
} from '@material-ui/styles/withStyles';
// https://stackoverflow.com/a/49928360/3406963 without generic branch types
type IsAny<T> = 0 extends (1 & T) ? true : false;
type Or<A, B, C = false> = A extends true
? true
: B extends true
? true
: C extends true
? true
: false;
type And<A, B, C = true> = A extends true
? B extends true
? C extends true
? true
: false
: false
: false;
/**
* @internal
*
* check if a type is `{}`
*
* 1. false if the given type has any members
* 2. false if the type is `object` which is the only other type with no members
* {} is a top type so e.g. `string extends {}` but not `string extends object`
* 3. false if the given type is `unknown`
*/
export type IsEmptyInterface<T> = And<
keyof T extends never ? true : false,
string extends T ? true : false,
unknown extends T ? false : true
>;
/**
* @internal
*
* If a style callback is given with `theme => stylesOfTheme` then typescript
* infers `Props` to `any`.
* If a static object is given with { ...members } then typescript infers `Props`
* to `{}`.
*
* So we require no props in `useStyles` if `Props` in `makeStyles(styles)` is
* inferred to either `any` or `{}`
*/
export type StylesRequireProps<S> = Or<
IsAny<PropsOfStyles<S>>,
IsEmptyInterface<PropsOfStyles<S>>
> extends true
? false
: true;
/**
* @internal
*
* `Props` are `any` either by explicit annotation or if there are no callbacks
* from which the typechecker could infer a type so it falls back to `any`.
* See the test cases for examples and implications of explicit `any` annotation
*/
export type StylesHook<S extends Styles<any, any>> = StylesRequireProps<S> extends false
? (props?: any) => ClassNameMap<ClassKeyOfStyles<S>>
: (props: PropsOfStyles<S>) => ClassNameMap<ClassKeyOfStyles<S>>;
export default function makeStyles<S extends Styles<any, any>>(
styles: S,
options?: WithStylesOptions,
): StylesHook<S>;
}
declare module '@material-ui/styles/styled' {
import { Omit, PropsOf } from '@material-ui/core';
import {
CSSProperties,
StyledComponentProps,
Styles,
WithStylesOptions,
} from '@material-ui/styles/withStyles';
/**
* @internal
*/
export type ComponentCreator<C extends React.ReactType> = <Theme>(
styles: CSSProperties | ((theme: Theme) => CSSProperties),
options?: WithStylesOptions,
) => React.ComponentType<
Omit<JSX.LibraryManagedAttributes<C, PropsOf<C>>, 'classes' | 'className'> &
StyledComponentProps<'root'> & { className?: string }
>;
export interface StyledProps {
className: string;
}
export default function styled<C extends React.ReactType>(Component: C): ComponentCreator<C>;
}
declare module '@material-ui/styles/StylesProvider' {
import { GenerateId, Jss } from 'jss';
interface StylesOptions {
disableGeneration?: boolean;
generateClassName?: GenerateId;
jss?: Jss;
// TODO need info @oliviertassinari
sheetsCache?: {};
// TODO need info @oliviertassinari
sheetsManager?: {};
// TODO need info @oliviertassinari
sheetsRegistry?: {};
}
const StylesContext: React.Context<StylesOptions>;
export interface StylesProviderProps extends StylesOptions {
children: React.ReactNode;
}
const StylesProvider: React.ComponentType<StylesProviderProps>;
export default StylesProvider;
}
declare module '@material-ui/styles/ThemeProvider' {
import { Theme } from '@material-ui/core';
const ThemeContext: React.Context<Theme>;
export interface ThemeProviderProps {
children: React.ReactNode;
theme: Theme | ((outerTheme: Theme) => Theme);
}
const ThemeProvider: React.ComponentType<ThemeProviderProps>;
export default ThemeProvider;
}
declare module '@material-ui/styles/useTheme' {
export default function useTheme<T>(): T;
}
declare module '@material-ui/styles/withStyles' {
import * as React from 'react';
import { Omit, PropInjector, PropsOf } from '@material-ui/core';
import * as CSS from 'csstype';
import * as JSS from 'jss';
export interface CSSProperties extends CSS.Properties<number | string> {
// Allow pseudo selectors and media queries
[k: string]: CSS.Properties<number | string>[keyof CSS.Properties] | CSSProperties;
}
/**
* @internal
* This is basically the API of JSS. It defines a Map<string, CSS>,
* where
* - the `keys` are the class (names) that will be created
* - the `values` are objects that represent CSS rules (`React.CSSProperties`).
*
* if only `CSSProperties` are matched `Props` are inferred to `any`
*/
export type StyleRules<Props extends object, ClassKey extends string = string> = Record<
ClassKey,
CSSProperties | ((props: Props) => CSSProperties)
>;
/**
* @internal
*/
export type StyleRulesCallback<Theme, Props extends object, ClassKey extends string = string> = (
theme: Theme,
) => StyleRules<Props, ClassKey>;
export type Styles<Theme, Props extends {}, ClassKey extends string = string> =
| StyleRules<Props, ClassKey>
| StyleRulesCallback<Theme, Props, ClassKey>;
export interface WithStylesOptions extends JSS.StyleSheetFactoryOptions {
flip?: boolean;
withTheme?: boolean;
name?: string;
}
export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;
/**
* @internal
*/
export type ClassKeyInferable<Theme, Props extends {}> = string | Styles<Theme, Props>;
export type ClassKeyOfStyles<S> = S extends string
? S
: S extends StyleRulesCallback<any, any, infer K>
? K
: S extends StyleRules<any, infer K>
? K
: never;
/**
* infers the type of the theme used in the styles
*/
export type PropsOfStyles<S> = S extends Styles<any, infer Props> ? Props : {};
/**
* infers the type of the props used in the styles
*/
export type ThemeOfStyles<S> = S extends Styles<infer Theme, any> ? Theme : {};
export type WithStyles<
S extends ClassKeyInferable<any, any>,
IncludeTheme extends boolean | undefined = false
> = (IncludeTheme extends true ? { theme: ThemeOfStyles<S> } : {}) & {
classes: ClassNameMap<ClassKeyOfStyles<S>>;
innerRef?: React.Ref<any> | React.RefObject<any>;
} & PropsOfStyles<S>;
export interface StyledComponentProps<ClassKey extends string = string> {
classes?: Partial<ClassNameMap<ClassKey>>;
innerRef?: React.Ref<any> | React.RefObject<any>;
}
export default function withStyles<
S extends Styles<any, any>,
Options extends WithStylesOptions = {}
>(
style: S,
options?: Options,
): PropInjector<WithStyles<S, Options['withTheme']>, StyledComponentProps<ClassKeyOfStyles<S>>>;
}
declare module '@material-ui/styles/withTheme' {
import { PropInjector } from '@material-ui/core';
export interface WithTheme<Theme> {
theme: Theme;
innerRef?: React.Ref<any>;
}
export default function withTheme<Theme>(): PropInjector<
WithTheme<Theme>,
Partial<WithTheme<Theme>>
>;
}