返回 CodeWhale
route-whale.tsx
根目录 / web / components / route / route-whale.tsx
1 import { useId } from "react";
2 import whale from "@/vendor/whale-b/whale-b.json";
3
4 const GRADIENT_PARTS = new Set(["flukes", "dorsal", "body", "flipper"]);
5
6 export function RouteWhale() {
7 const gradient = `road-whale-${useId().replace(/[^a-z0-9]/gi, "")}`;
8 const { x1, y1, x2, y2 } = whale.gradient;
9 return (
10 <svg className="road-whale" viewBox={whale.viewBox} aria-hidden="true" focusable="false">
11 <defs>
12 <linearGradient id={gradient} gradientUnits="userSpaceOnUse" x1={x1} y1={y1} x2={x2} y2={y2}>
13 <stop className="road-whale-rise" />
14 <stop className="road-whale-deep" offset="1" />
15 </linearGradient>
16 </defs>
17 <g className="road-whale-swim">
18 {whale.paths.map((path) => (
19 <path
20 key={path.id}
21 d={path.d}
22 className={`road-whale-${path.id}`}
23 fill={GRADIENT_PARTS.has(path.id) ? `url(#${gradient})` : undefined}
24 />
25 ))}
26 </g>
27 </svg>
28 );
29 }
30
30 lines Plain Text