Files
blitzkit/packages/website/src/components/Gallery/Card.tsx
T

104 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-09-27 16:07:45 -05:00
import { asset, Avatar } from "@blitzkit/core";
import { Cross1Icon, DownloadIcon } from "@radix-ui/react-icons";
2024-10-24 18:21:37 -05:00
import {
Dialog,
Flex,
IconButton,
Link,
Skeleton,
Text,
2025-09-27 16:07:45 -05:00
} from "@radix-ui/themes";
import { useRef } from "react";
import { useIntersection } from "../../hooks/useIntersection";
import { useLocale } from "../../hooks/useLocale";
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
2024-10-24 17:46:02 -05:00
type GalleryCardProps = MaybeSkeletonComponentProps<{
2025-04-20 20:49:54 -05:00
avatar: Avatar;
2024-10-24 17:46:02 -05:00
}>;
export function GalleryCard(props: GalleryCardProps) {
2025-04-20 20:49:54 -05:00
const src = asset(
2026-03-31 14:11:45 -05:00
`gallery/avatars/${!props.skeleton && `${props.avatar.id}${props.avatar.extension}`}`,
2025-04-20 20:49:54 -05:00
);
2025-09-27 16:07:45 -05:00
const card = useRef<HTMLDivElement>(null!);
2025-04-20 20:49:54 -05:00
const { unwrap } = useLocale();
2024-10-24 17:46:02 -05:00
useIntersection(() => props.skeleton && props.onIntersection?.(), card, {
disabled: !props.skeleton || props.onIntersection === undefined,
});
2024-10-24 18:21:37 -05:00
const content = (
<Flex
direction="column"
align="center"
width="6rem"
gap="1"
ref={card}
2025-09-27 16:07:45 -05:00
style={{ cursor: "pointer" }}
2024-10-24 18:21:37 -05:00
>
2024-10-24 17:46:02 -05:00
{props.skeleton && (
<>
<Skeleton width="100%" height="4.57rem" />
<Skeleton width="100%" height="1em" />
</>
)}
{!props.skeleton && (
<>
<img
style={{
2025-09-27 16:07:45 -05:00
width: "4rem",
height: "4.57rem",
2024-10-24 17:46:02 -05:00
// aspect ratio 7 / 8
2025-09-27 16:07:45 -05:00
objectFit: "cover",
2024-10-24 17:46:02 -05:00
}}
2024-10-24 18:21:37 -05:00
src={src}
2026-03-31 14:11:45 -05:00
alt={unwrap(props.avatar.name!)}
2024-10-24 17:46:02 -05:00
/>
2025-09-27 16:07:45 -05:00
<Text size="1" align="center" style={{ maxWidth: "100%" }}>
2026-03-31 14:11:45 -05:00
{unwrap(props.avatar.name!)}
2024-10-24 17:46:02 -05:00
</Text>
</>
)}
</Flex>
);
2024-10-24 18:21:37 -05:00
if (props.skeleton) return content;
return (
<Dialog.Root>
<Dialog.Trigger>{content}</Dialog.Trigger>
<Dialog.Content
onOpenAutoFocus={(event) => event.preventDefault()}
width="fit-content"
>
<Flex position="absolute" top="3" right="3" gap="3">
<Link download href={src}>
<IconButton variant="ghost">
<DownloadIcon />
</IconButton>
</Link>
<Dialog.Close>
<IconButton variant="ghost">
<Cross1Icon />
</IconButton>
</Dialog.Close>
</Flex>
2024-10-24 18:23:38 -05:00
<Flex px="4" justify="center" mt="3">
2026-03-31 14:11:45 -05:00
<img src={src} alt={unwrap(props.avatar.name!)} />
2024-10-24 18:21:37 -05:00
</Flex>
<Flex justify="center" mt="4">
2025-09-27 16:07:45 -05:00
<Dialog.Title align="center" style={{ maxWidth: "10rem" }}>
2026-03-31 14:11:45 -05:00
{unwrap(props.avatar.name!)}
2024-10-24 18:21:37 -05:00
</Dialog.Title>
</Flex>
</Dialog.Content>
</Dialog.Root>
);
2024-10-24 17:46:02 -05:00
}