Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchayan721 committed Sep 1, 2023
1 parent 379f10d commit 3eeadea
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 99 deletions.
21 changes: 21 additions & 0 deletions src/components/Carousel/DynamicSlides/CarouselDataCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Card, alpha, styled } from "@mui/material";

const CarouselDataCard = styled(Card)(({ theme }) => ({
position: 'absolute',
bottom: 50,
left: 50,
right: 0,
height: 'max-content',
width: 'max-content',
minWidth: '25rem',
padding: theme.Spaces.md,
backgroundColor: alpha(theme.palette.background.default, 0.5),
backdropFilter: 'blur(0.25rem)',
color: theme.palette.text.primary,
transition: theme.Transitions.createTransition({
property: 'transform',
duration: 'shortest',
}),
}));

export default CarouselDataCard;
47 changes: 47 additions & 0 deletions src/components/Carousel/DynamicSlides/UnitSlide.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import Image from 'next/image';
import { CarouselData } from '../carouselData';
import { styled } from '@mui/material';
import { SplideSlide } from '@splidejs/react-splide';
import '@splidejs/splide/dist/css/themes/splide-default.min.css';
import CarouselDataCard from './CarouselDataCard';


const StyledImage = styled(Image)(({ theme }) => ({
height: `calc(100dvh - ${theme.Heights.header.default})`,
width: '100%',
objectFit: 'cover',
}));



const DynamicSlide = ({ image, title, id, description, link, active }: CarouselData & { active?: boolean }) => {

let slideTitle = title;
let slideImage = image;
let slideId = id;
let slideKey = `slide-${id}`;

if (typeof window === 'undefined') {
slideTitle = 'Loading...';
slideImage = '/images/placeholder.png';
slideId = 0;
}

return (
<SplideSlide key={slideKey}>
<StyledImage
width="1920"
height="1080"
src={image}
alt={title}
/>
<CarouselDataCard className={active ? 'active' : ''}>
<h1>{title}</h1>
<p>{description}</p>
</CarouselDataCard>
</SplideSlide>
);
};

export default DynamicSlide;
63 changes: 63 additions & 0 deletions src/components/Carousel/DynamicSlides/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import dynamic from 'next/dynamic';
import carouselData from '../carouselData';
import DynamicSlide from './UnitSlide';
import '@splidejs/splide/dist/css/themes/splide-default.min.css';


const arrowPath = 'M15.71 3.854 13.685 5.951 28.153 19.923 13.858 34.074 15.91 36.146 32.315 19.904 15.71 3.854z';
const options = {
type: 'loop',
perPage: 1,
perMove: 1,
lazyLoad: 'nearby',
drag: 'free',
snap: true,
pagination: false,
arrows: true,
arrowPath,
autoplay: true,
pauseOnHover: true,
interval: 5000,
gap: '1rem',
padding: '9.5rem',
breakpoints: {
900: {
perPage: 2,
arrows: false,
},
768: {
perPage: 1,
arrows: false,
},
},
};

interface DynamicSplideProps {
options?: any;
children?: React.ReactNode;
onMove?: (splide: any, newIndex: number) => void;
};

// Explicitly naming the component
const DynamicSplide = dynamic<DynamicSplideProps>(() => import('@splidejs/react-splide').then((mod) => mod.Splide), {
ssr: false,
});

const DynamicSlides = () => {
return (
<DynamicSplide
options={options}
onMove={(splide, newIndex) => {
console.log('splide', splide);
console.log('moved', newIndex);
}}
>
{carouselData.map((slideData) => (
<DynamicSlide active {...slideData} />
))}
</DynamicSplide>
)
}

export default DynamicSlides
54 changes: 54 additions & 0 deletions src/components/Carousel/carouselData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export interface CarouselData {
id: number;
title: string;
description: string;
image: string;
link: string;
}

