@smakss/react-scroll-direction 0.0.1
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/LICENSE +21 -0
- package/Readme.md +61 -0
- package/dist/cjs/index.js +2839 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +2837 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 MAKSS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Detect react scroll direction
|
|
2
|
+
|
|
3
|
+
    
|
|
4
|
+
|
|
5
|
+
This is a custom hook for react which is useful to detect scroll direction in react applications with a efficient way and custom threshold.
|
|
6
|
+
|
|
7
|
+
## How it works?
|
|
8
|
+
|
|
9
|
+
To install it you can simply do the following command:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @smakss/react-scroll-direction
|
|
13
|
+
or
|
|
14
|
+
yarn add @smakss/react-scroll-direction
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
to include it with common js module you should do this:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
var { useDetectScroll } = require("@smakss/react-scroll-direction");
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
and to include it with ECMAscript module you can simply do this one:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { useDetectScroll } from "@smakss/react-scroll-direction";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
then to use it within your application you can do it just like below:
|
|
30
|
+
|
|
31
|
+
The useDetectScroll custom hook will accept 3 input parameter:
|
|
32
|
+
|
|
33
|
+
- `thr` (`Number`): A number to indicate the threshold of firing scroll direction event, which is `0` by default and it is only accept a positive numeric value. If it gets higher value the steps will be longer.
|
|
34
|
+
- `up` (`string`): A string value for the output of custom hook if the scroll direction is upward. The default value is `up`.
|
|
35
|
+
- `down` (`string`): A string value for the output of custom hook if the scroll direction is downward. The default value is `down`.
|
|
36
|
+
|
|
37
|
+
## Examples of usage
|
|
38
|
+
|
|
39
|
+
if scroll goes upward:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const [scrollDir] = useDetectScroll();
|
|
43
|
+
|
|
44
|
+
// scrollDir: "up"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
if scroll goes downward:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const [scrollDir] = useDetectScroll();
|
|
51
|
+
|
|
52
|
+
// scrollDir: "down"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Demo
|
|
56
|
+
|
|
57
|
+
You can check the [working demo](https://runkit.com/smakss/) in runkit.
|
|
58
|
+
|
|
59
|
+
or
|
|
60
|
+
|
|
61
|
+
[]()
|