Files
blitzkit/packages/website-ue/src/components/AvatarCard/index.tsx
T

66 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-01-15 12:55:18 -06:00
import { literals } from "@blitzkit/i18n";
import { useStrings } from "../../hooks/useStrings";
2026-01-12 14:13:21 -06:00
import type { Avatar } from "../../protos/avatar";
2026-01-16 20:37:11 -06:00
import type { PropsWithSkeleton } from "../../types/propsWithSkeleton";
2026-01-15 12:55:18 -06:00
import { Badge } from "../Badge";
2026-01-16 20:37:11 -06:00
import { InlineSkeleton } from "../InlineSkeleton";
import { Skeleton } from "../Skeleton";
2026-01-12 14:13:21 -06:00
import { Text } from "../Text";
import "./index.css";
2026-01-14 13:58:53 -06:00
interface Props {
name: string;
avatars: Avatar[];
}
2026-01-13 13:30:09 -06:00
2026-01-14 13:58:53 -06:00
const MAX_CARDS = 3;
const CARD_TRIM = "var(--space-3)";
2026-01-16 20:37:11 -06:00
export function AvatarCard(props: PropsWithSkeleton<Props>) {
2026-01-12 14:13:21 -06:00
return (
<div className="avatar-card">
2026-01-16 20:37:11 -06:00
<Series skeleton={props.skeleton} {...props} />
2026-01-14 13:58:53 -06:00
2026-01-13 13:30:09 -06:00
<Text align="center" className="avatar-label">
2026-01-16 20:37:11 -06:00
{props.skeleton ? <InlineSkeleton /> : props.name}
2026-01-13 13:30:09 -06:00
</Text>
2026-01-12 14:13:21 -06:00
</div>
);
}
2026-01-14 13:58:53 -06:00
interface SeriesProps {
avatars: Avatar[];
}
2026-01-16 20:37:11 -06:00
function Series(props: PropsWithSkeleton<SeriesProps>) {
const count = Math.min(props.skeleton ? 0 : props.avatars.length, MAX_CARDS);
2026-01-15 12:55:18 -06:00
const strings = useStrings();
2026-01-14 13:58:53 -06:00
return (
<div className="avatar-series">
2026-01-16 20:37:11 -06:00
{!props.skeleton &&
props.avatars.slice(-MAX_CARDS).map((avatar, index) => (
<div
key={avatar.name}
className="avatar-entry"
style={{
filter: `brightness(${(index + 1) / count})`,
top: `calc(${index} * ${CARD_TRIM})`,
left: `calc(${index} * ${CARD_TRIM})`,
width: `calc(100% - ${CARD_TRIM} * ${count - 1})`,
height: `calc(100% - ${CARD_TRIM} * ${count - 1})`,
backgroundImage: `url(/api/avatars/${avatar.name}.webp)`,
}}
/>
))}
2026-01-15 12:55:18 -06:00
2026-01-16 20:37:11 -06:00
{!props.skeleton && props.avatars.length > 1 && (
2026-01-15 12:55:18 -06:00
<Badge color="gray" highContrast className="count">
2026-01-16 20:37:11 -06:00
{literals(strings.units.x, { value: props.avatars.length })}
2026-01-15 12:55:18 -06:00
</Badge>
)}
2026-01-16 20:37:11 -06:00
{props.skeleton && <Skeleton className="avatar-entry" />}
2026-01-14 13:58:53 -06:00
</div>
);
}