@smakss/react-scroll-direction 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +28 -24
- package/dist/cjs/index.js +66 -1232
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +68 -1234
- package/dist/esm/index.js.map +1 -1
- package/package.json +16 -7
package/Readme.md
CHANGED
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React Scroll Direction Hook
|
|
2
2
|
|
|
3
3
|
    
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Detect scroll direction in your React applications effortlessly using `@smakss/react-scroll-direction`, a custom React Hook with an adjustable threshold.
|
|
6
6
|
|
|
7
|
-
This package
|
|
7
|
+
This package was inspired by a [popular StackOverflow answer](https://stackoverflow.com/a/62497293/11908502), crafted to be a ready-to-use solution for detecting scroll direction in your React applications.
|
|
8
8
|
|
|
9
9
|
## Demo
|
|
10
10
|
|
|
11
|
+
Click the button below to view a demo on CodeSandbox:
|
|
12
|
+
|
|
11
13
|
[](https://codesandbox.io/s/react-scroll-direction-tclwvp?fontsize=14&hidenavigation=1&theme=dark)
|
|
12
14
|
|
|
13
|
-
##
|
|
15
|
+
## Installation
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
Install the package using npm or yarn:
|
|
16
18
|
|
|
17
19
|
```bash
|
|
18
|
-
npm
|
|
19
|
-
or
|
|
20
|
+
npm install @smakss/react-scroll-direction
|
|
21
|
+
# or
|
|
20
22
|
yarn add @smakss/react-scroll-direction
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
To include it in your project, use:
|
|
26
|
+
|
|
27
|
+
CommonJS:
|
|
24
28
|
|
|
25
29
|
```js
|
|
26
|
-
|
|
30
|
+
const { useDetectScroll } = require("@smakss/react-scroll-direction");
|
|
27
31
|
```
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
ES Module:
|
|
30
34
|
|
|
31
35
|
```js
|
|
32
36
|
import { useDetectScroll } from "@smakss/react-scroll-direction";
|
|
33
37
|
```
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
## Usage
|
|
36
40
|
|
|
37
|
-
The useDetectScroll custom hook
|
|
41
|
+
The `useDetectScroll` custom hook accepts an options object with the following properties:
|
|
38
42
|
|
|
39
|
-
- `thr
|
|
40
|
-
- `axis
|
|
41
|
-
- `scrollUp
|
|
42
|
-
- `scrollDown
|
|
43
|
-
- `still
|
|
43
|
+
- `thr`: Threshold to trigger scroll direction change (default: `0`, only accepts positive values).
|
|
44
|
+
- `axis`: Scroll axis (`"y"` or `"x"`, default: `"y"`).
|
|
45
|
+
- `scrollUp`: Output value when scrolling up or left (default: `"up"` for y-axis, `"left"` for x-axis).
|
|
46
|
+
- `scrollDown`: Output value when scrolling down or right (default: `"down"` for y-axis, `"right"` for x-axis).
|
|
47
|
+
- `still`: Output value when no scrolling is detected (default: `"still"`).
|
|
44
48
|
|
|
45
|
-
## Examples
|
|
49
|
+
## Examples
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
Detecting scroll up/down:
|
|
48
52
|
|
|
49
53
|
```js
|
|
50
|
-
const
|
|
54
|
+
const scrollDir = useDetectScroll({});
|
|
51
55
|
|
|
52
|
-
//
|
|
56
|
+
// Outputs: "up", "down", or "still"
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
Detecting scroll left/right:
|
|
56
60
|
|
|
57
61
|
```js
|
|
58
|
-
const
|
|
62
|
+
const scrollDir = useDetectScroll({ axis: "x" });
|
|
59
63
|
|
|
60
|
-
//
|
|
64
|
+
// Outputs: "left", "right", or "still"
|
|
61
65
|
```
|