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.
120 lines
2.5 KiB
120 lines
2.5 KiB
3 years ago
|
import classnames from '../_util/classNames';
|
||
|
import { cloneElement } from '../_util/vnode';
|
||
6 years ago
|
import { canGoNext } from './utils/innerSliderUtils';
|
||
6 years ago
|
|
||
6 years ago
|
function noop() {}
|
||
6 years ago
|
|
||
4 years ago
|
function handler(options, handle, e) {
|
||
|
if (e) {
|
||
|
e.preventDefault();
|
||
|
}
|
||
|
handle(options, e);
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
const PrevArrow = (_, { attrs }) => {
|
||
|
const { clickHandler, infinite, currentSlide, slideCount, slidesToShow } = attrs;
|
||
|
const prevClasses = { 'slick-arrow': true, 'slick-prev': true };
|
||
3 years ago
|
let prevHandler = function (e) {
|
||
4 years ago
|
handler({ message: 'previous' }, clickHandler, e);
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
if (!infinite && (currentSlide === 0 || slideCount <= slidesToShow)) {
|
||
|
prevClasses['slick-disabled'] = true;
|
||
|
prevHandler = noop;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
const prevArrowProps = {
|
||
|
key: '0',
|
||
|
'data-role': 'none',
|
||
|
class: prevClasses,
|
||
|
style: { display: 'block' },
|
||
|
onClick: prevHandler,
|
||
|
};
|
||
|
const customProps = {
|
||
|
currentSlide,
|
||
|
slideCount,
|
||
|
};
|
||
|
let prevArrow;
|
||
6 years ago
|
|
||
4 years ago
|
if (attrs.prevArrow) {
|
||
|
prevArrow = cloneElement(
|
||
|
attrs.prevArrow({
|
||
|
...prevArrowProps,
|
||
|
...customProps,
|
||
|
}),
|
||
|
{
|
||
|
key: '0',
|
||
|
class: prevClasses,
|
||
|
style: { display: 'block' },
|
||
|
onClick: prevHandler,
|
||
|
},
|
||
|
false,
|
||
|
);
|
||
|
} else {
|
||
|
prevArrow = (
|
||
|
<button key="0" type="button" {...prevArrowProps}>
|
||
|
{' '}
|
||
|
Previous
|
||
|
</button>
|
||
|
);
|
||
|
}
|
||
|
return prevArrow;
|
||
6 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
PrevArrow.inheritAttrs = false;
|
||
6 years ago
|
|
||
4 years ago
|
const NextArrow = (_, { attrs }) => {
|
||
|
const { clickHandler, currentSlide, slideCount } = attrs;
|
||
6 years ago
|
|
||
4 years ago
|
const nextClasses = { 'slick-arrow': true, 'slick-next': true };
|
||
3 years ago
|
let nextHandler = function (e) {
|
||
4 years ago
|
handler({ message: 'next' }, clickHandler, e);
|
||
|
};
|
||
|
if (!canGoNext(attrs)) {
|
||
|
nextClasses['slick-disabled'] = true;
|
||
|
nextHandler = noop;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
const nextArrowProps = {
|
||
|
key: '1',
|
||
|
'data-role': 'none',
|
||
|
class: classnames(nextClasses),
|
||
|
style: { display: 'block' },
|
||
|
onClick: nextHandler,
|
||
|
};
|
||
|
const customProps = {
|
||
|
currentSlide,
|
||
|
slideCount,
|
||
|
};
|
||
|
let nextArrow;
|
||
6 years ago
|
|
||
4 years ago
|
if (attrs.nextArrow) {
|
||
|
nextArrow = cloneElement(
|
||
|
attrs.nextArrow({
|
||
|
...nextArrowProps,
|
||
|
...customProps,
|
||
|
}),
|
||
|
{
|
||
|
key: '1',
|
||
|
class: classnames(nextClasses),
|
||
|
style: { display: 'block' },
|
||
|
onClick: nextHandler,
|
||
|
},
|
||
|
false,
|
||
|
);
|
||
|
} else {
|
||
|
nextArrow = (
|
||
|
<button key="1" type="button" {...nextArrowProps}>
|
||
|
{' '}
|
||
|
Next
|
||
|
</button>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return nextArrow;
|
||
6 years ago
|
};
|
||
4 years ago
|
|
||
|
NextArrow.inheritAttrs = false;
|
||
|
|
||
|
export { PrevArrow, NextArrow };
|