UNPKG

3.11 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _createClass from 'babel-runtime/helpers/createClass';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import React, { Component } from 'react';
7import PropTypes from 'prop-types';
8import { toArrayChildren } from './utils';
9
10var Thumb = function (_Component) {
11 _inherits(Thumb, _Component);
12
13 function Thumb() {
14 var _ref;
15
16 var _temp, _this, _ret;
17
18 _classCallCheck(this, Thumb);
19
20 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
21 args[_key] = arguments[_key];
22 }
23
24 return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Thumb.__proto__ || Object.getPrototypeOf(Thumb)).call.apply(_ref, [this].concat(args))), _this), _this.getDefaultThumb = function () {
25 var children = [];
26 for (var i = 0; i < _this.props.length; i++) {
27 children.push(React.createElement('span', { key: i }));
28 }
29 return children;
30 }, _temp), _possibleConstructorReturn(_this, _ret);
31 }
32
33 _createClass(Thumb, [{
34 key: 'render',
35 value: function render() {
36 var _this2 = this;
37
38 var className = 'banner-anim-thumb';
39 var defaultClass = className + '-default';
40 className = (className + ' ' + (this.props.prefixCls || '')).trim();
41 className = !this.props['default'] ? className : (className + ' ' + defaultClass).trim();
42 var children = this.props['default'] ? this.getDefaultThumb() : this.props.children;
43 if (this.props.length && toArrayChildren(children).length !== this.props.length) {
44 console.warn('The thumbnail length and the images length different.'); // eslint-disable-line
45 }
46 var childToRender = toArrayChildren(children).map(function (item, i) {
47 var props = _extends({}, item.props);
48 props.onClick = function (e) {
49 e.stopPropagation();
50 _this2.props.thumbClick(i);
51 };
52 props.className = ((props.className || '') + ' ' + (_this2.props.active === i ? 'active' : '')).trim();
53 return React.cloneElement(item, props);
54 });
55 var props = _extends({}, this.props, this.props.componentProps);
56 ['length', 'thumbClick', 'active', 'default', 'component', 'componentProps', 'prefixCls'].forEach(function (key) {
57 return delete props[key];
58 });
59 props.className = className;
60 return React.createElement(this.props.component, props, childToRender);
61 }
62 }]);
63
64 return Thumb;
65}(Component);
66
67Thumb.propTypes = {
68 children: PropTypes.any,
69 style: PropTypes.object,
70 prefixCls: PropTypes.string,
71 component: PropTypes.any,
72 thumbClick: PropTypes.func,
73 'default': PropTypes.bool,
74 length: PropTypes.number,
75 active: PropTypes.number,
76 componentProps: PropTypes.object
77};
78Thumb.defaultProps = {
79 component: 'div',
80 componentProps: {},
81 thumbClick: function thumbClick() {}
82};
83Thumb.isBannerAnimThumb = true;
84
85export default Thumb;
\No newline at end of file