Moving Gradient Button
wise-ui/moving-gradient-buttonFreeComponent
A button that reveals a spinning gradient border and flowing gradient text on hover.
Live preview
live · rendered by the registry
Rendered by wise-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://wise-ui.com/r/moving-gradient-button.jsonSource
1"use client"23import * as React from "react"4import { motion, useMotionValue, useTransform, animate } from "motion/react"5import { cn } from "@/registry/wise-ui/lib/utils"67interface MovingGradientButtonProps8 extends React.ButtonHTMLAttributes<HTMLButtonElement> {9 animateBorder?: boolean10 animateText?: boolean11 gradientFrom?: string12 gradientTo?: string13 startIcon?: React.ReactNode14 endIcon?: React.ReactNode15 children: React.ReactNode16}1718const MovingGradientButton = React.forwardRef<19 HTMLButtonElement,20 MovingGradientButtonProps21>(22 (23 {24 animateBorder = true,25 animateText = true,26 gradientFrom = "#00a896",27 gradientTo = "#c084fc",28 startIcon,29 endIcon,30 children,31 disabled,32 className,33 ...props34 },35 ref36 ) => {37 const [isHovered, setIsHovered] = React.useState(false)38 const rotation = useMotionValue(0)39 const controlRef = React.useRef<ReturnType<typeof animate> | null>(null)4041 React.useEffect(() => {42 if (isHovered && (animateBorder || animateText) && !disabled) {43 controlRef.current = animate(44 rotation,45 rotation.get() + 360 * 10000,46 { duration: 3 * 10000, ease: "linear" }47 )48 } else {49 controlRef.current?.stop()50 }51 return () => {52 controlRef.current?.stop()53 }54 }, [isHovered, animateBorder, animateText, disabled, rotation])5556 // Shift –100% per 360° - with backgroundRepeat:"repeat" this scrolls57 // the from→to→from gradient infinitely without any visible seam58 const backgroundPosition = useTransform(59 rotation,60 (v) => `${-(v * 100) / 360}% 0%`61 )6263 const showBorderAnimation = isHovered && animateBorder && !disabled64 const showTextAnimation = isHovered && animateText && !disabled6566 return (67 <div68 className={cn(69 "group relative inline-flex rounded-md",70 disabled && "pointer-events-none opacity-50"71 )}72 onMouseEnter={() => setIsHovered(true)}73 onMouseLeave={() => setIsHovered(false)}74 >75 {/* Static border - visible at rest */}76 <div77 className="pointer-events-none absolute inset-0 rounded-md border border-border transition-opacity duration-300"78 style={{ opacity: showBorderAnimation ? 0 : 1 }}79 />8081 {/* Spinning conic gradient - visible on hover */}82 <div83// … truncated
What it pulls in
npm packages
Files it writes
More from wise-ui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Tabsanimated-tabs | wise-ui | Components | Free | 3 deps | |
| Border Beamborder-beam | wise-ui | Components | Free | 3 deps | |
| Data Tabledata-table | wise-ui | Components | Free | 3 deps | |
| Dockdock | wise-ui | Components | Free | 3 deps | |
| Dot Matrixdot-matrix | wise-ui | Components | Free | 2 deps | |
| Editable Texteditable-text | wise-ui | Components | Free | 4 deps | |
| Gradient Sidebargradient-sidebar | wise-ui | Components | Free | 3 deps | |
| Kanban Boardkanban-board | wise-ui | Components | Free | 6 deps |
