60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
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(
|
|
<>
|
|
<div className="auction-reaction-layer" aria-hidden="true">
|
|
{reactions.map((reaction) => (
|
|
<div
|
|
key={reaction.id}
|
|
className="auction-floating-reaction"
|
|
data-reaction-id={reaction.id}
|
|
style={reactionStyle(reaction.id)}
|
|
>
|
|
<span className="auction-floating-emoji">
|
|
{AUCTION_REACTIONS[reaction.kind].emoji}
|
|
</span>
|
|
<span className="auction-floating-name">
|
|
{reaction.displayName}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<span
|
|
className="sr-only"
|
|
role="status"
|
|
aria-live="polite"
|
|
aria-atomic="true"
|
|
>
|
|
{latest
|
|
? `${latest.displayName}님의 ${AUCTION_REACTIONS[latest.kind].label} 반응`
|
|
: ""}
|
|
</span>
|
|
</>,
|
|
document.body,
|
|
);
|
|
}
|