UNPKG

rc-banner-anim

Version:
74 lines (64 loc) 2.76 kB
import _extends from 'babel-runtime/helpers/extends'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { toArrayChildren } from './utils'; var Thumb = function (_Component) { _inherits(Thumb, _Component); function Thumb() { var _temp, _this, _ret; _classCallCheck(this, Thumb); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.getDefaultThumb = function () { var children = []; for (var i = 0; i < _this.props.length; i++) { children.push(React.createElement('span', { key: i })); } return children; }, _temp), _possibleConstructorReturn(_this, _ret); } Thumb.prototype.render = function render() { var _this2 = this; var className = 'banner-anim-thumb'; var defaultClass = className + '-default'; className = (className + ' ' + (this.props.prefixCls || '')).trim(); className = !this.props['default'] ? className : (className + ' ' + defaultClass).trim(); var children = this.props['default'] ? this.getDefaultThumb() : this.props.children; if (this.props.length && toArrayChildren(children).length !== this.props.length) { console.warn('The thumbnail length and the images length different.'); // eslint-disable-line } var childToRender = toArrayChildren(children).map(function (item, i) { var props = _extends({}, item.props); props.onClick = _this2.props.thumbClick.bind(_this2, i); props.className = ((props.className || '') + ' ' + (_this2.props.active === i ? 'active' : '')).trim(); return React.cloneElement(item, props); }); var props = _extends({}, this.props); ['length', 'thumbClick', 'active', 'default', 'component', 'prefixCls'].forEach(function (key) { return delete props[key]; }); props.className = className; return React.createElement(this.props.component, props, childToRender); }; return Thumb; }(Component); Thumb.propTypes = { children: PropTypes.any, style: PropTypes.object, prefixCls: PropTypes.string, component: PropTypes.any, thumbClick: PropTypes.func, 'default': PropTypes.bool, length: PropTypes.number, active: PropTypes.number }; Thumb.defaultProps = { component: 'div', thumbClick: function thumbClick() {} }; Thumb.isBannerAnimThumb = true; export default Thumb;