components/linyi/ink-ring.tsx
motion
"use client"; import * as React from "react";import { motion, useReducedMotion } from "motion/react";import { cn } from "@/lib/cn"; export interface InkRingProps { /** px */ size?: number; /** dense 浓墨 · light 淡墨 */ tone?: "dense" | "light"; /** Accessible label. */ label?: string; className?: string;} /** * 墨圈 —— a loading ring drawn with one brush stroke and a dry-brush tail. */export function InkRing({ size = 44, tone = "dense", label = "加载中", className }: InkRingProps) { const id = React.useId().replace(/:/g, ""); const reduce = useReducedMotion(); const head = tone === "dense" ? "var(--ink-1)" : "var(--ink-3)"; const tail = tone === "dense" ? "var(--ink-3)" : "var(--ink-4)"; return ( <span role="status" aria-label={label} className={cn("inline-flex", className)}> <svg width={size} height={size} viewBox="0 0 48 48" aria-hidden="true"> <defs> <filter id={`ring-${id}`} x="-10%" y="-10%" width="120%" height="120%"> <feTurbulence type="fractalNoise" baseFrequency="1.1" numOctaves="2" seed="2" /> <feDisplacementMap in="SourceGraphic" scale="1.8" xChannelSelector="R" yChannelSelector="G" /> </filter> </defs> <motion.g animate={reduce ? undefined : { rotate: 360 }} transition={{ duration: 1.6, ease: "linear", repeat: Infinity }} > <g filter={`url(#ring-${id})`} fill="none" strokeLinecap="round"> <circle cx="24" cy="24" r="17" stroke={head} strokeWidth="4.2" strokeDasharray="72 35" /> <motion.circle cx="24" cy="24" r="17" stroke={tail} strokeWidth="2" strokeDasharray="1.5 3 1 4 0.8 6" opacity={0.8} initial={{ strokeDashoffset: -74 }} animate={reduce ? undefined : { strokeDashoffset: [-74, -56, -74] }} transition={{ duration: 1.6, ease: "easeInOut", repeat: Infinity }} /> </g> </motion.g> </svg> </span> );}