feat: implement banner component with carousel functionality and dynamic content

This commit is contained in:
fredy.siswanto 2025-03-03 13:42:01 +07:00
parent 1b4ff4c3e7
commit b42aa6c960
2 changed files with 51 additions and 11 deletions

View File

@ -1,21 +1,38 @@
import useEmblaCarousel from 'embla-carousel-react'
import { Link } from 'react-router'
import { APP } from '~/configs/meta'
import { BANNER } from '~/data/contents'
export const Banner = () => {
const [emblaReference] = useEmblaCarousel({ loop: false })
return (
<div className="min-h-[65px]">
<div className="">
<div className="relative">
<Link
to="/#"
className="mt-2 h-full py-2"
<div
className="embla overflow-hidden"
ref={emblaReference}
>
<img
src={'/images/banner.png'}
alt={APP.title}
className="h-[70px] w-[100%] content-center sm:h-full"
/>
</Link>
<div className="embla__container flex">
{BANNER.map(({ urlImage, alt, link }, index) => (
<div
key={index}
className="embla__slide max-h-[100px] min-h-[65px] w-full min-w-0 flex-none"
>
<Link
to={link}
className="mt-2 h-full py-2"
>
<img
src={urlImage}
alt={alt}
className="h-[70px] w-[100%] content-center sm:h-full"
/>
</Link>
</div>
))}
</div>
</div>
</div>
</div>
)

View File

@ -1,4 +1,9 @@
import type { TNews } from '~/types/news'
type TBanner = {
urlImage: string
alt: string
link: string
}
export const DUMMY_DESCRIPTION = 'Berita Terhangat hari ini'
@ -147,3 +152,21 @@ export const KAJIAN: TNews = {
},
],
}
export const BANNER: TBanner[] = [
{
urlImage: '/images/banner.png',
alt: 'banner',
link: '/category/spotlight',
},
{
urlImage: 'https://placehold.co/1000x65.png',
alt: 'banner',
link: '/#',
},
{
urlImage: '/images/banner.png',
alt: 'banner',
link: '/#',
},
]