@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 CHANGED
@@ -1,61 +1,65 @@
1
- # Detect react scroll direction
1
+ # React Scroll Direction Hook
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/@smakss/react-scroll-direction) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@smakss/react-scroll-direction) ![NPM](https://img.shields.io/npm/l/@smakss/react-scroll-direction) ![npm](https://img.shields.io/npm/dt/@smakss/react-scroll-direction) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@smakss/react-scroll-direction)
4
4
 
5
- This is a custom hook for react which is useful to detect scroll direction in React applications in an efficient way with a custom threshold.
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 is created on behalf of a [StackOverflow answer](https://stackoverflow.com/a/62497293/11908502) which draws some attention to itself, so if someone just wants something to work with right away, they can access it easily here.
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
  [![View @smakss/search](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-scroll-direction-tclwvp?fontsize=14&hidenavigation=1&theme=dark)
12
14
 
13
- ## How it works?
15
+ ## Installation
14
16
 
15
- To install it you can simply do the following command:
17
+ Install the package using npm or yarn:
16
18
 
17
19
  ```bash
18
- npm i @smakss/react-scroll-direction
19
- or
20
+ npm install @smakss/react-scroll-direction
21
+ # or
20
22
  yarn add @smakss/react-scroll-direction
21
23
  ```
22
24
 
23
- to include it with common js module you should do this:
25
+ To include it in your project, use:
26
+
27
+ CommonJS:
24
28
 
25
29
  ```js
26
- var { useDetectScroll } = require("@smakss/react-scroll-direction");
30
+ const { useDetectScroll } = require("@smakss/react-scroll-direction");
27
31
  ```
28
32
 
29
- and to include it with ECMAscript module you can simply do this one:
33
+ ES Module:
30
34
 
31
35
  ```js
32
36
  import { useDetectScroll } from "@smakss/react-scroll-direction";
33
37
  ```
34
38
 
35
- then to use it within your application you can do it just like below:
39
+ ## Usage
36
40
 
37
- The useDetectScroll custom hook will accept 3 input parameter:
41
+ The `useDetectScroll` custom hook accepts an options object with the following properties:
38
42
 
39
- - `thr` (`number`): A number to indicate the threshold of firing scroll direction event, which is `0` by default and only accepts a positive numeric value. If it gets a higher value the steps will be longer.
40
- - `axis` (`string`): Indicate the page scroll axis, whether, in the `y` or `x` axes, it is `y` by default.
41
- - `scrollUp` (`string`): A string value for the output of the custom hook if the scroll direction is upward. The default value is `up` if the axis is `y` and `left` if the axis is `x`.
42
- - `scrollDown` (`string`): A string value for the output of the custom hook if the scroll direction is downward. The default value is `down` if the axis is `y` and `right` if the axis is `x`.
43
- - `still` (`string`): default value for the direction when there is no scrolling happening on the page. The default value is `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 of usage
49
+ ## Examples
46
50
 
47
- ### If the scroll goes upward/downward
51
+ Detecting scroll up/down:
48
52
 
49
53
  ```js
50
- const [scrollDir] = useDetectScroll({});
54
+ const scrollDir = useDetectScroll({});
51
55
 
52
- // scrollDir: "up"/"down"
56
+ // Outputs: "up", "down", or "still"
53
57
  ```
54
58
 
55
- ### If the scroll goes left/right
59
+ Detecting scroll left/right:
56
60
 
57
61
  ```js
58
- const [scrollDir] = useDetectScroll({ axis: "x" });
62
+ const scrollDir = useDetectScroll({ axis: "x" });
59
63
 
60
- // scrollDir: "left"/"right"
64
+ // Outputs: "left", "right", or "still"
61
65
  ```