import React, { useEffect, useState } from "react"; import clsx from "clsx"; const rotationDuration = 3800; const COIN_ANIM: Record = { "front-front": "animate-coin-front-front", "front-back": "animate-coin-front-back", "back-front": "animate-coin-back-front", "back-back": "animate-coin-back-back", }; function Coin(props: { frontList: boolean[]; rotation: boolean; onTransitionEnd: () => void; }) { const [lastFront, setLastFront] = useState(props.frontList); useEffect(() => { if (!props.rotation) { return; } const id = setTimeout(() => { setLastFront(props.frontList); props.onTransitionEnd(); }, rotationDuration); return () => clearTimeout(id); }, [props.rotation, props.frontList, props.onTransitionEnd]); return (
{props.frontList.map((value, index) => ( ))}
); } /** 方孔铜钱造型 */ function CoinFace({ side }: { side: "front" | "back" }) { const isFront = side === "front"; return (
{isFront ? "乾" : "坤"}
); } function CoinItem(props: { front: boolean; lastFront: boolean; rotation: boolean; }) { const animKey = `${getFront(props.lastFront)}-${getFront(props.front)}`; const animClass = props.rotation ? COIN_ANIM[animKey] : ""; return (
); } function getFront(front: boolean): string { return front ? "front" : "back"; } export default Coin;