From 42830bd355423f893064915f1f24276455d5f5e6 Mon Sep 17 00:00:00 2001 From: mahdi andalib Date: Thu, 17 Feb 2022 13:12:27 +0330 Subject: [PATCH] digikala project added --- src/App.js | 4 +- src/components/Digikala/ImageSlider.js | 76 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/components/Digikala/ImageSlider.js diff --git a/src/App.js b/src/App.js index b4e5b6b..564558b 100644 --- a/src/App.js +++ b/src/App.js @@ -44,6 +44,7 @@ import TableDesign1 from "./components/Table/Design1"; import ReactTable2 from "./components/ReactTable2"; // import ReactTable3 from "./components/ReactTable3"; import ReactTable4 from "./components/ReactTable4"; +import Digikala from "./components/Digikala/ImageSlider"; import Switch from "./components/Switch"; @@ -91,7 +92,8 @@ function App() { {/* */} {/* */} {/* */} - + {/* */} + ); diff --git a/src/components/Digikala/ImageSlider.js b/src/components/Digikala/ImageSlider.js new file mode 100644 index 0000000..b69ea0c --- /dev/null +++ b/src/components/Digikala/ImageSlider.js @@ -0,0 +1,76 @@ +import React, { useState } from "react"; + +import rightArrow from "./black-right-arrow.svg"; +import leftArrow from "./black-left-arrow.svg"; + +const ImageSlider = ({ slides }) => { + const [current, setCurrent] = useState(0); + const length = slides.length; + + const nextSlide = () => { + setCurrent(current === length - 1 ? 0 : current + 1); + }; + + const prevSlide = () => { + setCurrent(current === 0 ? length - 1 : current - 1); + }; + + console.log(current); + + if (!Array.isArray(slides) || slides.length <= 0) { + return null; + } + + return ( +
+
+ {slides.map((slide, index) => { + return ( +
+ {index === current && ( + mahdi + )} +
+ ); + })} + +
+
+ ); +}; + +export default ImageSlider; + +function Tabbar({ nextSlide, prevSlide }) { + const tabs = [ + { + icon: rightArrow, + click: nextSlide, + }, + { + icon: leftArrow, + click: prevSlide, + }, + ]; + return ( +
+ {tabs.map((tab, index) => ( + + ))} +
+ ); +}