@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 CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40stianlarsen%2Freact-light-beam.svg)](https://badge.fury.io/js/%40stianlarsen%2Freact-light-beam)
4
4
 
5
- ![Preview / example image](https://github.com/Stianlars1/react-light-beam/blob/5422cdc60ae7ab6b52d644d452646bec7212f76f/lightBeam.png)
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
@@ -3,4 +3,8 @@
3
3
  width: 100vw;
4
4
  transition: all 0.5s ease;
5
5
  will-change: auto;
6
+ -webkit-user-select: none;
7
+ -moz-user-select: none;
8
+ user-select: none;
9
+ pointer-events: none;
6
10
  }/*# sourceMappingURL=lightBeam.module.css.map */
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 bodyRef = (0, react_1.useRef)(document.body);
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
- const handleScroll = () => {
45
- if (elementRef.current) {
46
- const rect = elementRef.current.getBoundingClientRect();
47
- const windowHeight = window.innerHeight;
48
- // Invert the fullWidth value: 1 becomes 0, and 0 becomes 1
49
- const adjustedFullWidth = 1 - fullWidth;
50
- // Calculate progress
51
- const progress = invert
52
- ? 0 +
53
- Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight))
54
- : 1 -
55
- Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight));
56
- // Update motion values
57
- inViewProgress.set(progress);
58
- opacity.set(0.839322 + (1 - 0.839322) * progress);
59
- }
60
- };
61
- // Attach scroll and resize event listeners
62
- bodyRef.current.addEventListener("scroll", handleScroll);
63
- bodyRef.current.addEventListener("resize", handleScroll);
64
- // Initial call to handleScroll to set initial state
65
- handleScroll();
66
- return () => {
67
- bodyRef.current.removeEventListener("scroll", handleScroll);
68
- bodyRef.current.removeEventListener("resize", handleScroll);
69
- };
70
- }, [inViewProgress, opacity]);
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.4",
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",