-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathdots.js
84 lines (74 loc) · 2.08 KB
/
dots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
import React from "react";
import classnames from "classnames";
import { clamp } from "./utils/innerSliderUtils";
const getDotCount = spec => {
let dots;
if (spec.infinite) {
dots = Math.ceil(spec.slideCount / spec.slidesToScroll);
} else {
dots =
Math.ceil((spec.slideCount - spec.slidesToShow) / spec.slidesToScroll) +
1;
}
return dots;
};
export class Dots extends React.PureComponent {
clickHandler(options, e) {
// In Autoplay the focus stays on clicked button even after transition
// to next slide. That only goes away by click somewhere outside
e.preventDefault();
this.props.clickHandler(options);
}
render() {
const {
onMouseEnter,
onMouseOver,
onMouseLeave,
infinite,
slidesToScroll,
slidesToShow,
slideCount,
currentSlide
} = this.props;
let dotCount = getDotCount({
slideCount,
slidesToScroll,
slidesToShow,
infinite
});
const mouseEvents = { onMouseEnter, onMouseOver, onMouseLeave };
let dots = [];
for (let i = 0; i < dotCount; i++) {
let _rightBound = (i + 1) * slidesToScroll - 1;
let rightBound = infinite
? _rightBound
: clamp(_rightBound, 0, slideCount - 1);
let _leftBound = rightBound - (slidesToScroll - 1);
let leftBound = infinite
? _leftBound
: clamp(_leftBound, 0, slideCount - 1);
let className = classnames({
"slick-active": infinite
? currentSlide >= leftBound && currentSlide <= rightBound
: currentSlide === leftBound
});
let dotOptions = {
message: "dots",
index: i,
slidesToScroll,
currentSlide
};
let onClick = this.clickHandler.bind(this, dotOptions);
dots = dots.concat(
<li key={i} className={className} role="listitem">
{React.cloneElement(this.props.customPaging(i), { onClick })}
</li>
);
}
return React.cloneElement(this.props.appendDots(dots), {
className: this.props.dotsClass,
...mouseEvents
});
}
}