diff --git a/frontend/components/Carousel.jsx b/frontend/components/Carousel.jsx index 264e3bd..df387c2 100644 --- a/frontend/components/Carousel.jsx +++ b/frontend/components/Carousel.jsx @@ -63,15 +63,65 @@ // }; // export default Carousel; -import React, { useState, useEffect, useRef } from 'react'; -import './style/carousel2.css'; +import React, { useState, useEffect, useRef } from "react"; +import "./style/carousel2.css"; +import sunImg from "../public/image/sun-light.png"; +import moonImg from "../public/image/moon-light.png"; const Carousel = () => { + // toggle button + const [theme, setTheme] = useState("light"); + + const toggleTheme = (newTheme) => { + setTheme(newTheme); + + if (newTheme === "dark") { + document.documentElement.classList.add("dark"); + } else { + document.documentElement.classList.remove("dark"); + } + }; + + useEffect(() => { + // Set theme based on system preference + const prefersDark = window.matchMedia( + "(prefers-color-scheme: dark)" + ).matches; + if (prefersDark) { + setTheme("dark"); + document.documentElement.classList.add("dark"); + } + }, []); + const [carouselItems, setCarouselItems] = useState([ - { id: 1, image: '../image/event.JPG', author: '', title: 'devXsphere gaianet', topic: 'meetup' }, - { id: 2, image: '../image/event 2.JPG', author: 'Author 2', title: 'Title 2', topic: 'Topic 2' }, - { id: 3, image: '../image/event 3.JPG', author: 'Author 3', title: 'Title 3', topic: 'Topic 3' }, - { id: 4, image: '../image/event4.jpg', author: 'Author 4', title: 'Title 4', topic: 'Topic 4' } + { + id: 1, + image: "../image/event.JPG", + author: "", + title: "devXsphere gaianet", + topic: "meetup", + }, + { + id: 2, + image: "../image/event 2.JPG", + author: "Author 2", + title: "Title 2", + topic: "Topic 2", + }, + { + id: 3, + image: "../image/event 3.JPG", + author: "Author 3", + title: "Title 3", + topic: "Topic 3", + }, + { + id: 4, + image: "../image/event4.jpg", + author: "Author 4", + title: "Title 4", + topic: "Topic 4", + }, ]); const timeRunning = 1000; @@ -82,57 +132,83 @@ const Carousel = () => { useEffect(() => { const runNextAuto = setTimeout(() => { - showSlider('next'); + showSlider("next"); }, timeAutoNext); return () => clearTimeout(runNextAuto); }, [carouselItems]); const showSlider = (type) => { - if (type === 'next') { + if (type === "next") { setCarouselItems((prevItems) => [...prevItems.slice(1), prevItems[0]]); - carouselRef.current.classList.add('next'); + carouselRef.current.classList.add("next"); } else { - setCarouselItems((prevItems) => [prevItems[prevItems.length - 1], ...prevItems.slice(0, -1)]); - carouselRef.current.classList.add('prev'); + setCarouselItems((prevItems) => [ + prevItems[prevItems.length - 1], + ...prevItems.slice(0, -1), + ]); + carouselRef.current.classList.add("prev"); } clearTimeout(timeRef.current); timeRef.current = setTimeout(() => { - carouselRef.current.classList.remove('next'); - carouselRef.current.classList.remove('prev'); + carouselRef.current.classList.remove("next"); + carouselRef.current.classList.remove("prev"); }, timeRunning); }; return ( -
{/* Text color to light gray */} +
{/* Text color to light gray */} With over 100 years of combined experience, we've got a well-seasoned team at the helm.