railyard/apps/ritgram/web/components/ImageCarousel.tsx
caelum0x f80b04ae0f feat(ritgram): move GitGram app into railyard as Ritgram, next to Rithub
Moved later/gitgram-ai/gitgram/ to apps/ritgram/ (fresh history; full history stays in caelum0x/gitgram).
AITimeMachine stays separate in later/gitgram-ai per the Rithub master plan.
Logs, pid files and env files are ignored; GPL-3.0 mobile/proximity noted in THIRD_PARTY_NOTICES.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 04:18:46 +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>
);
}