-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into tr-hide-grace-period-input
- Loading branch information
Showing
17 changed files
with
731 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Carousel from "components/ui/Carousel"; | ||
import { CmsTopicHeader } from "lib/cms/topics"; | ||
import { chunk, isObject, isString } from "lodash-es"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
|
||
export const Topics = ({ | ||
topics, | ||
imagePlaceholders, | ||
selectedTopic, | ||
onClick, | ||
}: { | ||
topics: CmsTopicHeader[]; | ||
imagePlaceholders: string[]; | ||
selectedTopic?: CmsTopicHeader | string; | ||
onClick?: (topic: CmsTopicHeader) => void; | ||
}) => { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<> | ||
<div className="hidden w-full gap-3 md:flex"> | ||
{topics.map((topic, index) => ( | ||
<Link | ||
key={index} | ||
href={`/topics/${topic.slug}`} | ||
className={` | ||
ztg-transition flex flex-1 cursor-pointer items-center gap-4 rounded-lg p-3 transition-all md:max-w-sm md:hover:scale-[1.015] | ||
${ | ||
(isString(selectedTopic) && selectedTopic === topic.slug) || | ||
(isObject(selectedTopic) && selectedTopic.slug === topic.slug) | ||
? "bg-gray-200" | ||
: "bg-white" | ||
} | ||
`} | ||
onClick={(e) => { | ||
if (onClick) { | ||
e.preventDefault(); | ||
onClick(topic); | ||
} else { | ||
router.push(`/topics/${topic.slug}`); | ||
} | ||
}} | ||
> | ||
<div className="relative h-10 w-10"> | ||
<Image | ||
key={index} | ||
priority | ||
src={topic.thumbnail ?? ""} | ||
alt={`Image for topic ${topic.title}`} | ||
placeholder="blur" | ||
blurDataURL={imagePlaceholders[index]} | ||
fill | ||
sizes="100vw" | ||
className="rounded-lg object-cover" | ||
style={{ | ||
objectFit: "cover", | ||
}} | ||
/> | ||
</div> | ||
<div> | ||
<h3 className="font-base text-sm text-gray-800">{topic.title}</h3> | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
<div className="relative block w-full md:hidden"> | ||
<Carousel | ||
options={{ align: "start", duration: 10 }} | ||
slides={chunk(topics, 3).map((topics, index) => ( | ||
<div className="flex gap-2"> | ||
{topics.map((topic, index) => ( | ||
<Link | ||
href={`/topics/${topic.slug}`} | ||
key={index} | ||
className="flex flex-1 cursor-pointer items-center gap-4 rounded-lg bg-white p-2 transition-all hover:bg-gray-200 hover:bg-opacity-30 md:max-w-sm" | ||
> | ||
<div className="relative h-10 w-10"> | ||
<Image | ||
key={index} | ||
priority | ||
src={topic.thumbnail ?? ""} | ||
alt={`Image for topic ${topic.title}`} | ||
placeholder="blur" | ||
blurDataURL={imagePlaceholders[index]} | ||
fill | ||
sizes="100vw" | ||
className="rounded-lg object-cover" | ||
style={{ | ||
objectFit: "cover", | ||
}} | ||
/> | ||
</div> | ||
<div> | ||
<h3 className="font-base text-sm text-gray-800"> | ||
{topic.title} | ||
</h3> | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
))} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import React, { ReactNode, useCallback, useEffect, useState } from "react"; | ||
import { EmblaCarouselType, EmblaOptionsType } from "embla-carousel"; | ||
import useEmblaCarousel from "embla-carousel-react"; | ||
import { ChevronLeft, ChevronRight } from "react-feather"; | ||
|
||
type CarouselProps = { | ||
slides: Array<ReactNode>; | ||
options?: EmblaOptionsType; | ||
}; | ||
|
||
const Carousel: React.FC<CarouselProps> = (props) => { | ||
const { slides, options } = props; | ||
const [emblaRef, emblaApi] = useEmblaCarousel(options); | ||
|
||
const { | ||
prevBtnDisabled, | ||
nextBtnDisabled, | ||
onPrevButtonClick, | ||
onNextButtonClick, | ||
} = usePrevNextButtons(emblaApi); | ||
|
||
return ( | ||
<div> | ||
<div className="mb-2 flex items-center justify-end gap-1"> | ||
<button | ||
onClick={onPrevButtonClick} | ||
className={`ztg-transition ml-[12px] mr-[8px] flex h-[18px] w-[18px] items-center justify-center rounded-full ${ | ||
prevBtnDisabled ? "text-pastel-blue opacity-30" : " text-gray-700" | ||
}`} | ||
disabled={prevBtnDisabled} | ||
> | ||
<ChevronLeft className="relative right-[1px]" /> | ||
</button> | ||
<button | ||
onClick={onNextButtonClick} | ||
className={`ztg-transition flex h-[18px] w-[18px] items-center justify-center rounded-full ${ | ||
nextBtnDisabled ? "text-pastel-blue opacity-30" : "text-gray-700" | ||
}`} | ||
disabled={nextBtnDisabled} | ||
> | ||
<ChevronRight className="relative left-[1px]" /> | ||
</button> | ||
</div> | ||
|
||
<div className="embla"> | ||
<div className="embla__viewport" ref={emblaRef}> | ||
<div className="embla__container"> | ||
{slides.map((slide, index) => ( | ||
<div className="embla__slide" key={index}> | ||
<div className="embla__slide__number"> | ||
<span>{slide}</span> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
type UsePrevNextButtonsType = { | ||
prevBtnDisabled: boolean; | ||
nextBtnDisabled: boolean; | ||
onPrevButtonClick: () => void; | ||
onNextButtonClick: () => void; | ||
}; | ||
|
||
export const usePrevNextButtons = ( | ||
emblaApi: EmblaCarouselType | undefined, | ||
): UsePrevNextButtonsType => { | ||
const [prevBtnDisabled, setPrevBtnDisabled] = useState(true); | ||
const [nextBtnDisabled, setNextBtnDisabled] = useState(true); | ||
|
||
const onPrevButtonClick = useCallback(() => { | ||
if (!emblaApi) return; | ||
emblaApi.scrollPrev(); | ||
}, [emblaApi]); | ||
|
||
const onNextButtonClick = useCallback(() => { | ||
if (!emblaApi) return; | ||
emblaApi.scrollNext(); | ||
}, [emblaApi]); | ||
|
||
const onSelect = useCallback((emblaApi: EmblaCarouselType) => { | ||
setPrevBtnDisabled(!emblaApi.canScrollPrev()); | ||
setNextBtnDisabled(!emblaApi.canScrollNext()); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!emblaApi) return; | ||
|
||
onSelect(emblaApi); | ||
emblaApi.on("reInit", onSelect); | ||
emblaApi.on("select", onSelect); | ||
}, [emblaApi, onSelect]); | ||
|
||
return { | ||
prevBtnDisabled, | ||
nextBtnDisabled, | ||
onPrevButtonClick, | ||
onNextButtonClick, | ||
}; | ||
}; | ||
|
||
export default Carousel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.