ant-design-vue/components/vc-slick/arrows.jsx

120 lines
2.5 KiB
Vue
Raw Normal View History

import classnames from '../_util/classNames';
import { cloneElement } from '../_util/vnode';
2019-01-12 11:33:27 +08:00
import { canGoNext } from './utils/innerSliderUtils';
2018-07-20 16:13:21 +08:00
2019-01-12 11:33:27 +08:00
function noop() {}
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
function handler(options, handle, e) {
if (e) {
e.preventDefault();
}
handle(options, e);
}
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
const PrevArrow = (_, { attrs }) => {
const { clickHandler, infinite, currentSlide, slideCount, slidesToShow } = attrs;
const prevClasses = { 'slick-arrow': true, 'slick-prev': true };
2021-06-23 23:08:16 +08:00
let prevHandler = function (e) {
2020-07-20 16:29:46 +08:00
handler({ message: 'previous' }, clickHandler, e);
};
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
if (!infinite && (currentSlide === 0 || slideCount <= slidesToShow)) {
prevClasses['slick-disabled'] = true;
prevHandler = noop;
}
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
const prevArrowProps = {
key: '0',
'data-role': 'none',
class: prevClasses,
style: { display: 'block' },
onClick: prevHandler,
};
const customProps = {
currentSlide,
slideCount,
};
let prevArrow;
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
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;
2019-01-12 11:33:27 +08:00
};
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
PrevArrow.inheritAttrs = false;
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
const NextArrow = (_, { attrs }) => {
const { clickHandler, currentSlide, slideCount } = attrs;
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
const nextClasses = { 'slick-arrow': true, 'slick-next': true };
2021-06-23 23:08:16 +08:00
let nextHandler = function (e) {
2020-07-20 16:29:46 +08:00
handler({ message: 'next' }, clickHandler, e);
};
if (!canGoNext(attrs)) {
nextClasses['slick-disabled'] = true;
nextHandler = noop;
}
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
const nextArrowProps = {
key: '1',
'data-role': 'none',
class: classnames(nextClasses),
style: { display: 'block' },
onClick: nextHandler,
};
const customProps = {
currentSlide,
slideCount,
};
let nextArrow;
2018-07-20 16:13:21 +08:00
2020-07-20 16:29:46 +08:00
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;
2019-01-12 11:33:27 +08:00
};
2020-07-20 16:29:46 +08:00
NextArrow.inheritAttrs = false;
export { PrevArrow, NextArrow };