Skip to content

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

fix: updated motion type in dock (#762)

Arghya Dasd64c422b7c52
diff --git a/public/llms-full.txt b/public/llms-full.txt
index 3ee67a8d..d499b731 100644
--- a/public/llms-full.txt
+++ b/public/llms-full.txt
@@ -6090,12 +6090,12 @@ Description: An implementation of the MacOS dock using react + tailwindcss + mot
import { cva, type VariantProps } from "class-variance-authority";
import {
motion,
- MotionProps,
MotionValue,
useMotionValue,
useSpring,
useTransform,
} from "motion/react";
+import type { MotionProps } from "motion/react";
import React, { PropsWithChildren, useRef } from "react";
import { cn } from "@/lib/utils";
@@ -7978,6 +7978,232 @@ export default function GlobeDemo() {
+===== COMPONENT: grid-beams =====
+Title: Grid Beams
+Description: A dynamic grid background with animated light beams rays and grid patterns.
+
+--- file: registry/magicui/grid-beams.tsx ---
+"use client";
+
+import { motion } from "motion/react";
+import React, { HTMLAttributes, useMemo } from "react";
+import { cn } from "@/lib/utils";
+
+const createGridMask = (start: number, end: number): string => {
+ const mid = (start + end) / 2;
+ return `linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.05) ${start}%, rgba(0,0,0,0.2) ${mid}%, rgba(0,0,0,0.6) ${end - 20}%, rgba(0,0,0,1) ${end}%)`;
+};
+
+const generateRayConfig = (index: number, total: number) => {
+ const progress = index / Math.max(total - 1, 1);
+ const leftPercent = 2 + progress * 96;
+ const rotation = 28 - progress * 56;
+ const variation = (index * 0.618) % 1;
+
+ return {
+ left: `${leftPercent}%`,
+ rotation,
+ width: 40 + variation * 25,
+ duration: 6 + variation * 5,
+ delay: -variation * 10,
+ swayDuration: 12 + variation * 9,
+ swayDelay: -variation * 10,
+ blur: 24 + variation * 9,
+ strongSway: index % 2 === 0,
+ };
+};
+
+interface GridBeamsProps extends HTMLAttributes<HTMLDivElement> {
+ children: React.ReactNode;
+ gridSize?: number;
+ gridColor?: string;
+ rayCount?: number;
+ rayOpacity?: number;
+ raySpeed?: number;
+ rayLength?: string;
+ gridFadeStart?: number;
+ gridFadeEnd?: number;
+ backgroundColor?: string;
+}
+
+interface LightRayProps {
+ left: string;
+ rotation: number;
+ width: number;
+ delay: number;
+ duration: number;
+ swayDuration: number;
+ swayDelay: number;
+ blurAmount: number;
+ isStrongerSway: boolean;
+ opacity: number;
+ speed: number;
+ length: string;
+}
+
+const LightRay = React.memo<LightRayProps>(
+ ({
+ left,
+ rotation,
+ width,
+ delay,
+ duration,
+ swayDuration,
+ swayDelay,
+ blurAmount,
+ isStrongerSway,
+ opacity,
+ speed,
+ length,
+ }) => {
+ return (
+ <motion.div
+ className="absolute pointer-events-none -top-[5%] left-[var(--ray-left)] w-[var(--ray-width)] h-[var(--ray-height)] origin-top mix-blend-screen bg-[linear-gradient(to_bottom,rgba(200,220,255,var(--ray-opacity)),rgba(200,220,255,0))] blur-[var(--ray-blur)] translate-x-[-50%] rotate-[var(--ray-rotation)]"
+ style={
+ {
+ "--ray-left": left,
+ "--ray-width": `${width}px`,
+ "--ray-height": length,
+ "--ray-opacity": opacity,
+ "--ray-blur": `${blurAmount}px`,
+ "--ray-rotation": `${rotation}deg`,
+ } as React.CSSProperties
+ }
+ animate={{
+ opacity: [0.3, 0.7, 0.3],
+ transform: [
+ `translateX(-50%) rotate(${rotation}deg)`,
+ `translateX(-50%) rotate(${rotation + (isStrongerSway ? 1 : 0.5)}deg)`,
+ `translateX(-50%) rotate(${rotation}deg)`,
+ ],
+ }}
+ transition={{
+ opacity: {
+ duration: duration / speed,
+ delay: delay / speed,
+ repeat: Infinity,
+ ease: "easeInOut",
+ },
+ transform: {
+ duration: swayDuration / speed,
+ delay: swayDelay / speed,
+ repeat: Infinity,
+ ease: "easeInOut",
+ },
+ }}
+ />
+ );
+ },
+);
+
+export const GridBeams: React.FC<GridBeamsProps> = ({
+ children,
+ className,
+ gridSize = 40,
+ gridColor = "rgba(200, 220, 255, 0.2)",
+ rayCount = 15,
+ rayOpacity = 0.35,
+ raySpeed = 1,
+ rayLength = "45vh",
+ gridFadeStart = 30,
+ gridFadeEnd = 90,
+ backgroundColor = "#020412",
+ ...props
+}) => {
+ const rayConfigs = useMemo(() => {
+ return Array.from({ length: rayCount }, (_, i) =>
+ generateRayConfig(i, rayCount),
+ );
+ }, [rayCount]);
+
+ const gridMask = useMemo(
+ () => createGridMask(gridFadeStart, gridFadeEnd),
+ [gridFadeStart, gridFadeEnd],
+ );
+
+ return (
+ <div
+ className={cn(
+ "relative overflow-hidden bg-[var(--bg-color)] bg-[radial-gradient(ellipse_at_50%_-20%,#1a2c5a,transparent_70%)]",
+ className,
+ )}
+ style={
+ {
+ "--bg-color": backgroundColor,
+ } as React.CSSProperties
+ }
+ {...props}
+ >
+ <div
+ className="absolute inset-0 pointer-events-none bg-[linear-gradient(var(--grid-color)_1px,transparent_1px),linear-gradient(90deg,var(--grid-color)_1px,transparent_1px)] bg-size-[var(--grid-size)_var(--grid-size)] [mask-image:var(--grid-mask)] [webkit-mask-image:var(--grid-mask)]"
+ style={
+ {
+ "--grid-color": gridColor,
+ "--grid-size": `${gridSize}px`,
+ "--grid-mask": gridMask,
+ } as React.CSSProperties
+ }
+ />
+ <div className="absolute inset-0 overflow-hidden pointer-events-none">
+ {rayConfigs.map((config, index) => (
+ <LightRay
+ key={index}
+ left={config.left}
+ rotation={config.rotation}
+ width={config.width}
+ delay={config.delay}
+ duration={config.duration}
+ swayDuration={config.swayDuration}
+ swayDelay={config.swayDelay}
+ blurAmount={config.blur}
+ isStrongerSway={config.strongSway}
+ opacity={rayOpacity}
+ speed={raySpeed}
+ length={rayLength}
+ />
+ ))}
+ </div>
+
+ <div className="relative z-10">{children}</div>
+ </div>
+ );
+};
+
+
+===== EXAMPLE: grid-beams-demo =====
+Title: grid-beams-demo
+
+--- file: registry/example/grid-beams-demo.tsx ---
+import { GridBeams } from "@/registry/magicui/grid-beams";
+
+export default function GridBeamsDemo() {
+ return (
+ <div className="relative h-[500px] w-full overflow-hidden rounded-lg border">
+ <GridBeams
+ gridSize={0}
+ gridColor="rgba(255, 255, 255, 0.2)"
+ rayCount={20}
+ rayOpacity={0.55}
+ raySpeed={1.5}
+ rayLength="40vh"
+ gridFadeStart={5}
+ gridFadeEnd={90}
+ className="h-full w-full"
+ >
+ <div className="flex h-full items-center justify-center">
+ <div className="text-center space-y-6 px-4 mt-50">
+ <h1 className="text-5xl md:text-7xl font-bold text-white leading-tight">
+ Grid <span className="text-blue-400">BEAMS</span>
+ </h1>
+ </div>
+ </div>
+ </GridBeams>
+ </div>
+ );
+}
+
+
+
===== COMPONENT: grid-pattern =====
Title: Grid Pattern
Description: A background grid pattern made with SVGs, fully customizable using Tailwind CSS.
@@ -8369,10 +8595,10 @@ Description: A text highlighter that mimics the effect of a human-drawn marker s
"use client";
import { useEffect, useRef } from "react";
+import { useInView } from "motion/react";
import { annotate } from "rough-notation";
import type React from "react";
-// Define available annotation actions
type AnnotationAction =
| "highlight"
| "underline"
@@ -8382,7 +8608,6 @@ type AnnotationAction =
| "crossed-off"
| "bracket";
-// Custom TypeScript interface for supported props
interface HighlighterProps {
children: React.ReactNode;
action?: AnnotationAction;
@@ -8392,43 +8617,54 @@ interface HighlighterProps {
iterations?: number;
padding?: number;
multiline?: boolean;
+ isView?: boolean;
}
export function Highlighter({
children,
action = "highlight",
- color = "#ffd1dc", // Default pink color
+ color = "#ffd1dc",
strokeWidth = 1.5,
animationDuration = 600,
iterations = 2,
padding = 2,
multiline = true,
+ isView = false,
}: HighlighterProps) {
const elementRef = useRef<HTMLSpanElement>(null);
+ const isInView = useInView(elementRef, {
+ once: true,
+ margin: "-10%",
+ });
+
+ // If isView is false, always show. If isView is true, wait for inView
+ const shouldShow = !isView || isInView;
useEffect(() => {
+ if (!shouldShow) return;
+
const element = elementRef.current;
- if (element) {
- const annotation = annotate(element, {
- type: action,
- color,
- strokeWidth,
- animationDuration,
- iterations,
- padding,
- multiline,
- });
+ if (!element) return;
+
+ const annotation = annotate(element, {
+ type: action,
+ color,
+ strokeWidth,
+ animationDuration,
+ iterations,
+ padding,
+ multiline,
+ });
- annotation.show();
+ annotation.show();
- // Store the current element in closure for cleanup
- return () => {
- if (element) {
- annotate(element, { type: action }).remove();
- }
- };
- }
+ return () => {
+ if (element) {
+ annotate(element, { type: action }).remove();
+ }
+ };
}, [
+ shouldShow,
action,
color,
strokeWidth,
@@ -8474,10 +8710,10 @@ export default function HighlighterDemo() {
"use client";
import { useEffect, useRef } from "react";
+import { useInView } from "motion/react";
import { annotate } from "rough-notation";
import type React from "react";
-// Define available annotation actions
type AnnotationAction =
| "highlight"
| "underline"
@@ -8487,7 +8723,6 @@ type AnnotationAction =
| "crossed-off"
| "bracket";
-// Custom TypeScript interface for supported props
interface HighlighterProps {
children: React.ReactNode;
action?: AnnotationAction;
@@ -8497,43 +8732,54 @@ interface HighlighterProps {
iterations?: number;
padding?: number;
multiline?: boolean;
+ isView?: boolean;
}
export function Highlighter({
children,
action = "highlight",
- color = "#ffd1dc", // Default pink color
+ color = "#ffd1dc",
strokeWidth = 1.5,
animationDuration = 600,
iterations = 2,
padding = 2,
multiline = true,
+ isView = false,
}: HighlighterProps) {
const elementRef = useRef<HTMLSpanElement>(null);
+ const isInView = useInView(elementRef, {
+ once: true,
+ margin: "-10%",
+ });
+
+ // If isView is false, always show. If isView is true, wait for inView
+ const shouldShow = !isView || isInView;
useEffect(() => {
+ if (!shouldShow) return;
+
const element = elementRef.current;
- if (element) {
- const annotation = annotate(element, {
- type: action,
- color,
- strokeWidth,
- animationDuration,
- iterations,
- padding,
- multiline,
- });
+ if (!element) return;
+
+ const annotation = annotate(element, {
+ type: action,
+ color,
+ strokeWidth,
+ animationDuration,
+ iterations,
+ padding,
+ multiline,
+ });
- annotation.show();
+ annotation.show();
- // Store the current element in closure for cleanup
- return () => {
- if (element) {
- annotate(element, { type: action }).remove();
- }
- };
- }
+ return () => {
+ if (element) {
+ annotate(element, { type: action }).remove();
+ }
+ };
}, [
+ shouldShow,
action,
color,
strokeWidth,
@@ -15246,6 +15492,10 @@ interface TextAnimateProps extends MotionProps {
* The animation preset to use
*/
animation?: AnimationVariant;
+ /**
+ * Whether to enable accessibility features (default: true)
+ */
+ accessible?: boolean;
}
const staggerTimings: Record<AnimationType, number> = {
@@ -15493,6 +15743,7 @@ const TextAnimateBase = ({
once = false,
by = "word",
animation = "fadeIn",
+ accessible = true,
...props
}: TextAnimateProps) => {
const MotionComponent = motion.create(Component);
@@ -15569,8 +15820,10 @@ const TextAnimateBase = ({
exit="exit"
className={cn("whitespace-pre-wrap", className)}
viewport={{ once }}
+ aria-label={accessible ? children : undefined}
{...props}
>
+ {accessible && <span className="sr-only">{children}</span>}
{segments.map((segment, i) => (
<motion.span
key={`${by}-${segment}-${i}`}
@@ -15581,6 +15834,7 @@ const TextAnimateBase = ({
by === "character" && "",
segmentClassName,
)}
+ aria-hidden={accessible ? true : undefined}
>
{segment}
</motion.span>
diff --git a/public/llms.txt b/public/llms.txt
index 3e8c56b3..a91ba9ef 100644
--- a/public/llms.txt
+++ b/public/llms.txt
@@ -33,6 +33,7 @@ This file provides LLM-friendly entry points to documentation and examples.
- [Flickering Grid](https://magicui.design/docs/components/flickering-grid): A flickering grid background made with SVGs, fully customizable using Tailwind CSS.
- [Flip Text](https://magicui.design/docs/components/flip-text): Text flipping character animation
- [Globe](https://magicui.design/docs/components/globe): An autorotating, interactive, and highly performant globe made using WebGL.
+- [Grid Beams](https://magicui.design/docs/components/grid-beams): A dynamic grid background with animated light beams rays and grid patterns.
- [Grid Pattern](https://magicui.design/docs/components/grid-pattern): A background grid pattern made with SVGs, fully customizable using Tailwind CSS.
- [Hero Video Dialog](https://magicui.design/docs/components/hero-video-dialog): A hero video dialog component.
- [Highlighter](https://magicui.design/docs/components/highlighter): A text highlighter that mimics the effect of a human-drawn marker stroke.
@@ -210,6 +211,7 @@ This file provides LLM-friendly entry points to documentation and examples.
- [Highlighter Demo](https://github.com/magicuidesign/magicui/blob/main/registry/example/highlighter-demo.tsx): Example usage
- [Arc Timeline Demo](https://github.com/magicuidesign/magicui/blob/main/registry/example/arc-timeline-demo.tsx): Example usage
- [Animated Theme Toggler Demo](https://github.com/magicuidesign/magicui/blob/main/registry/example/animated-theme-toggler-demo.tsx): Example usage
+- [grid-beams-demo](https://github.com/magicuidesign/magicui/blob/main/registry/example/grid-beams-demo.tsx): Example usage
## Optional
diff --git a/public/r/dock.json b/public/r/dock.json
index fa56cf56..adbcdc99 100644
--- a/public/r/dock.json
+++ b/public/r/dock.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/dock.tsx",
- "content": "\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport {\n motion,\n MotionProps,\n MotionValue,\n useMotionValue,\n useSpring,\n useTransform,\n} from \"motion/react\";\nimport React, { PropsWithChildren, useRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface DockProps extends VariantProps<typeof dockVariants> {\n className?: string;\n iconSize?: number;\n iconMagnification?: number;\n iconDistance?: number;\n direction?: \"top\" | \"middle\" | \"bottom\";\n children: React.ReactNode;\n}\n\nconst DEFAULT_SIZE = 40;\nconst DEFAULT_MAGNIFICATION = 60;\nconst DEFAULT_DISTANCE = 140;\n\nconst dockVariants = cva(\n \"supports-backdrop-blur:bg-white/10 supports-backdrop-blur:dark:bg-black/10 mx-auto mt-8 flex h-[58px] w-max items-center justify-center gap-2 rounded-2xl border p-2 backdrop-blur-md\",\n);\n\nconst Dock = React.forwardRef<HTMLDivElement, DockProps>(\n (\n {\n className,\n children,\n iconSize = DEFAULT_SIZE,\n iconMagnification = DEFAULT_MAGNIFICATION,\n iconDistance = DEFAULT_DISTANCE,\n direction = \"middle\",\n ...props\n },\n ref,\n ) => {\n const mouseX = useMotionValue(Infinity);\n\n const renderChildren = () => {\n return React.Children.map(children, (child) => {\n if (\n React.isValidElement<DockIconProps>(child) &&\n child.type === DockIcon\n ) {\n return React.cloneElement(child, {\n ...child.props,\n mouseX: mouseX,\n size: iconSize,\n magnification: iconMagnification,\n distance: iconDistance,\n });\n }\n return child;\n });\n };\n\n return (\n <motion.div\n ref={ref}\n onMouseMove={(e) => mouseX.set(e.pageX)}\n onMouseLeave={() => mouseX.set(Infinity)}\n {...props}\n className={cn(dockVariants({ className }), {\n \"items-start\": direction === \"top\",\n \"items-center\": direction === \"middle\",\n \"items-end\": direction === \"bottom\",\n })}\n >\n {renderChildren()}\n </motion.div>\n );\n },\n);\n\nDock.displayName = \"Dock\";\n\nexport interface DockIconProps\n extends Omit<MotionProps & React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n size?: number;\n magnification?: number;\n distance?: number;\n mouseX?: MotionValue<number>;\n className?: string;\n children?: React.ReactNode;\n props?: PropsWithChildren;\n}\n\nconst DockIcon = ({\n size = DEFAULT_SIZE,\n magnification = DEFAULT_MAGNIFICATION,\n distance = DEFAULT_DISTANCE,\n mouseX,\n className,\n children,\n ...props\n}: DockIconProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const padding = Math.max(6, size * 0.2);\n const defaultMouseX = useMotionValue(Infinity);\n\n const distanceCalc = useTransform(mouseX ?? defaultMouseX, (val: number) => {\n const bounds = ref.current?.getBoundingClientRect() ?? { x: 0, width: 0 };\n return val - bounds.x - bounds.width / 2;\n });\n\n const sizeTransform = useTransform(\n distanceCalc,\n [-distance, 0, distance],\n [size, magnification, size],\n );\n\n const scaleSize = useSpring(sizeTransform, {\n mass: 0.1,\n stiffness: 150,\n damping: 12,\n });\n\n return (\n <motion.div\n ref={ref}\n style={{ width: scaleSize, height: scaleSize, padding }}\n className={cn(\n \"flex aspect-square cursor-pointer items-center justify-center rounded-full\",\n className,\n )}\n {...props}\n >\n {children}\n </motion.div>\n );\n};\n\nDockIcon.displayName = \"DockIcon\";\n\nexport { Dock, DockIcon, dockVariants };\n",
+ "content": "\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport {\n motion,\n MotionValue,\n useMotionValue,\n useSpring,\n useTransform,\n} from \"motion/react\";\nimport type { MotionProps } from \"motion/react\";\nimport React, { PropsWithChildren, useRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface DockProps extends VariantProps<typeof dockVariants> {\n className?: string;\n iconSize?: number;\n iconMagnification?: number;\n iconDistance?: number;\n direction?: \"top\" | \"middle\" | \"bottom\";\n children: React.ReactNode;\n}\n\nconst DEFAULT_SIZE = 40;\nconst DEFAULT_MAGNIFICATION = 60;\nconst DEFAULT_DISTANCE = 140;\n\nconst dockVariants = cva(\n \"supports-backdrop-blur:bg-white/10 supports-backdrop-blur:dark:bg-black/10 mx-auto mt-8 flex h-[58px] w-max items-center justify-center gap-2 rounded-2xl border p-2 backdrop-blur-md\",\n);\n\nconst Dock = React.forwardRef<HTMLDivElement, DockProps>(\n (\n {\n className,\n children,\n iconSize = DEFAULT_SIZE,\n iconMagnification = DEFAULT_MAGNIFICATION,\n iconDistance = DEFAULT_DISTANCE,\n direction = \"middle\",\n ...props\n },\n ref,\n ) => {\n const mouseX = useMotionValue(Infinity);\n\n const renderChildren = () => {\n return React.Children.map(children, (child) => {\n if (\n React.isValidElement<DockIconProps>(child) &&\n child.type === DockIcon\n ) {\n return React.cloneElement(child, {\n ...child.props,\n mouseX: mouseX,\n size: iconSize,\n magnification: iconMagnification,\n distance: iconDistance,\n });\n }\n return child;\n });\n };\n\n return (\n <motion.div\n ref={ref}\n onMouseMove={(e) => mouseX.set(e.pageX)}\n onMouseLeave={() => mouseX.set(Infinity)}\n {...props}\n className={cn(dockVariants({ className }), {\n \"items-start\": direction === \"top\",\n \"items-center\": direction === \"middle\",\n \"items-end\": direction === \"bottom\",\n })}\n >\n {renderChildren()}\n </motion.div>\n );\n },\n);\n\nDock.displayName = \"Dock\";\n\nexport interface DockIconProps\n extends Omit<MotionProps & React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n size?: number;\n magnification?: number;\n distance?: number;\n mouseX?: MotionValue<number>;\n className?: string;\n children?: React.ReactNode;\n props?: PropsWithChildren;\n}\n\nconst DockIcon = ({\n size = DEFAULT_SIZE,\n magnification = DEFAULT_MAGNIFICATION,\n distance = DEFAULT_DISTANCE,\n mouseX,\n className,\n children,\n ...props\n}: DockIconProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const padding = Math.max(6, size * 0.2);\n const defaultMouseX = useMotionValue(Infinity);\n\n const distanceCalc = useTransform(mouseX ?? defaultMouseX, (val: number) => {\n const bounds = ref.current?.getBoundingClientRect() ?? { x: 0, width: 0 };\n return val - bounds.x - bounds.width / 2;\n });\n\n const sizeTransform = useTransform(\n distanceCalc,\n [-distance, 0, distance],\n [size, magnification, size],\n );\n\n const scaleSize = useSpring(sizeTransform, {\n mass: 0.1,\n stiffness: 150,\n damping: 12,\n });\n\n return (\n <motion.div\n ref={ref}\n style={{ width: scaleSize, height: scaleSize, padding }}\n className={cn(\n \"flex aspect-square cursor-pointer items-center justify-center rounded-full\",\n className,\n )}\n {...props}\n >\n {children}\n </motion.div>\n );\n};\n\nDockIcon.displayName = \"DockIcon\";\n\nexport { Dock, DockIcon, dockVariants };\n",
"type": "registry:ui",
"target": "components/magicui/dock.tsx"
}
diff --git a/registry/magicui/dock.tsx b/registry/magicui/dock.tsx
index 43a810f7..d5ba18cc 100644
--- a/registry/magicui/dock.tsx
+++ b/registry/magicui/dock.tsx
@@ -3,12 +3,12 @@
import { cva, type VariantProps } from "class-variance-authority";
import {
motion,
- MotionProps,
MotionValue,
useMotionValue,
useSpring,
useTransform,
} from "motion/react";
+import type { MotionProps } from "motion/react";
import React, { PropsWithChildren, useRef } from "react";
import { cn } from "@/lib/utils";