import React, { useEffect, useState } from "react"; import clsx from "clsx"; const rotationDuration = 3800; const bezier = "cubic-bezier(0.645,0.045,0.355,1)"; 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; }) { let animate = ""; if (props.rotation) { animate = `animate-[coin-${getFront(props.lastFront)}-${getFront( props.front, )}_${rotationDuration / 1000}s_${bezier}]`; } return (
); } function getFront(front: boolean): string { return front ? "front" : "back"; } export default Coin;