You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-10Lines changed: 30 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# React Scroll Utilities (Beta)
2
2
3
-
React Scroll Utilities is a Lightweight library to track scroll events like, proximity to components, direction of scroll and render a component if it's on screen sight. I'll be adding more features and improving the functionality. I'm also open to read any request or change that you think that would be a good addition. This library only supports vertical scroll at the moment.
3
+
React Scroll Utilities is a Lightweight library to track scroll events like, proximity to components, direction of scroll and render a component if it's on screen sight. I'll be adding more features and improving the functionality. I'm also open to read any request or change that you think that would be a good addition.
4
4
5
5
## ScrollWatcher Component
6
6
@@ -26,7 +26,7 @@ You only need to render this component on the top level of your app, it provides
26
26
27
27
## useProximity hook
28
28
29
-
This hook lets you know how far is the screen from the component, it returns negative and positive values, where 0 is the top limit of the screen (when you scroll down your component ( out of sight ), proximity will be on negatives values) and 2 is the bottom limit of the screen (when you scroll up your component ( out of sight ), proximity will be more than 2), so your component is on screen if the proximity value is between 0 and 2, were 1 is approximately the center of the screen.
29
+
This hook lets you know how far is the screen from the component, it returns an object with two properties: x and y. Which values represents the proximity the component has to the center of the current viewport as a float value. For Y the acceptable value where the component is on sigth is between 0 and 2. For X the acceptable value where the component is on sigth is between 0 and 3.
30
30
31
31
### Usage
32
32
@@ -37,26 +37,38 @@ This hook only take one argument that should be a ref to an HTML Element. This h
37
37
```js
38
38
//TypeScript
39
39
functionExample() {
40
-
constref= useRef <HTMLDivElement>null;
40
+
constref= useRef <HTMLDivElement>(null);
41
41
42
-
constproximity=useProximity(ref);
42
+
//I'm destructuring the object but you can easily use it without destructuring
This component implements the useProximity hook, and will only render your component if proximity is on an acceptable value (between 0 and 2). So you can use it to add animations to your components on render, like an entry transition.
71
+
This component implements the useProximity hook, and will only render your component if proximity is on an acceptable value (between 0 and 2 for Y and between 0 and 3 for X). So you can use it to add animations to your components on render, like an entry transition.
60
72
61
73
### Usage
62
74
@@ -82,7 +94,7 @@ This component needs a React Children to work, it also accepts custom styles, th
82
94
83
95
## useDirection hook
84
96
85
-
This hooks returns the current direction of the scroll. It returns an string that can be "UP"or "DOWN", its default value is "DOWN".
97
+
This hooks returns the current direction of the scroll. It returns an string that can be "UP", "DOWN", "RIGHT" or "LEFT", its default value is "DOWN".
86
98
87
99
### Usage
88
100
@@ -104,6 +116,14 @@ function Example() {
104
116
//Do something else
105
117
break;
106
118
}
119
+
case"RIGHT": {
120
+
// Do something
121
+
break;
122
+
}
123
+
case"LEFT": {
124
+
//Do something else
125
+
break;
126
+
}
107
127
}
108
128
}, [direction]);
109
129
@@ -119,4 +139,4 @@ function Example() {
119
139
120
140
## Directions enum
121
141
122
-
This lib provides an enum for TypeScript users, it just has two properties at the moment: Directions.up and Directions.down, that returns the value of "UP"and "DOWN", you can use it as helper for useDirection hook.
142
+
This lib provides an enum for TypeScript users, it just has two properties at the moment: Directions.up, Directions.down, Directions.right and Directions.left that returns the value of "UP", "DOWN" "RIGHT" and "LEFT", you can use it as helper for useDirection hook.
0 commit comments