@stianlarsen/react-light-beam 1.0.4 → 1.0.6
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 +0 -2
- package/dist/css/lightBeam.module.css +4 -0
- package/dist/index.js +34 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40stianlarsen%2Freact-light-beam)
|
|
4
4
|
|
|
5
|
-

|
|
6
|
-
|
|
7
5
|
A customizable React component that creates a light beam effect using conic gradients. The component is fully responsive and supports both light and dark modes. Ideal for adding dynamic and engaging visual elements to your web applications.
|
|
8
6
|
|
|
9
7
|
## Preview
|
package/dist/index.js
CHANGED
|
@@ -35,39 +35,45 @@ const useDarkmode_1 = require("./hooks/useDarkmode");
|
|
|
35
35
|
const LightBeam = ({ className, colorLightmode = "rgba(0,0,0, 0.5)", colorDarkmode = "rgba(255, 255, 255, 0.5)", maskLightByProgress = false, fullWidth = 1.0, // Default to full width
|
|
36
36
|
invert = false, id = undefined, }) => {
|
|
37
37
|
const elementRef = (0, react_1.useRef)(null);
|
|
38
|
-
const
|
|
38
|
+
const [bodyElement, setBodyElement] = (0, react_1.useState)(null); // State to hold the body element
|
|
39
39
|
const inViewProgress = (0, framer_motion_1.useMotionValue)(0);
|
|
40
40
|
const opacity = (0, framer_motion_1.useMotionValue)(0.839322);
|
|
41
41
|
const { isDarkmode } = (0, useDarkmode_1.useIsDarkmode)();
|
|
42
42
|
const chosenColor = isDarkmode ? colorDarkmode : colorLightmode;
|
|
43
43
|
(0, react_1.useEffect)(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
44
|
+
// Set the body element after the component mounts
|
|
45
|
+
setBodyElement(document.body);
|
|
46
|
+
}, []);
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
if (bodyElement) {
|
|
49
|
+
const handleScroll = () => {
|
|
50
|
+
if (elementRef.current) {
|
|
51
|
+
const rect = elementRef.current.getBoundingClientRect();
|
|
52
|
+
const windowHeight = window.innerHeight;
|
|
53
|
+
// Invert the fullWidth value: 1 becomes 0, and 0 becomes 1
|
|
54
|
+
const adjustedFullWidth = 1 - fullWidth;
|
|
55
|
+
// Calculate progress
|
|
56
|
+
const progress = invert
|
|
57
|
+
? 0 +
|
|
58
|
+
Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight))
|
|
59
|
+
: 1 -
|
|
60
|
+
Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight));
|
|
61
|
+
// Update motion values
|
|
62
|
+
inViewProgress.set(progress);
|
|
63
|
+
opacity.set(0.839322 + (1 - 0.839322) * progress);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Attach scroll and resize event listeners
|
|
67
|
+
bodyElement.addEventListener("scroll", handleScroll);
|
|
68
|
+
window.addEventListener("resize", handleScroll);
|
|
69
|
+
// Initial call to handleScroll to set initial state
|
|
70
|
+
handleScroll();
|
|
71
|
+
return () => {
|
|
72
|
+
bodyElement.removeEventListener("scroll", handleScroll);
|
|
73
|
+
window.removeEventListener("resize", handleScroll);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}, [bodyElement, inViewProgress, opacity]);
|
|
71
77
|
const backgroundPosition = (0, framer_motion_1.useTransform)(inViewProgress, [0, 1], [
|
|
72
78
|
`conic-gradient(from 90deg at 90% 0%, ${chosenColor}, transparent 180deg) 0% 0% / 50% 150% no-repeat, conic-gradient(from 270deg at 10% 0%, transparent 180deg, ${chosenColor}) 100% 0% / 50% 100% no-repeat`,
|
|
73
79
|
`conic-gradient(from 90deg at 0% 0%, ${chosenColor}, transparent 180deg) 0% 0% / 50% 100% no-repeat, conic-gradient(from 270deg at 100% 0%, transparent 180deg, ${chosenColor}) 100% 0% / 50% 100% no-repeat`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stianlarsen/react-light-beam",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A customizable React component that creates a light beam effect using conic gradients. Supports dark mode and various customization options.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|