This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/web/components/ImageCarousel.tsx
caelum0x 50d986473e feat: round-6 external harvest (19 more features, all products green)
- gitgram-web (4): per-image alt-text accessibility, "New posts" load-latest pill
- gitgram-backend (1): per-user muted words/tags moderation (MutedWord model + matcher)
- gitgram-mobile (4): swipe-to-action list rows, soft-reset event bus (tap tab scroll-top)
- aitm-api (7): gitnexus api_impact blast-radius/risk endpoints (reuse vendored gitnexus)
- aitm-mcp (3): MCP handshake instructions, context-efficient beads output projections

Note: gitgram-backend adds MutedWord Prisma model — run prisma migrate at deploy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 19:04:16 +03:00

68 lines
2.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useState } from 'react';
interface ImageCarouselProps {
images: string[];
/** Per-image alt text, parallel to `images`. Falls back to empty when absent. */
alts?: string[];
}
/**
* Resolve the alt text for the image at `index`. Returns the author-supplied
* description when present, otherwise an empty string so screen readers treat
* the image as decorative rather than announcing a meaningless filename.
*/
function altFor(alts: string[] | undefined, index: number): string {
return alts?.[index]?.trim() || '';
}
export default function ImageCarousel({ images, alts }: ImageCarouselProps) {
const [current, setCurrent] = useState(0);
if (!images || images.length === 0) return null;
if (images.length === 1) {
return <img src={images[0]} alt={altFor(alts, 0)} className="w-full" />;
}
const next = () => setCurrent((i) => (i + 1) % images.length);
const prev = () => setCurrent((i) => (i - 1 + images.length) % images.length);
return (
<div className="relative">
<img src={images[current]} alt={altFor(alts, current)} className="w-full" />
{current > 0 && (
<button
onClick={prev}
aria-label="Previous image"
className="absolute left-2 top-1/2 -translate-y-1/2 bg-black/50 text-white rounded-full w-8 h-8 flex items-center justify-center hover:bg-black/70"
>
‹
</button>
)}
{current < images.length - 1 && (
<button
onClick={next}
aria-label="Next image"
className="absolute right-2 top-1/2 -translate-y-1/2 bg-black/50 text-white rounded-full w-8 h-8 flex items-center justify-center hover:bg-black/70"
>
›
</button>
)}
<div className="absolute bottom-2 left-1/2 -translate-x-1/2 flex gap-1">
{images.map((_, i) => (
<div
key={i}
className={`w-1.5 h-1.5 rounded-full ${
i === current ? 'bg-white' : 'bg-white/50'
}`}
/>
))}
</div>
</div>
);
}