Skip to content

Commit 2d23996

Browse files
authored
Merge pull request #42 from zJaaal/dev
Dev
2 parents aa7dcee + 97e7a63 commit 2d23996

File tree

12 files changed

+49
-66
lines changed

12 files changed

+49
-66
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ React Scroll Utilities is a Lightweight library to track scroll events like, pro
1717
5. [useLinearValue Hook](#uselinearvalue-hook)
1818
6. [useDirection Hook](#usedirection-hook)
1919
7. [Linear Values Options](#linear-values-options)
20-
8. [Circle Component](#circle-component)
21-
9. [Rectangle Component](#rectangle-component)
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)
2224

2325

2426
## Installation
@@ -212,11 +214,6 @@ const SpinningSquare = () => {
212214
startValue: 0,
213215
endValue: 360,
214216
elementRef: ref,
215-
options: {
216-
//In this case lets say that we are going to use the SpinningSquare in a footer, so we use anchor: "bottom"
217-
//Anyways, I recommend to test each of the possible anchor values to see how it behaves.
218-
anchor: "bottom",
219-
},
220217
};
221218

222219
//Just an example of using an external object
@@ -329,7 +326,7 @@ So, let's say we are using a component of 1000px, middle as anchor and we set du
329326
330327
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.
331328

332-
### Recommendations
329+
### Options Recommendations
333330

334331
If you struggle trying to understand that. I mean it could be hard to understand with all those numbers and calculations.
335332

@@ -354,7 +351,7 @@ I recommend to experiment with those values. Just go and mess around with it, ma
354351
options, // You can pass it like this because it has the same name as the property
355352
});
356353
357-
//It's call height because I'm using this hook to change the height of a component on scroll
354+
//It's called height because I'm using this hook to change the height of a component on scroll
358355
//In this case, the height will vary from 10 to 100
359356
const height = useLinearValue({
360357
startValue: 10,
@@ -438,7 +435,7 @@ This will render a rectangle that has a height of 400px, a width of 100px and a
438435
```
439436
440437
441-
## Recomendations
438+
## Circle/Rectangle Recommendations
442439
443440
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.
444441

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "react-scroll-utilities",
33
"private": false,
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"license": "MIT",
66
"type": "module",
77
"main": "src/lib/index.ts",
8-
"homepage": "https://github.com/zJaaal/react-scroll-utilities#readme",
8+
"homepage": "https://react-scroll-utilities.netlify.app",
99
"keywords": [
1010
"scroll",
1111
"react-components",

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import LinearValue from "./site/components/linearValue/LinearValue";
66
import Proximity from "./site/components/proximity/Proximity";
77

88
function App() {
9+
console.log("Welcome to React Scroll Utilities v1.1.2");
910
return (
1011
<div style={{ height: "100%" }}>
1112
<Header />

src/__test__/functions/getLinearValueFromOptions.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import getLinearValueFromOptions from "../../lib/utils/calculations/linear/getLinearValueFromOptions";
22
import { describe, it, expect } from "vitest";
33
import getValueFromPercentage from "../../lib/utils/calculations/misc/getValueFromPercentage";
4+
import { LinearValueOptions } from "../../lib/types";
45
const start = 0;
56
const end = 500;
67
const delay = 50;
78
const duration = 50;
89
const height = 1000;
9-
const defaultOptions = {
10+
const defaultOptions: LinearValueOptions = {
1011
delay: 0,
1112
duration: 100,
12-
anchor: "middle" as "middle",
13+
anchor: "middle",
1314
};
1415

1516
describe("getLinearValueFromOptions function", () => {

src/lib/components/rectangle/Rectangle.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import React, {
2-
CSSProperties,
3-
FC,
4-
useEffect,
5-
useLayoutEffect,
6-
useRef,
7-
} from "react";
1+
import React, { CSSProperties, FC, useEffect, useRef } from "react";
82
import { useLinearValue } from "../../index";
93
import { validateRectangleProps } from "../../utils/validations/components/validateRectangleProps";
104
import { RectangleProps } from "./types";

src/lib/hooks/useDirection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
1+
import React, { useContext, useEffect, useMemo, useRef } from "react";
22
import ScrollContext from "../context/ScrollContext";
33
import { Coors, Directions } from "../types";
4-
import fixScroll from "../utils/calculations/proximity/fixScroll";
54
import validateScrollValue from "../utils/validations/hooks/validateScrollValue";
65

76
/**

src/lib/hooks/useDynamicColor.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { useRef, useLayoutEffect } from "react";
2-
import { DynamicColor, Directions, LinearValueOptions } from "../types";
3-
import clamp from "../utils/calculations/misc/clamp";
2+
import { DynamicColor, defaultOptions } from "../types";
43
import getCurrentColor from "../utils/calculations/color/getCurrentColor";
54
import validateColors from "../utils/validations/hooks/validateColors";
6-
import useDirection from "./useDirection";
75
import useProximity from "./useProximity";
86

9-
const defautlOptions: LinearValueOptions = {
10-
anchor: "middle",
11-
delay: 0,
12-
duration: 100,
13-
};
14-
157
/**
168
* @description This custom hook takes an object with four properties: startColor, endColor, elementRef and options.
179
*
@@ -29,7 +21,7 @@ const useDynamicColor = ({
2921
elementRef,
3022
options,
3123
}: DynamicColor) => {
32-
const mixedOptions = { ...defautlOptions, ...options };
24+
const mixedOptions = { ...defaultOptions, ...options };
3325
const color = useRef<number[]>([...startColor]);
3426
const height = useRef<number>();
3527

src/lib/hooks/useLinearValue.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import React, { useLayoutEffect, useRef } from "react";
2-
import { LinearValueOptions, LinearValueProps } from "../types";
3-
import clamp from "../utils/calculations/misc/clamp";
4-
import getLinearValue from "../utils/calculations/linear/getLinearValue";
5-
import { LinearValue, OptionsParams } from "../utils/calculations/types";
2+
import { LinearValueProps, defaultOptions } from "../types";
3+
import { OptionsParams } from "../utils/calculations/types";
64
import validateLinearValues from "../utils/validations/hooks/validateLinearValues";
75
import useProximity from "./useProximity";
8-
import getValueFromPercentage from "../utils/calculations/misc/getValueFromPercentage";
96
import getLinearValueFromOptions from "../utils/calculations/linear/getLinearValueFromOptions";
107

11-
const defaultOptions: LinearValueOptions = {
12-
anchor: "middle",
13-
duration: 100,
14-
delay: 0,
15-
};
16-
178
/**
189
* @description This custom hook takes an object with four properties: startValue, endValue, elementRef and options.
1910
*
@@ -53,7 +44,7 @@ const useLinearValue = ({
5344
value.current = getLinearValueFromOptions(optionsParams);
5445
}
5546
}, [y]);
56-
return clamp(startValue, endValue, value.current);
47+
return value.current;
5748
};
5849

5950
export default useLinearValue;

src/lib/hooks/useProximity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { RefObject, useContext, useLayoutEffect, useRef } from "react";
22
import ScrollContext from "../context/ScrollContext";
3-
import { Coors, ProximityState } from "../types";
3+
import { ProximityState } from "../types";
44
import getProximity from "../utils/calculations/proximity/getProximity";
55
import validateRef from "../utils/validations/hooks/validateRef";
66
import validateScrollValue from "../utils/validations/hooks/validateScrollValue";

0 commit comments

Comments
 (0)