const carouselData : CarouselData[] = [
{
id: 1,
title: "First Slide",
description: "This is the first slide",
image: "/images/home/container-1/slide-1.jpg",
link: "/",
},
{
id: 2,
title: "Second Slide",
description: "This is the second slide",
image: "/images/home/container-1/slide-2.jpg",
link: "/",
},
{
id: 3,
title: "Third Slide",
description: "This is the third slide",
image: "/images/home/container-1/slide-3.jpg",
link: "/",
},
{
id: 4,
title: "Fourth Slide",
description: "This is the fourth slide",
image: "/images/home/container-1/slide-4.jpg",
link: "/",
},
{
id: 5,
title: "Fifth Slide",
description: "This is the fifth slide",
image: "/images/home/container-1/slide-5.jpg",
link: "/",
},
{
id: 6,
title: "Sixth Slide",
description: "This is the sixth slide",
image: "/images/home/container-1/slide-6.jpg",
link: "/",
},
];

export default carouselData;
105 changes: 6 additions & 99 deletions src/components/Carousel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { styled, alpha } from '@mui/material';
import React from 'react';
import { SplideSlide } from '@splidejs/react-splide';
import Image from 'next/image';
import '@splidejs/splide/dist/css/themes/splide-default.min.css';
import dynamic from 'next/dynamic';
import DynamicSlides from './DynamicSlides';

const StyledSplideWrapper = styled('div')(({ theme }) => ({
'& .splide__slide': {
Expand All @@ -14,17 +11,18 @@ const StyledSplideWrapper = styled('div')(({ theme }) => ({

'& .splide__arrow--prev, & .splide__arrow--next': {
zIndex: 1,
backgroundColor: theme.palette.background.default,
backgroundColor: alpha(theme.palette.background.default, 0.33),
backdropFilter: 'blur(0.33rem)',
fontSize: '1.25rem',
transform: 'translateY(-7rem)',
height: '10rem',
width: '6rem',
borderRadius: '1.618rem',
opacity: 0.5,
opacity: 1,
transition: 'all 0.3s ease-in-out',

'& path': {
fill: theme.palette.primary.main,
fill: theme.palette.text.primary,
},

'&::before': {
Expand All @@ -33,102 +31,11 @@ const StyledSplideWrapper = styled('div')(({ theme }) => ({
},
}));

const arrowPath = 'M15.71 3.854 13.685 5.951 28.153 19.923 13.858 34.074 15.91 36.146 32.315 19.904 15.71 3.854z';
const options = {
type: 'loop',
perPage: 1,
perMove: 1,
lazyLoad: 'nearby',
drag: 'free',
snap: true,
pagination: false,
arrows: true,
arrowPath,
autoplay: true,
pauseOnHover: true,
interval: 5000,
gap: '1rem',
padding: '9.5rem',
breakpoints: {
900: {
perPage: 2,
arrows: false,
},
768: {
perPage: 1,
arrows: false,
},
},
};

interface DynamicSplideProps {
options?: any;
children?: React.ReactNode;
};

// Explicitly naming the component
const DynamicSplide = dynamic<DynamicSplideProps>(() => import('@splidejs/react-splide').then((mod) => mod.Splide), {
ssr: false,
});


const StyledImage = styled(Image)(({ theme }) => ({
height: `calc(100dvh - ${theme.Heights.header.default})`,
width: '100%',
objectFit: 'cover',
}));

const Carousel = () => {

return (
<StyledSplideWrapper>
<DynamicSplide options={options}>
<SplideSlide>
<StyledImage
width="1920"
height="1080"
src="/images/home/container-1/slide-1.jpg"
alt="lol"
/>

</SplideSlide>
<SplideSlide>
<StyledImage
width="1920"
height="1080"
src="/images/home/container-1/slide-2.jpg"
alt="lol"
/>

</SplideSlide>
<SplideSlide>
<StyledImage
width="1920"
height="1080"
src="/images/home/container-1/slide-3.jpg"
alt="lol"
/>

</SplideSlide>
<SplideSlide>
<StyledImage
width="1920"
height="1080"
src="/images/home/container-1/slide-5.jpg"
alt="lol"
/>

</SplideSlide>
<SplideSlide>
<StyledImage
width="1920"
height="1080"
src="/images/home/container-1/slide-6.jpg"
alt="lol"
/>

</SplideSlide>
</DynamicSplide>
<DynamicSlides />
</StyledSplideWrapper>
);
};
Expand Down

0 comments on commit 3eeadea

Please sign in to comment.