@stianlarsen/react-light-beam 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stian Larsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @stianlarsen/react-light-beam
2
+
3
+ [![npm version](https://badge.fury.io/js/%40stianlarsen%2Freact-light-beam.svg)](https://badge.fury.io/js/%40stianlarsen%2Freact-light-beam)
4
+
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.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @stianlarsen/react-light-beam
11
+ ```
12
+
13
+ or
14
+
15
+ ```bash
16
+ yarn add @stianlarsen/react-light-beam
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```jsx
22
+ import LightBeam from "@stianlarsen/react-light-beam";
23
+ import "your-css-file.css"; // Include the necessary styles
24
+
25
+ const App = () => {
26
+ return (
27
+ <div className="your-container-class">
28
+ <LightBeam
29
+ className="your-lightbeam-class"
30
+ colorDarkmode="hsl(var(--primary) / 1)"
31
+ colorLightmode="hsl(var(--foreground) / 0.2)"
32
+ fullWidth={0.8}
33
+ />
34
+ <YourContentHere />
35
+ </div>
36
+ );
37
+ };
38
+
39
+ export default App;
40
+ ```
41
+
42
+ ### Props
43
+
44
+ | Prop Name | Type | Default Value | Description |
45
+ | ---------------- | -------- | -------------------------- | -------------------------------------------------------------------------------------------- |
46
+ | `className` | `string` | `undefined` | Optional string representing custom classes to be added to the LightBeam container. |
47
+ | `colorLightmode` | `string` | `rgba(0,0,0, 0.5)` | Optional string representing the color of the light beam in light mode. |
48
+ | `colorDarkmode` | `string` | `rgba(255, 255, 255, 0.5)` | Optional string representing the color of the light beam in dark mode. |
49
+ | `fullWidth` | `number` | `1.0` | Optional number between `0` and `1` representing the maximum width the light beam can reach. |
50
+
51
+ ### Customization
52
+
53
+ You can customize the appearance and behavior of the light beam by adjusting the props or by applying additional styles via the `className` prop.
54
+
55
+ ### Dark Mode Support
56
+
57
+ The component automatically adjusts between light and dark modes based on the user's system preferences. You can pass different colors for light and dark modes using the `colorLightmode` and `colorDarkmode` props.
58
+
59
+ ### Example
60
+
61
+ ```jsx
62
+ <LightBeam
63
+ className="custom-lightbeam"
64
+ colorDarkmode="hsl(210, 22%, 18%)"
65
+ colorLightmode="hsl(0, 0%, 98%)"
66
+ fullWidth={0.5}
67
+ />
68
+ ```
69
+
70
+ ### License
71
+
72
+ MIT © [Stian Larsen](https://github.com/stianlarsen)
@@ -0,0 +1,3 @@
1
+ export declare const useIsDarkmode: () => {
2
+ isDarkmode: boolean;
3
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useIsDarkmode = void 0;
5
+ const react_1 = require("react");
6
+ const useIsDarkmode = () => {
7
+ const [isDarkmode, setIsDarkmodeActive] = (0, react_1.useState)(false);
8
+ (0, react_1.useEffect)(() => {
9
+ const matchMedia = window.matchMedia("(prefers-color-scheme: dark)");
10
+ const handleChange = () => {
11
+ setIsDarkmodeActive(matchMedia.matches);
12
+ };
13
+ // Set the initial value
14
+ setIsDarkmodeActive(matchMedia.matches);
15
+ // Listen for changes
16
+ matchMedia.addEventListener("change", handleChange);
17
+ // Cleanup listener on unmount
18
+ return () => {
19
+ matchMedia.removeEventListener("change", handleChange);
20
+ };
21
+ }, []);
22
+ return { isDarkmode };
23
+ };
24
+ exports.useIsDarkmode = useIsDarkmode;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { LightBeamProps } from "../types/types";
3
+ export declare const LightBeam: ({ className, colorLightmode, colorDarkmode, fullWidth, }: LightBeamProps) => React.JSX.Element;
4
+ export default LightBeam;
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ "use client";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.LightBeam = void 0;
28
+ const framer_motion_1 = require("framer-motion");
29
+ const react_1 = __importStar(require("react"));
30
+ const useDarkmode_1 = require("./hooks/useDarkmode");
31
+ const LightBeam = ({ className, colorLightmode = "rgba(0,0,0, 0.5)", colorDarkmode = "rgba(255, 255, 255, 0.5)", fullWidth = 1.0, // Default to full width
32
+ }) => {
33
+ const elementRef = (0, react_1.useRef)(null);
34
+ const bodyRef = (0, react_1.useRef)(document.body);
35
+ const inViewProgress = (0, framer_motion_1.useMotionValue)(0);
36
+ const opacity = (0, framer_motion_1.useMotionValue)(0.839322);
37
+ const { isDarkmode } = (0, useDarkmode_1.useIsDarkmode)();
38
+ (0, react_1.useEffect)(() => {
39
+ const handleScroll = () => {
40
+ if (elementRef.current) {
41
+ const rect = elementRef.current.getBoundingClientRect();
42
+ const windowHeight = window.innerHeight;
43
+ // Invert the fullWidth value: 1 becomes 0, and 0 becomes 1
44
+ const adjustedFullWidth = 1 - fullWidth;
45
+ // Calculate progress
46
+ const progress = 1 - Math.max(adjustedFullWidth, Math.min(1, rect.top / windowHeight));
47
+ console.log("progress: ", progress);
48
+ // Update motion values
49
+ inViewProgress.set(progress);
50
+ opacity.set(0.839322 + (1 - 0.839322) * progress);
51
+ }
52
+ };
53
+ // Attach scroll and resize event listeners
54
+ bodyRef.current.addEventListener("scroll", handleScroll);
55
+ bodyRef.current.addEventListener("resize", handleScroll);
56
+ // Initial call to handleScroll to set initial state
57
+ handleScroll();
58
+ return () => {
59
+ bodyRef.current.removeEventListener("scroll", handleScroll);
60
+ bodyRef.current.removeEventListener("resize", handleScroll);
61
+ };
62
+ }, [inViewProgress, opacity]);
63
+ const backgroundPosition = (0, framer_motion_1.useTransform)(inViewProgress, [0, 1], [
64
+ "conic-gradient(from 90deg at 90% 0%, var(--colorTop), transparent 180deg) 0% 0% / 50% 150% no-repeat, conic-gradient(from 270deg at 10% 0%, transparent 180deg, var(--colorTop)) 100% 0% / 50% 100% no-repeat",
65
+ "conic-gradient(from 90deg at 0% 0%, var(--colorTop), transparent 180deg) 0% 0% / 50% 100% no-repeat, conic-gradient(from 270deg at 100% 0%, transparent 180deg, var(--colorTop)) 100% 0% / 50% 100% no-repeat",
66
+ ]);
67
+ return (react_1.default.createElement(framer_motion_1.motion.div, { style: {
68
+ "--colorTop": `${isDarkmode ? colorDarkmode : colorLightmode}`,
69
+ background: backgroundPosition,
70
+ opacity: opacity,
71
+ height: "100%",
72
+ transition: "background 0.5s ease, opacity 0.5s ease",
73
+ zIndex: -1,
74
+ maskImage: `linear-gradient(to bottom, background 0%, transparent 98%)`,
75
+ }, ref: elementRef, className: `Conic_conic__HBaxC ${className}` }));
76
+ };
77
+ exports.LightBeam = LightBeam;
78
+ exports.default = exports.LightBeam;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@stianlarsen/react-light-beam",
3
+ "version": "1.0.0",
4
+ "description": "A customizable React component that creates a light beam effect using conic gradients. Supports dark mode and various customization options.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "rm -rf dist && tsc"
10
+ },
11
+ "files": [
12
+ "!src/**",
13
+ "dist",
14
+ "types"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/stianalars1/react-light-beam.git"
25
+ },
26
+ "keywords": [
27
+ "react",
28
+ "light beam",
29
+ "conic gradient",
30
+ "dark mode",
31
+ "framer-motion",
32
+ "animation"
33
+ ],
34
+ "author": "Stian Larsen <stian.larsen@mac.com>",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/stianalars1/react-light-beam/issues"
38
+ },
39
+ "homepage": "https://github.com/stianalars1/react-light-beam#readme",
40
+ "peerDependencies": {
41
+ "framer-motion": "^11.3.30",
42
+ "react": "^18",
43
+ "react-dom": "^18"
44
+ },
45
+ "devDependencies": {
46
+ "@types/react": "^18",
47
+ "@types/react-dom": "^18",
48
+ "typescript": "^5.5.4"
49
+ },
50
+ "dependencies": {
51
+ "framer-motion": "^11.3.30",
52
+ "react": "^18",
53
+ "react-dom": "^18"
54
+ }
55
+ }
@@ -0,0 +1,6 @@
1
+ export type LightBeamProps = {
2
+ className?: string;
3
+ fullWidth?: number;
4
+ colorLightmode?: string;
5
+ colorDarkmode?: string;
6
+ };