Flow Button
spell-ui/flow-buttonFreeComponent
A button with animated flowing dashed border on hover.
Live preview
live · rendered by the registry
Rendered by spell-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://spell.sh/r/flow-button.jsonSource
1"use client";23import * as React from "react";4import { Slot } from "@radix-ui/react-slot";5import { cn } from "@/lib/utils";67type SizeVariant = "sm" | "default" | "lg";89interface FlowButtonProps10 extends React.ButtonHTMLAttributes<HTMLButtonElement> {11 children: React.ReactNode;12 size?: SizeVariant;13 borderColor?: string;14 className?: string;15 asChild?: boolean;16}1718const sizeMap: Record<SizeVariant, string> = {19 sm: "h-8 rounded-full gap-1.5 px-3 text-sm",20 default: "h-9 px-4 py-2 text-sm rounded-full",21 lg: "h-10 rounded-full px-6 text-sm",22};2324const borderRadiusMap: Record<SizeVariant, number> = {25 sm: 16,26 default: 18,27 lg: 20,28};2930const FlowButton = React.forwardRef<31 HTMLButtonElement,32 FlowButtonProps33>(34 (35 {36 children,37 size = "default",38 borderColor = "var(--rotating-border-color)",39 className,40 asChild = false,41 ...props42 },43 ref,44 ) => {45 const buttonRef = React.useRef<HTMLButtonElement>(null);46 const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 });4748 React.useImperativeHandle(ref, () => buttonRef.current!);4950 const Comp = asChild ? Slot : "button";5152 React.useEffect(() => {53 if (buttonRef.current) {54 const { offsetWidth, offsetHeight } = buttonRef.current;55 setDimensions({ width: offsetWidth, height: offsetHeight });56 }57 }, [children]);5859 const buttonSize = sizeMap[size];60 const radius = borderRadiusMap[size];6162 const createRoundedRectPath = (w: number, h: number, r: number) => {63 return `M${r},0.5 H${w - r} A${r},${r} 0 0 1 ${w - 0.5},${r} V${64 h - r65 } A${r},${r} 0 0 1 ${w - r},${h - 0.5} H${r} A${r},${r} 0 0 1 0.5,${66 h - r67 } V${r} A${r},${r} 0 0 1 ${r},0.5 Z`;68 };6970 return (71 <>72 <style>73 {`74 @keyframes dash-flow {75 to {76 stroke-dashoffset: -10;77 }78 }79 `}80 </style>81 <div className="relative inline-block group pointer-events-none">82 <div83 className="absolute inset-[2px] group-hover:inset-0 pointer-events-none opacity-0 group-hover:opacity-100 transition-all ease-out duration-200 z-10"84 style={{ borderRadius: `${radius}px` }}85 >86 <svg87 width={dimensions.width}88 height={dimensions.height}89 viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}90 aria-hidden="true"91// … truncated
Files it writes
More from spell-ui
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Checkboxanimated-checkbox | spell-ui | Components | Free | 1 dep | |
| Animated Gradientanimated-gradient | spell-ui | Components | Free | no deps | |
| Badgebadge | spell-ui | Components | Free | 2 deps | |
| Bars Spinnerbars-spinner | spell-ui | Components | Free | no deps | |
| Blur Revealblur-reveal | spell-ui | Components | Free | 1 dep | |
| Chartchart | spell-ui | Components | Free | no deps | |
| Color Selectorcolor-selector | spell-ui | Components | Free | no deps | |
| Copy Buttoncopy-button | spell-ui | Components | Free | 1 dep |
