diff --git a/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarousel.tsx b/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarousel.tsx new file mode 100644 index 000000000000..9b85b4ec4646 --- /dev/null +++ b/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarousel.tsx @@ -0,0 +1,43 @@ +import React, { PropsWithChildren, useCallback, useEffect, useState } from 'react'; +import useEmblaCarousel, { EmblaCarouselType, EmblaOptionsType } from 'embla-carousel-react'; +import CFDCompareAccountsCarouselButton from './CompareAccountsCarouselButton'; + +const CompareAccountsCarousel = ({ children }: PropsWithChildren) => { + const options: EmblaOptionsType = { + align: 0, + containScroll: 'trimSnaps', + }; + const [emblaRef, emblaApi] = useEmblaCarousel(options); + const [prevBtnEnabled, setPrevBtnEnabled] = useState(false); + const [nextBtnEnabled, setNextBtnEnabled] = useState(false); + + const scrollPrev = useCallback(() => emblaApi?.scrollPrev(), [emblaApi]); + const scrollNext = useCallback(() => emblaApi?.scrollNext(), [emblaApi]); + + const onSelect = useCallback((emblaApi: EmblaCarouselType) => { + setPrevBtnEnabled(emblaApi.canScrollPrev()); + setNextBtnEnabled(emblaApi.canScrollNext()); + }, []); + + useEffect(() => { + if (!emblaApi) return; + + onSelect(emblaApi); + emblaApi.on('reInit', onSelect); + emblaApi.on('select', onSelect); + }, [emblaApi, onSelect]); + + return ( +
+
+
+ {children} +
+
+ + +
+ ); +}; + +export default CompareAccountsCarousel; diff --git a/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarouselButton.tsx b/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarouselButton.tsx new file mode 100644 index 000000000000..f8898a4b87f9 --- /dev/null +++ b/packages/tradershub/src/features/cfd/components/CompareAccountsCarousel/CompareAccountsCarouselButton.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { IconButton, qtMerge } from '@deriv/quill-design'; +import { LabelPairedChevronLeftMdRegularIcon, LabelPairedChevronRightMdRegularIcon } from '@deriv/quill-icons'; + +type TPrevNextButtonProps = { + enabled: boolean; + isNext?: boolean; + onClick: () => void; +}; + +const CFDCompareAccountsCarouselButton = ({ enabled, isNext = false, onClick }: TPrevNextButtonProps) => ( +