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

100 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-10-24 18:21:37 -05:00
import { Cross1Icon, DownloadIcon } from '@radix-ui/react-icons';
import {
Dialog,
Flex,
IconButton,
Link,
Skeleton,
Text,
} from '@radix-ui/themes';
2024-10-24 17:46:02 -05:00
import { useRef } from 'react';
import { useIntersection } from '../../hooks/useIntersection';
import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps';
type GalleryCardProps = MaybeSkeletonComponentProps<{
id: string;
name: string;
}>;
export function GalleryCard(props: GalleryCardProps) {
2024-10-24 18:21:37 -05:00
const src = `/api/gallery/${!props.skeleton && props.id}.webp`;
2024-10-24 17:46:02 -05:00
const card = useRef<HTMLDivElement>(null);
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}
style={{ cursor: 'pointer' }}
>
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={{
width: '4rem',
height: '4.57rem',
// aspect ratio 7 / 8
objectFit: 'cover',
}}
2024-10-24 18:21:37 -05:00
src={src}
alt={props.name}
2024-10-24 17:46:02 -05:00
/>
2024-10-24 18:21:37 -05:00
<Text size="1" align="center" style={{ maxWidth: '100%' }}>
2024-10-24 17:46:02 -05:00
{props.name}
</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">
2024-10-24 18:21:37 -05:00
<img src={src} alt={props.name} />
</Flex>
<Flex justify="center" mt="4">
<Dialog.Title align="center" style={{ maxWidth: '10rem' }}>
{props.name}
</Dialog.Title>
</Flex>
</Dialog.Content>
</Dialog.Root>
);
2024-10-24 17:46:02 -05:00
}