-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuseDetectScroll.types.ts
More file actions
115 lines (109 loc) · 1.96 KB
/
useDetectScroll.types.ts
File metadata and controls
115 lines (109 loc) · 1.96 KB
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
/**
* Axis values (const + type)
*/
export const Axis = {
/**
* Horizontal axis.
*/
X: 'x',
/**
* Vertical axis.
*/
Y: 'y',
} as const
/**
* Union of allowed axis values.
*/
export type Axis = (typeof Axis)[keyof typeof Axis]
/**
* Direction values (const + type)
*/
export const Direction = {
/**
* Scroll direction toward the top.
*/
Up: 'up',
/**
* Scroll direction toward the bottom.
*/
Down: 'down',
/**
* Scroll direction toward the left.
*/
Left: 'left',
/**
* Scroll direction toward the right.
*/
Right: 'right',
/**
* No scrolling detected.
*/
Still: 'still',
} as const
/**
* Union of allowed direction values.
*/
export type Direction = (typeof Direction)[keyof typeof Direction]
/**
* Scroll position values
*/
export type ScrollPosition = {
/**
* Distance from the top edge.
*/
top: number
/**
* Distance from the bottom edge.
*/
bottom: number
/**
* Distance from the left edge.
*/
left: number
/**
* Distance from the right edge.
*/
right: number
}
/**
* Scroll info returned by the hook
*/
export type ScrollInfo = {
/**
* Current scroll direction.
*/
scrollDir: Direction
/**
* Current scroll position.
*/
scrollPosition: ScrollPosition
}
/**
* Options accepted by the hook
*/
export type ScrollProps = {
/**
* Scroll target element (defaults to window).
*/
target?: HTMLDivElement | Window
/**
* Threshold for scroll direction changes.
*/
thr?: number
/**
* Axis to observe.
*/
axis?: Axis
/**
* Value returned when scrolling up (y) or left (x).
*/
scrollUp?: Direction
/**
* Value returned when scrolling down (y) or right (x).
*/
scrollDown?: Direction
/**
* Value returned when no scrolling is detected.
*/
still?: Direction
}