"use client"; import { useState, type ReactNode } from "react"; import { motion, useReducedMotion } from "motion/react"; type LiquidFlowProps = { children: ReactNode; className?: string; onClick?: () => void; /** Colour that floods the button. */ fill?: string; /** Label colour while the button is filled. */ fillText?: string; /** Seconds the flood takes. */ duration?: number; }; /* LiquidFlow: colour floods in from the exact point the pointer enters, and drains out where it leaves. */ export function LiquidFlow({ children, className = "rounded-full border border-[#a78bfa]/60 px-9 py-4 text-[15px] font-medium text-[#ede9fe]", onClick, fill = "#a78bfa", fillText = "#1a1530", duration = 0.5, }: LiquidFlowProps) { const reduce = useReducedMotion(); const [spot, setSpot] = useState({ x: 0, y: 0, r: 0, on: false }); const flood = (el: HTMLElement, x: number, y: number, on: boolean) => { const { width: w, height: h } = el.getBoundingClientRect(); // Radius that reaches the farthest corner from (x, y). const r = Math.hypot(Math.max(x, w - x), Math.max(y, h - y)); setSpot({ x, y, r, on }); }; const fromPointer = (e: React.PointerEvent, on: boolean) => { const b = e.currentTarget.getBoundingClientRect(); flood(e.currentTarget, e.clientX - b.left, e.clientY - b.top, on); }; const fromCentre = (e: React.FocusEvent, on: boolean) => { const b = e.currentTarget.getBoundingClientRect(); flood(e.currentTarget, b.width / 2, b.height / 2, on); }; return ( ); }