Skip to content

Commit 1b2f5d2

Browse files
authored
Fix carousel transition (#34)
1 parent 77b6728 commit 1b2f5d2

File tree

5 files changed

+159
-84
lines changed

5 files changed

+159
-84
lines changed

package-lock.json

Lines changed: 117 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"axios": "^1.3.5",
1515
"eslint": "^8.43.0",
1616
"eslint-config-react-app": "^7.0.1",
17+
"flowbite-react": "^0.6.4",
1718
"formik": "^2.2.9",
1819
"js-cookie": "^3.0.5",
1920
"jsonwebtoken": "^9.0.0",

src/App.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import RequiresAuth from "./components/RequiresAuth";
88
import { HomePageUser } from "./pages/HomePageUser";
99
import Navbar from "./components/Navbar/Navbar";
1010
import ContactForm from "./pages/Contact";
11-
import { Carousel } from "./components/Carousel/Carousel";
11+
import { DefaultCarousel } from "./components/Carousel/Carousel";
1212
import UserList from "./pages/Users";
1313

1414
function App() {
1515
return (
1616
<div className="bg-cover bg-gray-200 h-screen w-screen overflow-y-scroll">
1717
<PostProvider>
1818
<Navbar />
19-
<Carousel />
19+
2020
<Routes>
2121
{/* Public routes */}
2222
<Route path="signup" exact element={<Signup /> } />
2323
<Route path="login" exact element={<Login />} />
24-
<Route path="/" exact element={<HomePageUser />} />
24+
<Route path="/" exact element={<HomePageWithCarousel />} />
2525
<Route path="/contact" exact element={<ContactForm />} />
2626

2727
{/* Private routes */}
@@ -40,5 +40,12 @@ function App() {
4040
</div>
4141
);
4242
}
43-
43+
function HomePageWithCarousel() {
44+
return (
45+
<>
46+
<DefaultCarousel />
47+
<HomePageUser />
48+
</>
49+
);
50+
}
4451
export default App;
Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,32 @@
1-
import React, { useState } from "react";
2-
import { BsChevronCompactLeft, BsChevronCompactRight } from "react-icons/bs";
3-
import { RxDotFilled } from "react-icons/rx";
4-
import { useLocation } from "react-router-dom";
5-
export function Carousel() {
6-
const slides = [
7-
{
8-
url: "https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Mano-humana-y-robo%CC%81tica-tocan-un-cerebro-digital-1.jpg?w=1280&ssl=1",
9-
},
10-
{
11-
url: "https://i1.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Steve-Jobs-presenta-el-primer-iPhone-en-2007-1.jpg?w=1280&ssl=1",
12-
},
13-
{
14-
url: "https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Mujer-immersa-en-videojuego-con-realidad-virtual.jpg?w=1280&ssl=1",
15-
},
1+
'use client';
162

17-
{
18-
url: "https://images.unsplash.com/photo-1512756290469-ec264b7fbf87?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2253&q=80",
19-
},
20-
{
21-
url: "https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Coche-auto%CC%81nomo-con-HUD-Head-Up-Display.-Vehi%CC%81culo-auto%CC%81nomo-en-las-calles-de-la-ciudad.png?w=1280&ssl=1",
22-
},
23-
];
3+
import { Carousel } from 'flowbite-react';
244

25-
const [currentIndex, setCurrentIndex] = useState(0);
26-
27-
const prevSlide = () => {
28-
const isFirstSlide = currentIndex === 0;
29-
const newIndex = isFirstSlide ? slides.length - 1 : currentIndex - 1;
30-
setCurrentIndex(newIndex);
31-
};
32-
33-
const nextSlide = () => {
34-
const isLastSlide = currentIndex === slides.length - 1;
35-
const newIndex = isLastSlide ? 0 : currentIndex + 1;
36-
setCurrentIndex(newIndex);
37-
};
38-
39-
const goToSlide = (slideIndex) => {
40-
setCurrentIndex(slideIndex);
41-
};
42-
const location = useLocation();
43-
const isHomePage = location.pathname === "/";
44-
if (!isHomePage) {
45-
return null;
46-
}
5+
export function DefaultCarousel() {
476
return (
48-
<div className="max-w-[50] h-[500px] w-90 m-auto py-16 px-10 relative group animate-fade-right animate-once animate-duration-[500ms] animate-ease-out">
49-
<div
50-
style={{ backgroundImage: `url(${slides[currentIndex].url})` }}
51-
className="w-full h-full rounded bg-center bg-cover duration-500"
52-
></div>
7+
<Carousel>
8+
<img
9+
alt="..."
10+
src="https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Mano-humana-y-robo%CC%81tica-tocan-un-cerebro-digital-1.jpg?w=1280&ssl=1"
11+
/>
12+
<img
13+
alt="..."
14+
src="https://i1.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Steve-Jobs-presenta-el-primer-iPhone-en-2007-1.jpg?w=1280&ssl=1"
15+
/>
16+
<img
17+
alt="..."
18+
src="https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Mujer-immersa-en-videojuego-con-realidad-virtual.jpg?w=1280&ssl=1"
19+
/>
20+
<img
21+
alt="..."
22+
src="https://images.unsplash.com/photo-1512756290469-ec264b7fbf87?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2253&q=80"
23+
/>
24+
<img
25+
alt="..."
26+
src="https://i2.wp.com/www.revistamercado.do/wp-content/uploads/2021/08/Coche-auto%CC%81nomo-con-HUD-Head-Up-Display.-Vehi%CC%81culo-auto%CC%81nomo-en-las-calles-de-la-ciudad.png?w=1280&ssl=1"
27+
/>
28+
</Carousel>
29+
)
30+
}
5331

54-
<div className="hidden group-hover:block absolute top-[50%] -translate-x-0 translate-y-[-50%] left-5 text-2xl rounded-full p-2 bg-black/20 text-white cursor-pointer">
55-
<BsChevronCompactLeft onClick={prevSlide} size={30} />
56-
</div>
5732

58-
<div className="hidden group-hover:block absolute top-[50%] -translate-x-0 translate-y-[-50%] right-5 text-2xl rounded-full p-2 bg-black/20 text-white cursor-pointer">
59-
<BsChevronCompactRight onClick={nextSlide} size={30} />
60-
</div>
61-
<div className="flex top-4 justify-center py-2">
62-
{slides.map((slide, slideIndex) => (
63-
<div
64-
key={slideIndex}
65-
onClick={() => goToSlide(slideIndex)}
66-
className="text-2xl cursor-pointer"
67-
>
68-
<RxDotFilled />
69-
</div>
70-
))}
71-
</div>
72-
</div>
73-
);
74-
}

tailwind.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
module.exports = {
33
content: [
44
"./src/**/*.{js,jsx,ts,tsx}",
5+
"node_modules/flowbite-react/**/*.{js,jsx,ts,tsx}",
56
],
67
theme: {
78
extend: {},
89
},
910
plugins: [
10-
require('tailwindcss-animated')
11+
require('tailwindcss-animated'),
12+
require('flowbite/plugin'),
1113
],
1214
}
1315

0 commit comments

Comments
 (0)