You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.1 KiB
87 lines
2.1 KiB
3 years ago
|
import classnames from '../_util/classNames';
|
||
|
import { cloneElement } from '../_util/vnode';
|
||
|
import { clamp } from './utils/innerSliderUtils';
|
||
6 years ago
|
|
||
3 years ago
|
const getDotCount = function (spec) {
|
||
6 years ago
|
let dots;
|
||
6 years ago
|
|
||
|
if (spec.infinite) {
|
||
6 years ago
|
dots = Math.ceil(spec.slideCount / spec.slidesToScroll);
|
||
6 years ago
|
} else {
|
||
6 years ago
|
dots = Math.ceil((spec.slideCount - spec.slidesToShow) / spec.slidesToScroll) + 1;
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
return dots;
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
const Dots = (_, { attrs }) => {
|
||
|
const {
|
||
|
slideCount,
|
||
|
slidesToScroll,
|
||
|
slidesToShow,
|
||
|
infinite,
|
||
|
currentSlide,
|
||
|
appendDots,
|
||
|
customPaging,
|
||
|
clickHandler,
|
||
|
dotsClass,
|
||
|
onMouseenter,
|
||
|
onMouseover,
|
||
|
onMouseleave,
|
||
|
} = attrs;
|
||
|
const dotCount = getDotCount({
|
||
|
slideCount,
|
||
|
slidesToScroll,
|
||
|
slidesToShow,
|
||
|
infinite,
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
// Apply join & split to Array to pre-fill it for IE8
|
||
|
//
|
||
|
// Credit: http://stackoverflow.com/a/13735425/1849458
|
||
|
const mouseEvents = { onMouseenter, onMouseover, onMouseleave };
|
||
3 years ago
|
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,
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
3 years ago
|
let dotOptions = {
|
||
4 years ago
|
message: 'dots',
|
||
|
index: i,
|
||
|
slidesToScroll,
|
||
|
currentSlide,
|
||
|
};
|
||
3 years ago
|
|
||
4 years ago
|
function onClick(e) {
|
||
|
// In Autoplay the focus stays on clicked button even after transition
|
||
|
// to next slide. That only goes away by click somewhere outside
|
||
|
if (e) {
|
||
|
e.preventDefault();
|
||
6 years ago
|
}
|
||
4 years ago
|
clickHandler(dotOptions);
|
||
|
}
|
||
3 years ago
|
dots = dots.concat(
|
||
4 years ago
|
<li key={i} class={className}>
|
||
3 years ago
|
{cloneElement(customPaging({ i }), { onClick })}
|
||
|
</li>,
|
||
4 years ago
|
);
|
||
3 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
return cloneElement(appendDots({ dots }), {
|
||
|
class: dotsClass,
|
||
|
...mouseEvents,
|
||
|
});
|
||
6 years ago
|
};
|
||
4 years ago
|
|
||
|
Dots.inheritAttrs = false;
|
||
|
|
||
|
export default Dots;
|