UNPKG

zent

Version:

一套前端设计语言和基于React的实现

40 lines (39 loc) 2.23 kB
import { __assign, __extends } from "tslib"; import { jsx as _jsx } from "react/jsx-runtime"; import { PureComponent, Children } from 'react'; import cx from 'classnames'; var buildInDotsColors = ['black', 'blue', 'red', 'green']; var SwiperDots = (function (_super) { __extends(SwiperDots, _super); function SwiperDots() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.isDotActive = function (index, currentIndex, length) { return (index === currentIndex || (index === 0 && currentIndex > length - 1) || (index === length - 1 && currentIndex < 0)); }; _this.isBuildInColor = function (dotsColor) { return buildInDotsColors.indexOf(dotsColor) !== -1; }; return _this; } SwiperDots.prototype.render = function () { var _a; var _this = this; var _b = this.props, dotsColor = _b.dotsColor, dotsSize = _b.dotsSize, items = _b.items, currentIndex = _b.currentIndex, dotsType = _b.dotsType, onDotsClick = _b.onDotsClick, dotsTheme = _b.dotsTheme; var classString = cx('zent-swiper__dots', "zent-swiper__dots-" + dotsSize, "zent-swiper__dots--" + dotsType, "zent-swiper__dots--" + dotsTheme, (_a = {}, _a["zent-swiper__dots-" + dotsColor] = this.isBuildInColor(dotsColor), _a)); return (_jsx("ul", __assign({ className: classString, "data-zv": '10.0.17' }, { children: Children.map(items, function (item, index) { var isActive = _this.isDotActive(index, currentIndex, items.length); if (isActive && !_this.isBuildInColor(dotsColor)) { return (_jsx("li", { style: { background: dotsColor }, className: "zent-swiper__dots-item zent-swiper__dots-item-active", "data-zv": '10.0.17' }, index)); } return (_jsx("li", { className: cx('zent-swiper__dots-item', { 'zent-swiper__dots-item-active': isActive, }), onClick: function () { return onDotsClick(index); }, "data-zv": '10.0.17' }, index)); }) }), void 0)); }; return SwiperDots; }(PureComponent)); export default SwiperDots;