react-grid-lights 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 +21 -0
- package/README.md +204 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +455 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +429 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# react-grid-lights
|
|
2
|
+
|
|
3
|
+
A React component for animated grid backgrounds with traveling light particles. Create stunning visual effects with square or hexagonal grids and customizable light animations.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Two Grid Types**: Square (4-sided) and Hexagonal (6-sided) tessellations
|
|
11
|
+
- **Animated Light Particles**: Particles travel along grid edges with smooth animations
|
|
12
|
+
- **Particle Splitting**: Lights can split into multiple paths at intersections
|
|
13
|
+
- **Fading Trails**: Particles leave behind glowing trails that slowly fade
|
|
14
|
+
- **Explosion Effects**: Small burst animation when particles reach their end
|
|
15
|
+
- **Collision Avoidance**: Particles automatically avoid crossing paths
|
|
16
|
+
- **Fully Customizable**: Control colors, speeds, sizes, and behaviors
|
|
17
|
+
- **Responsive**: Automatically adapts to container size changes
|
|
18
|
+
- **HiDPI Support**: Crisp rendering on retina displays
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install react-grid-lights
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add react-grid-lights
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add react-grid-lights
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { Grid } from "react-grid-lights";
|
|
38
|
+
|
|
39
|
+
function App() {
|
|
40
|
+
return (
|
|
41
|
+
<div style={{ width: "100%", height: "400px" }}>
|
|
42
|
+
<Grid
|
|
43
|
+
shape={6}
|
|
44
|
+
animated
|
|
45
|
+
lightColor="#3b82f6"
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
### Basic Hexagon Grid (Static)
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<Grid shape={6} cellSize={60} lineColor="#e5e7eb" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Animated Square Grid
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<Grid
|
|
64
|
+
shape={4}
|
|
65
|
+
cellSize={40}
|
|
66
|
+
animated
|
|
67
|
+
lightColor="#10b981"
|
|
68
|
+
lightSpeed={2}
|
|
69
|
+
/>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Invisible Grid with Light Trails Only
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
<Grid
|
|
76
|
+
shape={6}
|
|
77
|
+
cellSize={80}
|
|
78
|
+
lineColor="transparent"
|
|
79
|
+
animated
|
|
80
|
+
lightColor="#8b5cf6"
|
|
81
|
+
lightSpeed={2}
|
|
82
|
+
minTravel={3}
|
|
83
|
+
maxTravel={10}
|
|
84
|
+
spawnRate={500}
|
|
85
|
+
splitChance={0.4}
|
|
86
|
+
trailFadeSpeed={0.005}
|
|
87
|
+
/>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Full Configuration Example
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
<Grid
|
|
94
|
+
shape={6} // Hexagonal grid
|
|
95
|
+
cellSize={100} // 100px cell size
|
|
96
|
+
lineColor="transparent" // Hide grid lines
|
|
97
|
+
lineWidth={1} // Grid line width
|
|
98
|
+
animated // Enable animations
|
|
99
|
+
lightColor="#3b82f6" // Blue lights
|
|
100
|
+
lightSpeed={2} // Medium speed
|
|
101
|
+
minTravel={3} // Min 3 edges traveled
|
|
102
|
+
maxTravel={12} // Max 12 edges traveled
|
|
103
|
+
spawnRate={600} // New particle every 600ms
|
|
104
|
+
splitChance={0.4} // 40% chance to split
|
|
105
|
+
trailFadeSpeed={0.005} // Slow trail fade
|
|
106
|
+
className="my-custom-class" // Additional CSS classes
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Props
|
|
111
|
+
|
|
112
|
+
| Prop | Type | Default | Description |
|
|
113
|
+
|------|------|---------|-------------|
|
|
114
|
+
| `shape` | `4 \| 6` | `4` | Grid shape: `4` for squares, `6` for hexagons |
|
|
115
|
+
| `cellSize` | `number` | `40` | Size of each cell in pixels |
|
|
116
|
+
| `lineColor` | `string` | `"#e5e7eb"` | Color of grid lines (use `"transparent"` to hide) |
|
|
117
|
+
| `lineWidth` | `number` | `1` | Width of grid lines in pixels |
|
|
118
|
+
| `className` | `string` | `""` | Additional CSS classes for the container |
|
|
119
|
+
| `animated` | `boolean` | `false` | Enable animated light particles |
|
|
120
|
+
| `lightColor` | `string` | `"#3b82f6"` | Color of light particles and trails |
|
|
121
|
+
| `lightSpeed` | `number` | `2` | Speed of particles (1-5 recommended) |
|
|
122
|
+
| `minTravel` | `number` | `2` | Minimum edges a particle travels before dying |
|
|
123
|
+
| `maxTravel` | `number` | `6` | Maximum edges a particle travels before dying |
|
|
124
|
+
| `spawnRate` | `number` | `1000` | Milliseconds between new particle spawns |
|
|
125
|
+
| `splitChance` | `number` | `0.3` | Probability (0-1) of particle splitting at nodes |
|
|
126
|
+
| `trailFadeSpeed` | `number` | `0.01` | How fast trails fade (lower = slower) |
|
|
127
|
+
|
|
128
|
+
## Styling
|
|
129
|
+
|
|
130
|
+
The component renders a container `div` with a `canvas` element inside. The container has `position: relative` and uses `width: 100%` and `height: 100%` by default.
|
|
131
|
+
|
|
132
|
+
**Important**: The component will fill its parent container. Make sure the parent has a defined height.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
// Good - parent has explicit height
|
|
136
|
+
<div style={{ height: "400px" }}>
|
|
137
|
+
<Grid animated />
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
// Good - parent uses flex/grid with defined dimensions
|
|
141
|
+
<div className="h-screen flex items-center">
|
|
142
|
+
<div className="w-full h-96">
|
|
143
|
+
<Grid animated />
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## How It Works
|
|
149
|
+
|
|
150
|
+
1. **Grid Generation**: On mount, the component builds a graph of nodes and edges based on the selected shape (square or hexagonal tessellation).
|
|
151
|
+
|
|
152
|
+
2. **Particle System**: When `animated` is true, particles spawn from the top edge of the grid and travel downward along connected edges.
|
|
153
|
+
|
|
154
|
+
3. **Path Finding**: Each particle randomly selects available edges at each node, avoiding edges currently occupied by other particles.
|
|
155
|
+
|
|
156
|
+
4. **Splitting**: Particles can split into two at intersections based on `splitChance`. Each particle can only split once.
|
|
157
|
+
|
|
158
|
+
5. **Trail Rendering**: As particles move, they leave behind glowing trails that persist and slowly fade based on `trailFadeSpeed`.
|
|
159
|
+
|
|
160
|
+
6. **Lifecycle**: Particles die after traveling `minTravel` to `maxTravel` edges (randomly determined), triggering a small explosion effect.
|
|
161
|
+
|
|
162
|
+
## Browser Support
|
|
163
|
+
|
|
164
|
+
- Chrome (latest)
|
|
165
|
+
- Firefox (latest)
|
|
166
|
+
- Safari (latest)
|
|
167
|
+
- Edge (latest)
|
|
168
|
+
|
|
169
|
+
Requires browsers with support for:
|
|
170
|
+
- Canvas 2D API
|
|
171
|
+
- ResizeObserver
|
|
172
|
+
- requestAnimationFrame
|
|
173
|
+
|
|
174
|
+
## TypeScript
|
|
175
|
+
|
|
176
|
+
Full TypeScript support with exported types:
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { Grid, type GridProps } from "react-grid-lights";
|
|
180
|
+
|
|
181
|
+
const props: GridProps = {
|
|
182
|
+
shape: 6,
|
|
183
|
+
animated: true,
|
|
184
|
+
lightColor: "#3b82f6",
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
<Grid {...props} />
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Performance Tips
|
|
191
|
+
|
|
192
|
+
- Use larger `cellSize` values for better performance on large containers
|
|
193
|
+
- Increase `spawnRate` to reduce the number of active particles
|
|
194
|
+
- Reduce `maxTravel` to limit particle lifetime
|
|
195
|
+
- Lower `splitChance` to reduce particle count
|
|
196
|
+
- Use `lineColor="transparent"` if you only want to show the animated lights
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|
|
201
|
+
|
|
202
|
+
## Contributing
|
|
203
|
+
|
|
204
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface GridProps {
|
|
4
|
+
/** Grid shape: 4 for squares, 6 for hexagons */
|
|
5
|
+
shape?: 4 | 6;
|
|
6
|
+
/** Size of each cell in pixels */
|
|
7
|
+
cellSize?: number;
|
|
8
|
+
/** Color of the grid lines (use "transparent" to hide) */
|
|
9
|
+
lineColor?: string;
|
|
10
|
+
/** Width of the grid lines */
|
|
11
|
+
lineWidth?: number;
|
|
12
|
+
/** Additional CSS classes */
|
|
13
|
+
className?: string;
|
|
14
|
+
/** Enable animated light particles */
|
|
15
|
+
animated?: boolean;
|
|
16
|
+
/** Color of the light particles and trails */
|
|
17
|
+
lightColor?: string;
|
|
18
|
+
/** Speed of the light particles (1-5 recommended) */
|
|
19
|
+
lightSpeed?: number;
|
|
20
|
+
/** Minimum travel distance before particle dies */
|
|
21
|
+
minTravel?: number;
|
|
22
|
+
/** Maximum travel distance before particle dies */
|
|
23
|
+
maxTravel?: number;
|
|
24
|
+
/** Milliseconds between particle spawns */
|
|
25
|
+
spawnRate?: number;
|
|
26
|
+
/** Probability of particle splitting (0-1) */
|
|
27
|
+
splitChance?: number;
|
|
28
|
+
/** Speed at which trails fade (lower = slower fade) */
|
|
29
|
+
trailFadeSpeed?: number;
|
|
30
|
+
}
|
|
31
|
+
declare function Grid({ shape, cellSize, lineColor, lineWidth, className, animated, lightColor, lightSpeed, minTravel, maxTravel, spawnRate, splitChance, trailFadeSpeed, }: GridProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
33
|
+
export { Grid, type GridProps, Grid as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface GridProps {
|
|
4
|
+
/** Grid shape: 4 for squares, 6 for hexagons */
|
|
5
|
+
shape?: 4 | 6;
|
|
6
|
+
/** Size of each cell in pixels */
|
|
7
|
+
cellSize?: number;
|
|
8
|
+
/** Color of the grid lines (use "transparent" to hide) */
|
|
9
|
+
lineColor?: string;
|
|
10
|
+
/** Width of the grid lines */
|
|
11
|
+
lineWidth?: number;
|
|
12
|
+
/** Additional CSS classes */
|
|
13
|
+
className?: string;
|
|
14
|
+
/** Enable animated light particles */
|
|
15
|
+
animated?: boolean;
|
|
16
|
+
/** Color of the light particles and trails */
|
|
17
|
+
lightColor?: string;
|
|
18
|
+
/** Speed of the light particles (1-5 recommended) */
|
|
19
|
+
lightSpeed?: number;
|
|
20
|
+
/** Minimum travel distance before particle dies */
|
|
21
|
+
minTravel?: number;
|
|
22
|
+
/** Maximum travel distance before particle dies */
|
|
23
|
+
maxTravel?: number;
|
|
24
|
+
/** Milliseconds between particle spawns */
|
|
25
|
+
spawnRate?: number;
|
|
26
|
+
/** Probability of particle splitting (0-1) */
|
|
27
|
+
splitChance?: number;
|
|
28
|
+
/** Speed at which trails fade (lower = slower fade) */
|
|
29
|
+
trailFadeSpeed?: number;
|
|
30
|
+
}
|
|
31
|
+
declare function Grid({ shape, cellSize, lineColor, lineWidth, className, animated, lightColor, lightSpeed, minTravel, maxTravel, spawnRate, splitChance, trailFadeSpeed, }: GridProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
33
|
+
export { Grid, type GridProps, Grid as default };
|