mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 03:49:45 +00:00
Рабочая версия (точки отключены)
This commit is contained in:
1 parent
1a4f0160e8
commit
26b6fefff9
11 files changed
+137
-27
No files matched your search
@@ -4,19 +4,18 @@ import Arrows from './components/Arrows';
|
||||
import SlidesList from './components/SlidesList';
|
||||
import Dots from './components/Dots';
|
||||
|
||||
//import { getSliderImages } from '../../api';
|
||||
import { g1, g2, g3 } from '../../images/gallery';
|
||||
import { getSliderImages } from '../../api';
|
||||
import './Slider.styles.scss';
|
||||
|
||||
export const SliderContext = createContext();
|
||||
|
||||
function Slider({ autoPlay = 1, autoPlayTime = 1 }) {
|
||||
function Slider({ autoPlay = 0, autoPlayTime = 0 }) {
|
||||
const [items, setItems] = useState([]);
|
||||
const [slide, setSlide] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = () => {
|
||||
const images = [g1, g2, g3];
|
||||
const loadData = async () => {
|
||||
const images = await getSliderImages();
|
||||
setItems(images);
|
||||
};
|
||||
loadData();
|
||||
@@ -32,7 +31,7 @@ function Slider({ autoPlay = 1, autoPlayTime = 1 }) {
|
||||
}
|
||||
|
||||
setSlide(slideNumber);
|
||||
}
|
||||
};
|
||||
|
||||
const goToSlide = (number) => {
|
||||
setSlide(number % items.length);
|
||||
@@ -40,15 +39,15 @@ function Slider({ autoPlay = 1, autoPlayTime = 1 }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoPlay) return;
|
||||
|
||||
|
||||
const interval = setInterval(() => {
|
||||
changeSlide(1);
|
||||
changeSlide(1);
|
||||
}, autoPlayTime);
|
||||
|
||||
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [items.length, slide]);
|
||||
}, [items.length, slide]);
|
||||
|
||||
return (
|
||||
<div className="slider">
|
||||
@@ -63,7 +62,7 @@ function Slider({ autoPlay = 1, autoPlayTime = 1 }) {
|
||||
>
|
||||
<Arrows />
|
||||
<SlidesList />
|
||||
<Dots />
|
||||
{/* <Dots /> */}
|
||||
</SliderContext.Provider>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
.slider {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
& .slide-list {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
transition: transform 0.5s ease-in-out;
|
||||
width: 100%;
|
||||
|
||||
& .slide {
|
||||
flex: 1 0 100%;
|
||||
position: relative;
|
||||
|
||||
|
||||
& .slide-image {
|
||||
display: flex;
|
||||
width: 80%;
|
||||
margin: 0 auto;
|
||||
border-radius: 8px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
& .slide-title {
|
||||
text-align: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,22 @@
|
||||
import React, { useContext } from "react";
|
||||
import { SliderContext } from "../Slider";
|
||||
|
||||
function Arrows() {
|
||||
const { changeSlide } = useContext(SliderContext);
|
||||
import { arrow } from '../../../images';
|
||||
import './Arrows.styles.scss';
|
||||
|
||||
return (
|
||||
<div className="arrows">
|
||||
<div className="arrow left" onClick={() => changeSlide(-1)} />
|
||||
<div className="arrow right" onClick={() => changeSlide(1)} />
|
||||
</div>
|
||||
);
|
||||
function Arrows() {
|
||||
const { changeSlide } = useContext(SliderContext);
|
||||
|
||||
return (
|
||||
<div className="arrows">
|
||||
<div className="arrow left" onClick={() => changeSlide(-1)}>
|
||||
<img src={ arrow } alt="" />
|
||||
</div>
|
||||
<div className="arrow right" onClick={() => changeSlide(1)}>
|
||||
<img src={ arrow } alt="" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Arrows;
|
||||
@@ -0,0 +1,36 @@
|
||||
.arrows {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
height: 100%;
|
||||
width: calc(100% - 10% + 60px);
|
||||
left: calc(5% - 30px);
|
||||
margin: 0 auto;
|
||||
color: white;
|
||||
|
||||
.arrow {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
height: 60px;
|
||||
width: 60px;
|
||||
padding-right: 5px;
|
||||
border-radius: 100%;
|
||||
background: #D9D9D9;
|
||||
font-size: 30px;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&.right {
|
||||
transform: rotateY(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { useContext } from "react";
|
||||
import { useContext } from "react";
|
||||
|
||||
import { SliderContext } from "../Slider";
|
||||
|
||||
export default function Dot({ number }) {
|
||||
function Dot({ number }) {
|
||||
const { goToSlide, slideNumber } = useContext(SliderContext);
|
||||
|
||||
return (
|
||||
@@ -10,4 +11,6 @@ export default function Dot({ number }) {
|
||||
onClick={() => goToSlide(number)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Dot;
|
||||
@@ -1,8 +1,9 @@
|
||||
import React, { useContext } from "react";
|
||||
import { useContext } from "react";
|
||||
|
||||
import { SliderContext } from "../Slider";
|
||||
import Dot from "./Dots";
|
||||
|
||||
export default function Dots() {
|
||||
function Dots() {
|
||||
const { slidesCount } = useContext(SliderContext);
|
||||
|
||||
const renderDots = () => {
|
||||
@@ -15,4 +16,6 @@ export default function Dots() {
|
||||
};
|
||||
|
||||
return <div className="dots">{renderDots()}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default Dots;
|
||||
Reference in new issue
Block a user