@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 +10 -9
- package/dist/css/lightBeam.module.css +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -29
- package/package.json +1 -1
- package/types/types.d.ts +1 -0
package/README.md
CHANGED
|
@@ -50,15 +50,16 @@ export default App;
|
|
|
50
50
|
|
|
51
51
|
### Props
|
|
52
52
|
|
|
53
|
-
| Prop Name | Type
|
|
54
|
-
| --------------------- |
|
|
55
|
-
| `id` | `string`
|
|
56
|
-
| `className` | `string`
|
|
57
|
-
| `colorLightmode` | `string`
|
|
58
|
-
| `colorDarkmode` | `string`
|
|
59
|
-
| `fullWidth` | `number`
|
|
60
|
-
| `maskLightByProgress` | `boolean`
|
|
61
|
-
| `invert` | `boolean`
|
|
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
|
|
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
|
|
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
|
-
: 1
|
|
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
|
+
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.
|
|
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",
|