1 | var _class, _temp;
|
2 |
|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4 |
|
5 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
6 |
|
7 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
8 |
|
9 | import React, { Component } from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import Instance from './instance.js';
|
12 |
|
13 | var Marquee = (_temp = _class = function (_Component) {
|
14 | _inherits(Marquee, _Component);
|
15 |
|
16 | function Marquee(props) {
|
17 | _classCallCheck(this, Marquee);
|
18 |
|
19 | var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
20 |
|
21 | _this.componentDidUpdate = function (prevProps) {
|
22 | if (!_this.props.list.equals(prevProps.list)) {
|
23 | _this.update();
|
24 | }
|
25 | };
|
26 |
|
27 | _this.componentDidMount = function () {
|
28 | if (_this.instance || _this.props.list.length === 0) return;
|
29 | _this.init();
|
30 | };
|
31 |
|
32 | _this.update = function () {
|
33 | _this.instance.setStart(0);
|
34 | _this.instance.setEnd(_this.props.step * (_this.props.list.length - 1));
|
35 | _this.instance.update();
|
36 | _this.instance.play();
|
37 | };
|
38 |
|
39 | _this.init = function () {
|
40 | var _this$props = _this.props,
|
41 | list = _this$props.list,
|
42 | step = _this$props.step,
|
43 | duration = _this$props.duration,
|
44 | delay = _this$props.delay,
|
45 | direction = _this$props.direction,
|
46 | loop = _this$props.loop;
|
47 |
|
48 | var instance = new Instance(_this.$el, {
|
49 | start: 0,
|
50 | end: step * (list.length - 1),
|
51 | step: step,
|
52 | duration: duration,
|
53 | delay: delay,
|
54 | direction: direction,
|
55 | loop: loop
|
56 | });
|
57 | instance.play();
|
58 | _this.instance = instance;
|
59 | };
|
60 |
|
61 | _this.onClick = function (item, index) {
|
62 | if (_this.props.onClick) _this.props.onClick(item, index);
|
63 | };
|
64 |
|
65 | return _this;
|
66 | }
|
67 |
|
68 | Marquee.prototype.render = function render() {
|
69 | var _this2 = this;
|
70 |
|
71 | var _props = this.props,
|
72 | className = _props.className,
|
73 | style = _props.style,
|
74 | list = _props.list,
|
75 | contentClassName = _props.contentClassName,
|
76 | contentStyle = _props.contentStyle,
|
77 | step = _props.step;
|
78 |
|
79 | return React.createElement(
|
80 | 'ul',
|
81 | { ref: function ref(el) {
|
82 | _this2.$el = el;
|
83 | }, className: 'marquee' + (className ? ' ' + className : ''), style: style },
|
84 | list && list.map(function (item, index) {
|
85 | return React.createElement(
|
86 | 'li',
|
87 | { className: 'marquee-li' + (contentClassName ? ' ' + contentClassName : ''), style: Object.assign({ height: step + 'px' }, contentStyle), key: index, onClick: function onClick() {
|
88 | _this2.onClick(item, index);
|
89 | } },
|
90 | item.value
|
91 | );
|
92 | })
|
93 | );
|
94 | };
|
95 |
|
96 | return Marquee;
|
97 | }(Component), _class.defaultProps = {
|
98 | step: 50,
|
99 | duration: 300,
|
100 | delay: 2000,
|
101 | direction: 'top',
|
102 | loop: true
|
103 | }, _temp);
|
104 | export { Marquee as default };
|
105 | Marquee.propTypes = process.env.NODE_ENV !== "production" ? {
|
106 | style: PropTypes.object,
|
107 | className: PropTypes.string,
|
108 | list: PropTypes.array,
|
109 |
|
110 | contentStyle: PropTypes.object,
|
111 | contentClassName: PropTypes.string,
|
112 |
|
113 | step: PropTypes.number,
|
114 | duration: PropTypes.number,
|
115 | delay: PropTypes.number,
|
116 | direction: PropTypes.string,
|
117 | loop: PropTypes.bool,
|
118 | onClick: PropTypes.func
|
119 | } : {}; |
\ | No newline at end of file |