@stianlarsen/react-light-beam 1.0.5 → 1.0.7

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
@@ -50,15 +50,16 @@ export default App;
50
50
 
51
51
  ### Props
52
52
 
53
- | Prop Name | Type | Default Value | Description |
54
- | --------------------- | --------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
- | `id` | `string` | `undefined` | Optional string representing a unique ID for the LightBeam container. |
56
- | `className` | `string` | `undefined` | Optional string representing custom classes to be added to the LightBeam container. |
57
- | `colorLightmode` | `string` | `rgba(0,0,0, 0.5)` | Optional string representing the color of the light beam in light mode. |
58
- | `colorDarkmode` | `string` | `rgba(255, 255, 255, 0.5)` | Optional string representing the color of the light beam in dark mode. |
59
- | `fullWidth` | `number` | `1.0` | Optional number between `0` and `1` representing the maximum width the light beam can reach. |
60
- | `maskLightByProgress` | `boolean` | `false` | If `true`, the `mask-image`'s linear gradient will start with the chosen color at 0% and the transparent part starting at 50%. As the user scrolls, it will dynamically change to have the transparent part at 95%, reducing the glow effect. If `false`, it will default to `linear-gradient(to bottom, chosenColor 25%, transparent 95%)`. |
61
- | `invert` | `boolean` | `false` | Optional boolean to invert the scroll progress calculation. |
53
+ | Prop Name | Type | Default Value | Description |
54
+ | --------------------- | ------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
+ | `id` | `string` | `undefined` | Optional string representing a unique ID for the LightBeam container. |
56
+ | `className` | `string` | `undefined` | Optional string representing custom classes to be added to the LightBeam container. |
57
+ | `colorLightmode` | `string` | `rgba(0,0,0, 0.5)` | Optional string representing the color of the light beam in light mode. |
58
+ | `colorDarkmode` | `string` | `rgba(255, 255, 255, 0.5)` | Optional string representing the color of the light beam in dark mode. |
59
+ | `fullWidth` | `number` | `1.0` | Optional number between `0` and `1` representing the maximum width the light beam can reach. |
60
+ | `maskLightByProgress` | `boolean` | `false` | If `true`, the `mask-image`'s linear gradient will start with the chosen color at 0% and the transparent part starting at 50%. As the user scrolls, it will dynamically change to have the transparent part at 95%, reducing the glow effect. If `false`, it will default to `linear-gradient(to bottom, chosenColor 25%, transparent 95%)`. |
61
+ | `invert` | `boolean` | `false` | Optional boolean to invert the scroll progress calculation. |
62
+ | `onLoaded` | `undefined or () => void` | `undefined` | Optional function to run when the component has mounted |
62
63
 
63
64
  ### Default Configuration
64
65
 
@@ -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.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { LightBeamProps } from "../types/types";
3
- export declare const LightBeam: ({ className, colorLightmode, colorDarkmode, maskLightByProgress, fullWidth, invert, id, }: LightBeamProps) => React.JSX.Element;
3
+ export declare const LightBeam: ({ className, colorLightmode, colorDarkmode, maskLightByProgress, fullWidth, invert, id, onLoaded, }: LightBeamProps) => React.JSX.Element;
package/dist/index.js CHANGED
@@ -33,41 +33,48 @@ const react_1 = __importStar(require("react"));
33
33
  const lightBeam_module_css_1 = __importDefault(require("./css/lightBeam.module.css"));
34
34
  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
- invert = false, id = undefined, }) => {
36
+ invert = false, id = undefined, onLoaded = 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
+ onLoaded && onLoaded();
47
+ }, []);
48
+ (0, react_1.useEffect)(() => {
49
+ if (bodyElement) {
50
+ const handleScroll = () => {
51
+ if (elementRef.current) {
52
+ const rect = elementRef.current.getBoundingClientRect();
53
+ const windowHeight = window.innerHeight;
54
+ // Invert the fullWidth value: 1 becomes 0, and 0 becomes 1
55
+ const adjustedFullWidth = 1 - fullWidth;
56
+ // Calculate progress
57
+ const progress = invert
58
+ ? 0 +
59
+ Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight))
60
+ : 1 -
61
+ Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight));
62
+ // Update motion values
63
+ inViewProgress.set(progress);
64
+ opacity.set(0.839322 + (1 - 0.839322) * progress);
65
+ }
66
+ };
67
+ // Attach scroll and resize event listeners
68
+ bodyElement.addEventListener("scroll", handleScroll);
69
+ window.addEventListener("resize", handleScroll);
70
+ // Initial call to handleScroll to set initial state
71
+ handleScroll();
72
+ return () => {
73
+ bodyElement.removeEventListener("scroll", handleScroll);
74
+ window.removeEventListener("resize", handleScroll);
75
+ };
76
+ }
77
+ }, [bodyElement, inViewProgress, opacity]);
71
78
  const backgroundPosition = (0, framer_motion_1.useTransform)(inViewProgress, [0, 1], [
72
79
  `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
80
  `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.5",
3
+ "version": "1.0.7",
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",
package/types/types.d.ts CHANGED
@@ -6,4 +6,5 @@ export type LightBeamProps = {
6
6
  maskLightByProgress?: boolean;
7
7
  invert?: boolean;
8
8
  id?: string;
9
+ onLoaded?: () => void;
9
10
  };