Files
supabase/apps/www/components/ImageFadeStack.tsx
T
Ivan VasilovandJoshen Lim 05a542ccea chore: Migrate all feather icons to lucide icons (#29038)
* Add lucide-react to docs (to make the autocomplete work).

* Migrate the docs app icons.

* Migrate the ui-patterns.

* Remove the old icons from ui package.

* Migrate the www app from react-feather icons.

* Migrate all of studio icons.

* Migrate the only component in design-system.

* Fix an old import in ui package. Revert an import in docs app.

* Fix some pages in www.

* Remove unneeded files used in generation of icons.

* Fix a prettier error.

* Fix more issues in www.

* Fix an issue in Log Date picker.

* Replace all string sizes with number sizes because the icons grew in some cases.

* Fix more imports in security page.

* Fix an extra import.

* Remove the size prop from all icons if they're in a button and they match the button size.

* Minor fixes for docs and www.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-09-04 19:46:21 +08:00

82 lines
2.2 KiB
TypeScript

import { PauseCircle, PlayCircle } from 'lucide-react'
import Image from 'next/image'
import { useEffect, useState } from 'react'
import { cn } from 'ui'
interface ImageFadeStackProps {
autoplay?: boolean
images: string[]
height?: 'default'
delay?: number
altText?: string
showNavigation?: boolean
}
const ImageFadeStack = ({
images,
height = 'default',
delay = 3000,
autoplay = false,
altText = 'Image',
showNavigation = false,
}: ImageFadeStackProps) => {
const [currentImageIndex, setCurrentImageIndex] = useState(0)
const [isPlaying, setIsPlaying] = useState(autoplay)
useEffect(() => {
if (isPlaying) {
const intervalId = setInterval(() => {
setCurrentImageIndex((prevIndex) => (prevIndex + 1) % images.length)
}, delay)
return () => clearInterval(intervalId)
}
}, [images, isPlaying])
function handleNavClick(index: number) {
setIsPlaying(false)
setCurrentImageIndex(index)
}
return (
<div className={`relative ${height === 'default' ? 'h-[300px]' : 'h-[400px]'} my-6`}>
{images.map((image, index) => (
<>
<Image
className="absolute top-0 left-0"
key={index}
src={image}
layout="fill"
alt={altText}
style={{
opacity: currentImageIndex === index ? 1 : 0,
transition: 'opacity 1s ease-in-out',
}}
/>
</>
))}
<div className="absolute bottom-4 right-4 flex gap-3">
{showNavigation &&
images.map((_, index) => (
<button className="text-white" onClick={() => handleNavClick(index)}>
<div
className={cn(
'w-2 h-2 rounded-full bg-foreground-muted hover:bg-surface-100 transition-colors',
currentImageIndex === index && 'bg-border-strong'
)}
/>
</button>
))}
<button
onClick={() => setIsPlaying(!isPlaying)}
className="text-white bg-foreground-light hover:bg-overlay rounded-full p-0.5 transition-colors"
>
{isPlaying ? <PauseCircle size={12} /> : <PlayCircle size={12} />}
</button>
</div>
</div>
)
}
export default ImageFadeStack