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
@@ -56,6 +57,40 @@ You only need to render this component on the top level of your app, it provides
56
57
</ScrollWatcher>
57
58
```
58
59
60
+
## useScrollWatcher Hook
61
+
62
+
This hooks creates an scroll context from a ref to a element that has overflow therefore can have an scroll behavior, that way you can pass that context to other hooks or components and use it as reference. This returns an object with the "position" of the scroll and the "element" we are using.
63
+
64
+
### Example
65
+
66
+
```js
67
+
68
+
functionExample () {
69
+
70
+
constscrollRef=useRef(null);
71
+
72
+
constcontext=useScrollWatcher(scrollRef);
73
+
74
+
//This div has an scroll because its content is bigger than it
75
+
return
76
+
<div
77
+
style={{
78
+
height:"60vh",
79
+
overflow:"scroll",
80
+
}}
81
+
ref={scrollRef}
82
+
>
83
+
<div
84
+
style={{
85
+
height:"4000px",
86
+
}}
87
+
></div>
88
+
</div>
89
+
}
90
+
```
91
+
92
+
For further instructions of how to use the hook in other hooks/components, for all hooks/components that accepts [Linear Values Options](#linear-values-options) it has a dedicated property, the other ones have an optional parameter called context.
93
+
59
94
## useProximity hook
60
95
61
96
This hook lets you know how far is the screen from the component, it returns an object with 3 properties: "x", "y" and "onSight". "x" and "y", represents the proximity of the component from the center of the screen, it works as a Cartesian Plane, where up and right are positive values for "y" and "x", and down and left are negative values for "y" and "x", the values goes from -innerHeight/2 to +innerHeight/2 or -height/2 to +height/2 in case that the component is bigger than the viewport, that is for "y" value, for "x" is the same but using the width of the viewport or the width of the component. onSight is a boolean that tells you if the component is inside the viewport or not.
@@ -64,7 +99,7 @@ So if your component is 2000h x 1000w it will go from -1000 to 1000 for Y axis,
64
99
65
100
### Usage
66
101
67
-
This hook only take one argument that should be a ref to an HTML Element. This hook won't work if ScrollWatcher is not implemented.
102
+
This hook only take two arguments, one that should be a ref to an HTML Element and the other one an scroll context created with [useScrollWatcher Hook](#usescrollwatcher-component). If you don't pass a context, you will have to implement [ScrollWatcher Component](#scrollwatcher-component).
68
103
69
104
#### Example
70
105
@@ -243,7 +278,7 @@ This hooks returns the current direction of the scroll. It returns an string tha
243
278
244
279
### Usage
245
280
246
-
The only requirement in order to use it, is to make the right implementation of ScrollWatcher. It doesn't take any arguments at the time. You can use this hook in combination of useProximity to make different animations using the direction of the scroll as reference. You can go to src/test-components/BackgroundChange.tsx to see and example of a background that reacts to the scroll and direction.
281
+
The only requirement in order to use it, is to make the right implementation of ScrollWatcher or pass an scroll context created with [useScrollWatcher Hook](#usescrollwatcher-component).
247
282
248
283
### Example
249
284
@@ -289,7 +324,7 @@ This lib provides an enum for TypeScript users, it just has four properties at t
289
324
290
325
## Linear Values Options
291
326
292
-
This options let you modify the behavior of the animations, is an object that useDynamicColor and useLinearValues use in their "options" property, it has 3 properties:"anchor", "delay"and "duration".
327
+
This options let you modify the behavior of the animations, is an object that useDynamicColor and useLinearValues use in their "options" property, it has 4 properties: "anchor", "delay", "duration" and "context".
293
328
294
329
### Anchor property
295
330
@@ -326,8 +361,14 @@ So, let's say we are using a component of 1000px, middle as anchor and we set du
326
361
327
362
The animation won't start until the center of the screen (middle anchor) is at the center of the component (500px). So the total distance from delay to the end of the component is 500px. We also setted a duration at half, so the animation should last as half of the total distance, at 250px of the end of the component the animation will finish.
328
363
364
+
### Context Property
365
+
366
+
This property accepts a context created with [useScrollWatcher Hook](#usescrollwatcher-component), this is the context the hook/component will use as reference
367
+
329
368
### Options Recommendations
330
369
370
+
Both Circle and Rectangle accepts this options.
371
+
331
372
If you struggle trying to understand that. I mean it could be hard to understand with all those numbers and calculations.
332
373
333
374
I recommend to experiment with those values. Just go and mess around with it, maybe you'll understand it better if you see how it behaves.
@@ -339,8 +380,8 @@ I recommend to experiment with those values. Just go and mess around with it, ma
339
380
//This is how this object looks. All values are optional. You can skip everyone of them
340
381
const options = {
341
382
anchor: "middle", // This is skippable because anchor is middle by default
342
-
delay: 30,
343
-
duration: 75,
383
+
delay: 30, //Animation won't trigger until the 30% of the height
384
+
duration: 75, //Animation will last the 75% of the height its left after the 30% of delay
344
385
};
345
386
346
387
//So now you just need to set it at the hooks
@@ -387,6 +428,8 @@ Just be sure that ScrollWatcher is at the top level of your app, any other way t
387
428
| rotate | Initial state of the line in degrees, you can set the start of the line at 90° instead of0°. This won't draw the circle, it will move the starting position of the line | number | 0 | 78, 90, 100, 80, 170, 45, 21.3, 56... | if you pass something else that's not a number, it won't work since it's not a valid degree (at the time). |
388
429
389
430
431
+
432
+
390
433
## Example
391
434
392
435
This will render a circle that has a radius of400 pixels and a line width of4 pixels.
@@ -437,6 +480,8 @@ This will render a rectangle that has a height of 400px, a width of 100px and a
437
480
438
481
## Circle/Rectangle Recommendations
439
482
483
+
Both Circle and Rectangle accepts [Linear Values Options](#linear-values-options) in options prop.
484
+
440
485
To make responsive the components, I recommend to use rem or em values, so that way you can modify the font-size of the root or parent component using media queries and therefore modify the sizes of the components.
441
486
442
487
For more information of how rem and em values work. [Just click here](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) and go to the section of relative length units.
0 commit comments