Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

Feature (Components): Add glow effect to Dot Pattern component (#510)

Isaac "H3rmel" Reginato32939d838890
diff --git a/__registry__/index.tsx b/__registry__/index.tsx
index b8123d69..561f533f 100644
--- a/__registry__/index.tsx
+++ b/__registry__/index.tsx
@@ -1951,6 +1951,31 @@ export const Index: Record<string, any> = {
}),
meta: undefined,
},
+ "dot-pattern-with-glow-effect": {
+ name: "dot-pattern-with-glow-effect",
+ description: "",
+ type: "registry:example",
+ registryDependencies: ["dot-pattern"],
+ files: [
+ {
+ path: "registry/example/dot-pattern-with-glow-effect.tsx",
+ type: "registry:example",
+ target: "",
+ },
+ ],
+ component: React.lazy(async () => {
+ const mod = await import(
+ "@/registry/example/dot-pattern-with-glow-effect.tsx"
+ );
+ const exportName =
+ Object.keys(mod).find(
+ (key) =>
+ typeof mod[key] === "function" || typeof mod[key] === "object",
+ ) || item.name;
+ return { default: mod.default || mod[exportName] };
+ }),
+ meta: undefined,
+ },
"flickering-grid-demo": {
name: "flickering-grid-demo",
description: "Example showing a flickering grid background.",
diff --git a/content/docs/components/dot-pattern.mdx b/content/docs/components/dot-pattern.mdx
index 084d5e28..34cf1261 100644
--- a/content/docs/components/dot-pattern.mdx
+++ b/content/docs/components/dot-pattern.mdx
@@ -47,17 +47,22 @@ npx shadcn@latest add "https://magicui.design/r/dot-pattern"
<ComponentPreview name="dot-pattern-linear-gradient" />
+### With Glow Effect
+
+<ComponentPreview name="dot-pattern-with-glow-effect" />
+
## Props
### Dot Pattern
-| Prop | Type | Default | Description |
-| ----------- | -------- | ------- | ----------------------------- |
-| `width` | `any` | `16` | Width of the dot pattern |
-| `height` | `any` | `16` | Height of the dot pattern |
-| `x` | `any` | `0` | X position of the dot |
-| `y` | `any` | `0` | Y position of the dot |
-| `cx` | `any` | `1` | X position of the circle |
-| `cy` | `any` | `1` | Y position of the circle |
-| `cr` | `any` | `1` | Radius of the circle |
-| `className` | `string` | `-` | Class name of the dot pattern |
+| Prop | Type | Default | Description |
+| ----------- | --------- | ------- | -------------------------------------------- |
+| `width` | `any` | `16` | Width of the dot pattern |
+| `height` | `any` | `16` | Height of the dot pattern |
+| `x` | `any` | `0` | X position of the dot |
+| `y` | `any` | `0` | Y position of the dot |
+| `cx` | `any` | `1` | X position of the circle |
+| `cy` | `any` | `1` | Y position of the circle |
+| `cr` | `any` | `1` | Radius of the circle |
+| `className` | `string` | `-` | Class name of the dot pattern |
+| `glow` | `boolean` | `false` | Activates the glow effect in the dot pattern |
diff --git a/public/r/dot-pattern-with-glow-effect.json b/public/r/dot-pattern-with-glow-effect.json
new file mode 100644
index 00000000..18f2a1be
--- /dev/null
+++ b/public/r/dot-pattern-with-glow-effect.json
@@ -0,0 +1,16 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "dot-pattern-with-glow-effect",
+ "type": "registry:example",
+ "registryDependencies": [
+ "dot-pattern"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dot-pattern-with-glow-effect.tsx",
+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { DotPattern } from \"@/registry/magicui/dot-pattern\";\n\nexport default function DotPatternWithGlowEffectDemo() {\n return (\n <div className=\"relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border bg-background md:shadow-xl\">\n <p className=\"z-10 whitespace-pre-wrap text-center text-5xl font-medium tracking-tighter text-black dark:text-white\">\n Dot Pattern With Glow Effect\n </p>\n <DotPattern\n glow={true}\n className={cn(\n \"[mask-image:radial-gradient(300px_circle_at_center,white,transparent)]\",\n )}\n />\n </div>\n );\n}\n",
+ "type": "registry:example",
+ "target": ""
+ }
+ ]
+}
\ No newline at end of file
diff --git a/registry.json b/registry.json
index 09e91f8d..d5e42107 100644
--- a/registry.json
+++ b/registry.json
@@ -1689,6 +1689,20 @@
}
]
},
+ {
+ "name": "dot-pattern-with-glow-effect",
+ "type": "registry:example",
+ "registryDependencies": [
+ "dot-pattern"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dot-pattern-with-glow-effect.tsx",
+ "type": "registry:example",
+ "target": ""
+ }
+ ]
+ },
{
"name": "flickering-grid-demo",
"type": "registry:example",
diff --git a/registry/example/dot-pattern-with-glow-effect.tsx b/registry/example/dot-pattern-with-glow-effect.tsx
new file mode 100644
index 00000000..34552de6
--- /dev/null
+++ b/registry/example/dot-pattern-with-glow-effect.tsx
@@ -0,0 +1,17 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+import { DotPattern } from "@/registry/magicui/dot-pattern";
+
+export default function DotPatternWithGlowEffectDemo() {
+ return (
+ <div className="relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden">
+ <DotPattern
+ glow={true}
+ className={cn(
+ "[mask-image:radial-gradient(300px_circle_at_center,white,transparent)]",
+ )}
+ />
+ </div>
+ );
+}
diff --git a/registry/magicui/dot-pattern.tsx b/registry/magicui/dot-pattern.tsx
index a1e79fab..f115a134 100644
--- a/registry/magicui/dot-pattern.tsx
+++ b/registry/magicui/dot-pattern.tsx
@@ -1,7 +1,22 @@
-import { useId } from "react";
+"use client";
import { cn } from "@/lib/utils";
+import { motion } from "motion/react";
+import React, { useEffect, useId, useRef, useState } from "react";
+/**
+ * DotPattern Component Props
+ *
+ * @param {number} [width=16] - The horizontal spacing between dots
+ * @param {number} [height=16] - The vertical spacing between dots
+ * @param {number} [x=0] - The x-offset of the entire pattern
+ * @param {number} [y=0] - The y-offset of the entire pattern
+ * @param {number} [cx=1] - The x-offset of individual dots
+ * @param {number} [cy=1] - The y-offset of individual dots
+ * @param {number} [cr=1] - The radius of each dot
+ * @param {string} [className] - Additional CSS classes to apply to the SVG container
+ * @param {boolean} [glow=false] - Whether dots should have a glowing animation effect
+ */
interface DotPatternProps extends React.SVGProps<SVGSVGElement> {
width?: number;
height?: number;
@@ -11,8 +26,40 @@ interface DotPatternProps extends React.SVGProps<SVGSVGElement> {
cy?: number;
cr?: number;
className?: string;
+ glow?: boolean;
[key: string]: unknown;
}
+
+/**
+ * DotPattern Component
+ *
+ * A React component that creates an animated or static dot pattern background using SVG.
+ * The pattern automatically adjusts to fill its container and can optionally display glowing dots.
+ *
+ * @component
+ *
+ * @see DotPatternProps for the props interface.
+ *
+ * @example
+ * // Basic usage
+ * <DotPattern />
+ *
+ * // With glowing effect and custom spacing
+ * <DotPattern
+ * width={20}
+ * height={20}
+ * glow={true}
+ * className="opacity-50"
+ * />
+ *
+ * @notes
+ * - The component is client-side only ("use client")
+ * - Automatically responds to container size changes
+ * - When glow is enabled, dots will animate with random delays and durations
+ * - Uses Motion for animations
+ * - Dots color can be controlled via the text color utility classes
+ */
+
export function DotPattern({
width = 16,
height = 16,
@@ -22,33 +69,90 @@ export function DotPattern({
cy = 1,
cr = 1,
className,
+ glow = false,
...props
}: DotPatternProps) {
const id = useId();
+ const containerRef = useRef<SVGSVGElement>(null);
+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
+
+ useEffect(() => {
+ const updateDimensions = () => {
+ if (containerRef.current) {
+ const { width, height } = containerRef.current.getBoundingClientRect();
+ setDimensions({ width, height });
+ }
+ };
+
+ updateDimensions();
+ window.addEventListener("resize", updateDimensions);
+ return () => window.removeEventListener("resize", updateDimensions);
+ }, []);
+
+ const dots = Array.from(
+ {
+ length:
+ Math.ceil(dimensions.width / width) *
+ Math.ceil(dimensions.height / height),
+ },
+ (_, i) => {
+ const col = i % Math.ceil(dimensions.width / width);
+ const row = Math.floor(i / Math.ceil(dimensions.width / width));
+ return {
+ x: col * width + cx,
+ y: row * height + cy,
+ delay: Math.random() * 5,
+ duration: Math.random() * 3 + 2,
+ };
+ },
+ );
return (
<svg
+ ref={containerRef}
aria-hidden="true"
className={cn(
- "pointer-events-none absolute inset-0 h-full w-full fill-neutral-400/80",
+ "pointer-events-none absolute inset-0 h-full w-full",
className,
)}
{...props}
>
<defs>
- <pattern
- id={id}
- width={width}
- height={height}
- patternUnits="userSpaceOnUse"
- patternContentUnits="userSpaceOnUse"
- x={x}
- y={y}
- >
- <circle id="pattern-circle" cx={cx} cy={cy} r={cr} />
- </pattern>
+ <radialGradient id={`${id}-gradient`}>
+ <stop offset="0%" stopColor="currentColor" stopOpacity="1" />
+ <stop offset="100%" stopColor="currentColor" stopOpacity="0" />
+ </radialGradient>
</defs>
- <rect width="100%" height="100%" strokeWidth={0} fill={`url(#${id})`} />
+ {dots.map((dot, index) => (
+ <motion.circle
+ key={`${dot.x}-${dot.y}`}
+ cx={dot.x}
+ cy={dot.y}
+ r={cr}
+ fill={glow ? `url(#${id}-gradient)` : "currentColor"}
+ className="text-neutral-400/80"
+ initial={glow ? { opacity: 0.4, scale: 1 } : {}}
+ animate={
+ glow
+ ? {
+ opacity: [0.4, 1, 0.4],
+ scale: [1, 1.5, 1],
+ }
+ : {}
+ }
+ transition={
+ glow
+ ? {
+ duration: dot.duration,
+ repeat: Infinity,
+ repeatType: "reverse",
+ delay: dot.delay,
+ ease: "easeInOut",
+ }
+ : {}
+ }
+ />
+ ))}
</svg>
);
}
diff --git a/registry/registry-examples.ts b/registry/registry-examples.ts
index 718d0f6c..7ea1f402 100644
--- a/registry/registry-examples.ts
+++ b/registry/registry-examples.ts
@@ -269,6 +269,20 @@ export const examples: Registry["items"] = [
},
],
},
+ {
+ name: "dot-pattern-with-glow-effect",
+ type: "registry:example",
+ title: "Dot Pattern with glow effect",
+ description: "Example showing a dot pattern with glow effect",
+ registryDependencies: ["https://magicui.design/r/dot-pattern"],
+ files: [
+ {
+ path: "example/dot-pattern-with-glow-effect.tsx",
+ type: "registry:example",
+ target: "",
+ },
+ ],
+ },
{
name: "flickering-grid-demo",
type: "registry:example",