Magical Mouse
bucharitesh/magical-mouseFreeComponent
A magical mouse component for Next.js apps with next-themes and Tailwind CSS, supporting system, light, and dark modes.
Install it
npx shadcn@latest add https://bucharitesh.in/r/magical-mouse.jsonSource
1'use client';23import { cn } from '@/lib/utils';4import { Sparkle } from 'lucide-react';5import * as React from 'react';6import { createRoot } from 'react-dom/client';78interface Point {9 x: number;10 y: number;11}1213interface MouseSparklesProps {14 /**15 * Custom icon component to render instead of the default Sparkle16 * @default Sparkle from lucide-react17 */18 icon?: React.ReactNode;19 /**20 * Duration of the star animation in milliseconds21 * @default 150022 */23 starAnimationDuration?: number;24 /**25 * Minimum time between star spawns in milliseconds26 * @default 25027 */28 minimumTimeBetweenStars?: number;29 /**30 * Minimum distance between star spawns in pixels31 * @default 7532 */33 minimumDistanceBetweenStars?: number;34 /**35 * Duration of the glow effect in milliseconds36 * @default 7537 */38 glowDuration?: number;39 /**40 * Maximum spacing between glow points in pixels41 * @default 1042 */43 maximumGlowPointSpacing?: number;44 /**45 * Colors for the stars in RGB format46 * @default ["249 146 253", "252 254 255"]47 */48 colors?: string[];49 /**50 * Sizes for the stars51 * @default ["1.4rem", "1rem", "0.6rem"]52 */53 sizes?: string[];54 /**55 * Custom class name56 */57 className?: string;58}5960const MouseSparkles = React.forwardRef<HTMLDivElement, MouseSparklesProps>(61 (62 {63 icon: Icon = <Sparkle className="h-full w-full" />,64 starAnimationDuration = 1500,65 minimumTimeBetweenStars = 250,66 minimumDistanceBetweenStars = 75,67 glowDuration = 75,68 maximumGlowPointSpacing = 10,69 colors = ['249 146 253', '252 254 255'],70 sizes = ['1.4rem', '1rem', '0.6rem'],71 className,72 ...props73 },74 ref75 ) => {76 const configRef = React.useRef({77 starAnimationDuration,78 minimumTimeBetweenStars,79 minimumDistanceBetweenStars,80 glowDuration,81 maximumGlowPointSpacing,82 colors,83 sizes,84 animations: ['fall-1', 'fall-2', 'fall-3'],85 });8687 const lastRef = React.useRef({88 starTimestamp: Date.now(),89 starPosition: { x: 0, y: 0 },90 mousePosition: { x: 0, y: 0 },91 });9293 let count = 0;9495 const createStar = React.useCallback(96 (position: Point) => {97 const wrapper = document.createElement('div');98 const color = selectRandom(configRef.current.colors);99 const size = selectRandom(configRef.current.sizes);100101 wrapper.className = cn(102 'absolute z-[10000] pointer-events-none',103// … truncated
What it pulls in
npm packages
Files it writes
More from bucharitesh
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bookbook | bucharitesh | Components | Free | 1 dep · 2 files | |
| Game of Lifegame-of-life | bucharitesh | Components | Free | no deps | |
| Metallic Buttonmetallic-button | bucharitesh | Components | Free | 2 deps | |
| Modern Progressmodern-progress | bucharitesh | Components | Free | 1 dep | |
| Pixel Iconpixel-icon | bucharitesh | Components | Free | no deps | |
| Split Text Effectsplit-text-effect | bucharitesh | Components | Free | 1 dep | |
| Text Highlighttext-highlight | bucharitesh | Components | Free | 1 dep | |
| View Magnifierview-magnifier | bucharitesh | Components | Free | 1 dep |
