UNPKG

2.26 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4import _inherits from "@babel/runtime/helpers/esm/inherits";
5import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6import Component from './base/component';
7import Children from './children';
8
9var Timeline = /*#__PURE__*/function (_Component) {
10 _inherits(Timeline, _Component);
11
12 var _super = _createSuper(Timeline);
13
14 function Timeline(props) {
15 var _this;
16
17 _classCallCheck(this, Timeline);
18
19 _this = _super.call(this, props);
20
21 _this.next = function () {
22 var _assertThisInitialize = _assertThisInitialized(_this),
23 state = _assertThisInitialize.state,
24 props = _assertThisInitialize.props;
25
26 var index = state.index,
27 count = state.count,
28 delay = state.delay;
29 var loop = props.loop;
30 var next = loop ? (index + 1) % count : index + 1;
31
32 if (next < count) {
33 setTimeout(function () {
34 _this.setState({
35 index: next
36 });
37 }, delay || 0);
38 }
39 };
40
41 var delay = props.delay,
42 _props$start = props.start,
43 start = _props$start === void 0 ? 0 : _props$start,
44 children = props.children;
45 var count = Children.toArray(children).length;
46 _this.state = {
47 delay: delay,
48 count: count,
49 index: start
50 };
51 return _this;
52 }
53
54 _createClass(Timeline, [{
55 key: "didMount",
56 value: function didMount() {
57 var context = this.context;
58 var root = context.root;
59 root.on('animationEnd', this.next);
60 }
61 }, {
62 key: "didUnmount",
63 value: function didUnmount() {
64 var context = this.context;
65 var root = context.root;
66 root.off('animationEnd', this.next);
67 }
68 }, {
69 key: "render",
70 value: function render() {
71 var state = this.state,
72 props = this.props;
73 var children = props.children;
74 var index = state.index;
75 var childrenArray = Children.toArray(children);
76 return childrenArray[index];
77 }
78 }]);
79
80 return Timeline;
81}(Component);
82
83export default Timeline;
\No newline at end of file