Skip to content

Commit b429b67

Browse files
committed
done Slider
1 parent 5c7f022 commit b429b67

File tree

6 files changed

+123
-9
lines changed

6 files changed

+123
-9
lines changed

07-slider/src/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom/client';
3-
import './index.css';
4-
import App from './App';
5-
import Alternative from './Alternative';
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
import "./index.css";
4+
import App from "./App";
65

7-
const root = ReactDOM.createRoot(document.getElementById('root'));
6+
const root = ReactDOM.createRoot(document.getElementById("root"));
87
root.render(
98
<React.StrictMode>
109
<App />

src/challanges/03-reviews/Review.jsx

-3
This file was deleted.

src/challanges/07-slider/Slider.jsx

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import ContainerPage from "../../components/ContainerPage";
2+
import { FaAngleRight } from "react-icons/fa6";
3+
import { FaAngleLeft } from "react-icons/fa6";
4+
import { FaQuoteRight } from "react-icons/fa6";
5+
import people from "./data";
6+
import { useEffect, useState } from "react";
7+
8+
const classButton =
9+
"absolute top-1/2 transform -translate-y-1/2 cursor-pointer w-8 h-8 bg-gray-600 text-white rounded-md";
10+
11+
export default function Slider() {
12+
const [currentIndex, setCurrentIndex] = useState(0);
13+
14+
const checkNum = (num) => {
15+
if (num > people.length - 1) return 0;
16+
if (num < 0) return people.length - 1;
17+
return num;
18+
};
19+
20+
const nextSlide = () => setCurrentIndex((prev) => checkNum(prev + 1));
21+
const prevSlide = () => setCurrentIndex((prev) => checkNum(prev - 1));
22+
23+
useEffect(() => {
24+
const slideInterval = setInterval(
25+
() => setCurrentIndex((prev) => checkNum(prev + 1)),
26+
3000
27+
);
28+
return () => clearInterval(slideInterval);
29+
}, [currentIndex]);
30+
31+
return (
32+
<ContainerPage>
33+
<div className="w-3/4 mt-10 mx-auto relative overflow-x-hidden flex">
34+
<div
35+
className="flex transition-all duration-500 ease-in-out"
36+
style={{ transform: `translateX(-${currentIndex * 100}%)` }}
37+
>
38+
{people.map((item) => {
39+
return (
40+
<div
41+
className="flex flex-col items-center justify-center gap-2 min-w-full px-16"
42+
key={item.id}
43+
>
44+
<div className="border-4 border-gray-300 rounded-full overflow-hidden">
45+
<img
46+
className="w-26 h-26 object-cover"
47+
src={item.image}
48+
alt={`pic-${item.name}`}
49+
/>
50+
</div>
51+
<h2 className="text-blue-400 capitalize tracking-wider text-2xl">
52+
{item.name}
53+
</h2>
54+
<p className="capitalize text-gray-700 mb-4">{item.title}</p>
55+
<p className="text-center text-gray-500">{item.quote}</p>
56+
<FaQuoteRight className="text-6xl text-blue-400" />
57+
</div>
58+
);
59+
})}
60+
</div>
61+
<button className={`${classButton} right-0`} onClick={nextSlide}>
62+
<FaAngleRight className="text-2xl mx-auto" />
63+
</button>
64+
<button className={`${classButton} left-0`} onClick={prevSlide}>
65+
<FaAngleLeft className="text-2xl mx-auto " />
66+
</button>
67+
</div>
68+
</ContainerPage>
69+
);
70+
}

src/challanges/07-slider/data.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const people = [
2+
{
3+
id: 1,
4+
image:
5+
"https://res.cloudinary.com/diqqf3eq2/image/upload/v1595959131/person-2_ipcjws.jpg",
6+
name: "maria ferguson",
7+
title: "office manager",
8+
quote:
9+
"Fingerstache umami squid, kinfolk subway tile selvage tumblr man braid viral kombucha gentrify fanny pack raclette pok pok mustache.",
10+
},
11+
{
12+
id: 2,
13+
image:
14+
"https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883417/person-3_ipa0mj.jpg",
15+
name: "john doe",
16+
title: "regular guy",
17+
quote:
18+
"Gastropub sustainable tousled prism occupy. Viral XOXO roof party brunch actually, chambray listicle microdosing put a bird on it paleo subway tile squid umami.",
19+
},
20+
{
21+
id: 3,
22+
image:
23+
"https://res.cloudinary.com/diqqf3eq2/image/upload/v1595959121/person-1_aufeoq.jpg",
24+
name: "peter smith",
25+
title: "product designer",
26+
quote:
27+
"Drinking vinegar polaroid street art echo park, actually semiotics next level butcher master cleanse hammock flexitarian ethical paleo.",
28+
},
29+
{
30+
id: 4,
31+
image:
32+
"https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883334/person-1_rfzshl.jpg",
33+
name: "susan andersen",
34+
title: "the boss",
35+
quote:
36+
"Marfa af yr 3 wolf moon kogi, readymade distillery asymmetrical seitan kale chips fingerstache cloud bread mustache twee messenger bag. ",
37+
},
38+
];
39+
40+
export default people;

src/routes/router.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Accordion from "../challanges/04-accordion-I/Accordion";
77
import AccordionII from "../challanges/05-accordion-II/AccordionII";
88
import Menu from "../challanges/06-menu/Menu";
99
import Tabs from "../challanges/06-tabs/Tabs";
10+
import Slider from "../challanges/07-slider/Slider";
1011

1112
const router = createBrowserRouter([
1213
{
@@ -42,6 +43,10 @@ const router = createBrowserRouter([
4243
path: "/tabs",
4344
element: <Tabs />,
4445
},
46+
{
47+
path: "/slider",
48+
element: <Slider />,
49+
},
4550
]);
4651

4752
export default router;

src/sections/home/Home.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export default function Home() {
2424
<Link to="/tabs" className="underline text-blue-500">
2525
Tabs
2626
</Link>
27+
<Link to="/slider" className="underline text-blue-500">
28+
Slider
29+
</Link>
2730
</div>
2831
);
2932
}

0 commit comments

Comments
 (0)