diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-22 15:51:50 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-22 15:51:50 +0700 |
| commit | 8080c415e466ce29d0f7c29284c3a8537c6b237d (patch) | |
| tree | 6c98a85efa39b63a7c13d0051fb48abb5e7711d0 /src/components | |
| parent | dfe8b63a901350aee7d9024524bc50529159b8b9 (diff) | |
add animate on load for smooth render
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/ui/AnimateOnLoad.jsx | 25 | ||||
| -rw-r--r-- | src/components/ui/HeroBanner.jsx | 25 | ||||
| -rw-r--r-- | src/components/ui/HeroBannerSecondary.jsx | 21 | ||||
| -rw-r--r-- | src/components/ui/PopularProduct.jsx | 5 |
4 files changed, 55 insertions, 21 deletions
diff --git a/src/components/ui/AnimateOnLoad.jsx b/src/components/ui/AnimateOnLoad.jsx new file mode 100644 index 00000000..fb9919e1 --- /dev/null +++ b/src/components/ui/AnimateOnLoad.jsx @@ -0,0 +1,25 @@ +import classNames from 'classnames' +import { motion } from 'framer-motion' + +/** + * Animate On Load + * @param {object} props + * @param {string} props.className - Container class + */ +const AnimateOnLoad = (props) => { + const { className: propsClassName, children } = props + + const combinedClassName = classNames(propsClassName) + + return ( + <motion.div + initial={{ opacity: 0 }} + animate={{ opacity: 1, transition: { duration: 0.3 } }} + className={combinedClassName} + > + {children} + </motion.div> + ) +} + +export default AnimateOnLoad diff --git a/src/components/ui/HeroBanner.jsx b/src/components/ui/HeroBanner.jsx index 96bd8917..746de778 100644 --- a/src/components/ui/HeroBanner.jsx +++ b/src/components/ui/HeroBanner.jsx @@ -1,16 +1,19 @@ -import DesktopView from '@/core/components/views/DesktopView' -import MobileView from '@/core/components/views/MobileView' +// Swiper import { Swiper, SwiperSlide } from 'swiper/react' import { Pagination, Autoplay } from 'swiper' import 'swiper/css' import 'swiper/css/pagination' import 'swiper/css/autoplay' + +import DesktopView from '@/core/components/views/DesktopView' +import MobileView from '@/core/components/views/MobileView' import { useMemo } from 'react' import Link from '@/core/components/elements/Link/Link' import Image from '@/core/components/elements/Image/Image' import { useQuery } from 'react-query' import { bannerApi } from '@/api/bannerApi' import { HeroBannerSkeleton } from '../skeleton/BannerSkeleton' +import AnimateOnLoad from './AnimateOnLoad' const swiperBanner = { autoplay: { @@ -49,15 +52,17 @@ const HeroBanner = () => { if (heroBanner.isLoading) return <HeroBannerSkeleton /> return ( - <> - <MobileView> - <Swiper {...swiperBannerMobile}>{BannerComponent}</Swiper> - </MobileView> + heroBanner.data && ( + <AnimateOnLoad> + <MobileView> + <Swiper {...swiperBannerMobile}>{BannerComponent}</Swiper> + </MobileView> - <DesktopView> - <Swiper {...swiperBannerDesktop}>{BannerComponent}</Swiper> - </DesktopView> - </> + <DesktopView> + <Swiper {...swiperBannerDesktop}>{BannerComponent}</Swiper> + </DesktopView> + </AnimateOnLoad> + ) ) } diff --git a/src/components/ui/HeroBannerSecondary.jsx b/src/components/ui/HeroBannerSecondary.jsx index b1023990..50db69f8 100644 --- a/src/components/ui/HeroBannerSecondary.jsx +++ b/src/components/ui/HeroBannerSecondary.jsx @@ -5,6 +5,7 @@ import { useMemo } from 'react' import { useQuery } from 'react-query' import { HeroBannerSkeleton } from '../skeleton/BannerSkeleton' import { bannerApi } from '@/api/bannerApi' +import AnimateOnLoad from './AnimateOnLoad' const HeroBannerSecondary = () => { const heroBannerSecondary = useQuery('heroBannerSecondary', bannerApi({ type: 'index-a-2' })) @@ -19,15 +20,17 @@ const HeroBannerSecondary = () => { return ( heroBannerSecondary.data && ( - <Link href={heroBannerSecondary.data[randomIndex].url} className='h-full'> - <Image - src={heroBannerSecondary.data[randomIndex].image} - width={512} - height={1024} - alt={heroBannerSecondary.data[randomIndex].name} - className='object-cover object-center h-full' - /> - </Link> + <AnimateOnLoad className='h-full'> + <Link href={heroBannerSecondary.data[randomIndex].url} className='h-full'> + <Image + src={heroBannerSecondary.data[randomIndex].image} + width={512} + height={1024} + alt={heroBannerSecondary.data[randomIndex].name} + className='object-cover object-center h-full' + /> + </Link> + </AnimateOnLoad> ) ) } diff --git a/src/components/ui/PopularProduct.jsx b/src/components/ui/PopularProduct.jsx index 211291c8..9ca3e4ea 100644 --- a/src/components/ui/PopularProduct.jsx +++ b/src/components/ui/PopularProduct.jsx @@ -5,6 +5,7 @@ import { useQuery } from 'react-query' import { PopularProductSkeleton } from '../skeleton/PopularProductSkeleton' import DesktopView from '@/core/components/views/DesktopView' import ProductCard from '@/lib/product/components/ProductCard' +import AnimateOnLoad from './AnimateOnLoad' const PopularProduct = () => { const popularProduct = useQuery('popularProduct', popularProductApi()) @@ -13,7 +14,7 @@ const PopularProduct = () => { return ( popularProduct.data && ( - <> + <AnimateOnLoad className='h-full'> <MobileView> <div className='px-4'> <div className='font-medium mb-4'>Produk Banyak Dilihat</div> @@ -36,7 +37,7 @@ const PopularProduct = () => { </div> </div> </DesktopView> - </> + </AnimateOnLoad> ) ) } |
