import type { CSSProperties } from "react"; import { createPortal } from "react-dom"; import { AUCTION_REACTIONS, type ActiveAuctionReaction, } from "../api/auction-reactions"; import "./auction-reactions.css"; function reactionStyle(id: string): CSSProperties { let hash = 0; for (const character of id) hash = (hash * 31 + character.charCodeAt(0)) >>> 0; return { "--reaction-left": `${8 + (hash % 78)}%`, "--reaction-drift": `${(hash % 65) - 32}px`, "--reaction-tilt": `${(hash % 21) - 10}deg`, } as CSSProperties; } export function AuctionReactionLayer({ reactions, }: { reactions: ActiveAuctionReaction[]; }) { if (typeof document === "undefined") return null; const latest = reactions.at(-1); return createPortal( <>
{latest ? `${latest.displayName}님의 ${AUCTION_REACTIONS[latest.kind].label} 반응` : ""} >, document.body, ); }