|
@@ -0,0 +1,68 @@
|
|
|
+import {useState} from 'react';
|
|
|
+
|
|
|
+const Dots = ({count, active, onChange}) => {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <ul>
|
|
|
+ {[...new Array(count)].map((item, index) => {
|
|
|
+ return (
|
|
|
+ <li
|
|
|
+ key={index}
|
|
|
+ style={{backgroundColor: active === index ? 'red' : 'black'}}
|
|
|
+ onClick={() => onChange(index)}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+const Gallery = ({
|
|
|
+ images = ['https://kot-pes.com/wp-content/uploads/2018/12/post_5c249026dde11.jpg',
|
|
|
+ 'https://bigpicture.ru/wp-content/uploads/2019/12/DmrVIH7W4AAU_90-800x533.jpg',
|
|
|
+ 'https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
|
|
|
+ 'https://images.pexels.com/photos/177809/pexels-photo-177809.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
|
|
|
+ ]
|
|
|
+ }) => {
|
|
|
+
|
|
|
+ const [index, setIndex] = useState(0);
|
|
|
+ const isDisabledBack = index === images.length - 1;
|
|
|
+ const isDisabledForward = index === 0;
|
|
|
+
|
|
|
+ const forward = () => {
|
|
|
+ if (index <= images.length - 1) {
|
|
|
+ setIndex(index + 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const back = () => {
|
|
|
+ if (index <= images.length - 1) {
|
|
|
+ setIndex(index - 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="Gallery">
|
|
|
+ <img src={images[index]}/>
|
|
|
+ <Dots
|
|
|
+ count={images.length}
|
|
|
+ active={index}
|
|
|
+ onChange={setIndex}
|
|
|
+ />
|
|
|
+ <button
|
|
|
+ onClick={back}
|
|
|
+ disabled={isDisabledForward}
|
|
|
+ >
|
|
|
+ Назад
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ onClick={forward}
|
|
|
+ disabled={isDisabledBack}
|
|
|
+ >
|
|
|
+ Вперед
|
|
|
+ </button>
|
|
|
+
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+export default Gallery;
|