-
Notifications
You must be signed in to change notification settings - Fork 115
/
index.d.ts
69 lines (59 loc) · 1.98 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
import * as React from "react";
export interface MediaQueryObject {
[id: string]: boolean | number | string;
}
/**
* All allowed forms of media query inputs
*/
type MediaQueryValue = string | MediaQueryObject | MediaQueryObject[];
/**
* The type of the `queries` prop
*/
interface MediaQueries {
[key: string]: MediaQueryValue;
}
/**
* The type of returned `matches` in case the `queries` prop is provided. The keys on `matches`
* are inferred from the shape of `queries`.
*
* @example
*
* <Media queries={{ small: '...', medium: '...' }}>{
* // matches: { small: boolean, medium: boolean }
* matches => {}
* }</Media>
*/
type QueryResults<Queries = MediaQueries> = { [key in keyof Queries]: boolean };
type BaseProps = {
render?: () => React.ReactNode;
targetWindow?: Window;
};
/**
* Props for the <Media> component when specifying `queries` (as opposed to `query`)
*/
export type MultiQueryProps<Queries> = BaseProps & {
queries: Queries;
defaultMatches?: Partial<QueryResults<Queries>>;
children?:
| ((matches: QueryResults<Queries>) => React.ReactNode)
| React.ReactNode;
onChange?: (matches: QueryResults<Queries>) => void;
};
/**
* Props for the <Media> component when specifying `query` (as opposed to `queries`)
*/
export type SingleQueryProps = BaseProps & {
query: MediaQueryValue;
defaultMatches?: boolean;
children?: ((matches: boolean) => React.ReactNode) | React.ReactNode;
onChange?: (matches: boolean) => void;
};
/**
* Conditionally renders based on whether or not a media query matches.
*/
export default function Media(props: SingleQueryProps): React.ReactElement;
export default function Media<Q>(props: MultiQueryProps<Q>): React.ReactElement;
type UseMediaSingleQueryProps = Omit<SingleQueryProps, 'render' | 'children'>
type UseMediaMultiQueryProps<Q> = Omit<MultiQueryProps<Q>, 'render' | 'children'>
export function useMedia(props: SingleQueryProps): boolean;
export function useMedia<Q>(props: UseMediaMultiQueryProps<Q>): QueryResults<Q>;