-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
react-cool-dimensions.d.ts
59 lines (50 loc) · 1.57 KB
/
react-cool-dimensions.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
declare module "react-cool-dimensions" {
// Types from @types/resize-observer-browser
interface ResizeObserverSize {
readonly inlineSize: number;
readonly blockSize: number;
}
interface ResizeObserverEntry {
readonly target: Element;
readonly contentRect: DOMRectReadOnly;
readonly borderBoxSize: ResizeObserverSize;
readonly contentBoxSize: ResizeObserverSize;
}
// Hook types
export interface Event<T extends HTMLElement | null = HTMLElement> {
readonly currentBreakpoint: string;
readonly width: number;
readonly height: number;
readonly entry: ResizeObserverEntry;
observe: (element?: T | null) => void;
unobserve: () => void;
}
export interface State {
readonly currentBreakpoint: string;
readonly width: number | null;
readonly height: number | null;
readonly entry?: ResizeObserverEntry;
}
export interface ShouldUpdate {
(state: State): boolean;
}
export interface OnResize<T extends HTMLElement | null = HTMLElement> {
(event: Event<T>): void;
}
export interface Options<T extends HTMLElement | null = HTMLElement> {
useBorderBoxSize?: boolean;
breakpoints?: Record<string, number>;
updateOnBreakpointChange?: boolean;
shouldUpdate?: ShouldUpdate;
onResize?: OnResize<T>;
polyfill?: any;
}
export interface Return<T extends HTMLElement | null>
extends Omit<Event<T>, "entry"> {
entry?: ResizeObserverEntry;
}
function useDimensions<T extends HTMLElement | null = HTMLElement>(
options?: Options<T>
): Return<T>;
export default useDimensions;
}