Skip to content

Commit c4aa76d

Browse files
authored
Merge pull request #48 from zJaaal/dev
Dev
2 parents 2d23996 + 599828d commit c4aa76d

34 files changed

+604
-394
lines changed

README.md

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ React Scroll Utilities is a Lightweight library to track scroll events like, pro
1212

1313
1. [Installation](#installation)
1414
2. [ScrollWatcher Component](#scrollwatcher-component)
15-
3. [useProximity Hook](#useproximity-hook)
16-
4. [useDynamicColor Hook](#usedynamiccolor-hook)
17-
5. [useLinearValue Hook](#uselinearvalue-hook)
18-
6. [useDirection Hook](#usedirection-hook)
19-
7. [Linear Values Options](#linear-values-options)
20-
8. [Options Recommendations](#options-recommendations)
21-
9. [Circle Component](#circle-component)
22-
10. [Rectangle Component](#rectangle-component)
23-
11. [Circle/Rectangle Recommendations](#circlerectangle-recommendations)
15+
3. [useScrollWatcher Hook](#usescrollwatcher-component)
16+
4. [useProximity Hook](#useproximity-hook)
17+
5. [useDynamicColor Hook](#usedynamiccolor-hook)
18+
6. [useLinearValue Hook](#uselinearvalue-hook)
19+
7. [useDirection Hook](#usedirection-hook)
20+
8. [Linear Values Options](#linear-values-options)
21+
9. [Options Recommendations](#options-recommendations)
22+
10. [Circle Component](#circle-component)
23+
11. [Rectangle Component](#rectangle-component)
24+
12. [Circle/Rectangle Recommendations](#circlerectangle-recommendations)
2425

2526

2627
## Installation
@@ -56,6 +57,40 @@ You only need to render this component on the top level of your app, it provides
5657
</ScrollWatcher>
5758
```
5859

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+
function Example () {
69+
70+
const scrollRef = useRef(null);
71+
72+
const context = 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+
5994
## useProximity hook
6095

6196
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,
6499

65100
### Usage
66101

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).
68103

69104
#### Example
70105

@@ -243,7 +278,7 @@ This hooks returns the current direction of the scroll. It returns an string tha
243278
244279
### Usage
245280
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).
247282
248283
### Example
249284
@@ -289,7 +324,7 @@ This lib provides an enum for TypeScript users, it just has four properties at t
289324
290325
## Linear Values Options
291326
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".
293328
294329
### Anchor property
295330
@@ -326,8 +361,14 @@ So, let's say we are using a component of 1000px, middle as anchor and we set du
326361

327362
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.
328363
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+
329368
### Options Recommendations
330369
370+
Both Circle and Rectangle accepts this options.
371+
331372
If you struggle trying to understand that. I mean it could be hard to understand with all those numbers and calculations.
332373
333374
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
339380
//This is how this object looks. All values are optional. You can skip everyone of them
340381
const options = {
341382
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
344385
};
345386
346387
//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
387428
| rotate | Initial state of the line in degrees, you can set the start of the line at 90° instead of 0°. 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). |
388429

389430

431+
432+
390433
## Example
391434

392435
This will render a circle that has a radius of 400 pixels and a line width of 4 pixels.
@@ -437,6 +480,8 @@ This will render a rectangle that has a height of 400px, a width of 100px and a
437480

438481
## Circle/Rectangle Recommendations
439482

483+
Both Circle and Rectangle accepts [Linear Values Options](#linear-values-options) in options prop.
484+
440485
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.
441486

442487
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.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
href="https://fonts.googleapis.com/css2?family=Sono:wght@400;500;700&display=swap"
1010
rel="stylesheet"
1111
/>
12+
<link rel="icon" type="image/x-icon" href="/react.svg" />
1213
<title>React Scroll Utilities</title>
1314
</head>
1415
<body>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-scroll-utilities",
33
"private": false,
4-
"version": "1.1.2",
4+
"version": "1.2.0",
55
"license": "MIT",
66
"type": "module",
77
"main": "src/lib/index.ts",

public/react.svg

Lines changed: 16 additions & 0 deletions
Loading

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import Footer from "./site/components/footer/Footer";
44
import Header from "./site/components/header/Header";
55
import LinearValue from "./site/components/linearValue/LinearValue";
66
import Proximity from "./site/components/proximity/Proximity";
7+
import packageJson from "../package.json";
78

89
function App() {
9-
console.log("Welcome to React Scroll Utilities v1.1.2");
10+
console.log(`Welcome to React Scroll Utilities ${packageJson.version}`);
1011
return (
1112
<div style={{ height: "100%" }}>
1213
<Header />

0 commit comments

Comments
 (0)