@tw1934/react-countdown 2.3.6-no-proptypes.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +372 -0
- package/dist/Countdown.d.ts +87 -0
- package/dist/LegacyCountdown.d.ts +21 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +473 -0
- package/dist/index.js +479 -0
- package/dist/utils.d.ts +31 -0
- package/package.json +99 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { cloneElement, Component, createElement } from 'react';
|
|
2
|
+
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function _arrayWithoutHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
10
|
+
}
|
|
11
|
+
function _assertThisInitialized(e) {
|
|
12
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
function _callSuper(t, o, e) {
|
|
16
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
17
|
+
}
|
|
18
|
+
function _classCallCheck(a, n) {
|
|
19
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
20
|
+
}
|
|
21
|
+
function _defineProperties(e, r) {
|
|
22
|
+
for (var t = 0; t < r.length; t++) {
|
|
23
|
+
var o = r[t];
|
|
24
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function _createClass(e, r, t) {
|
|
28
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
29
|
+
writable: !1
|
|
30
|
+
}), e;
|
|
31
|
+
}
|
|
32
|
+
function _getPrototypeOf(t) {
|
|
33
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
34
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
35
|
+
}, _getPrototypeOf(t);
|
|
36
|
+
}
|
|
37
|
+
function _inherits(t, e) {
|
|
38
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
39
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
40
|
+
constructor: {
|
|
41
|
+
value: t,
|
|
42
|
+
writable: !0,
|
|
43
|
+
configurable: !0
|
|
44
|
+
}
|
|
45
|
+
}), Object.defineProperty(t, "prototype", {
|
|
46
|
+
writable: !1
|
|
47
|
+
}), e && _setPrototypeOf(t, e);
|
|
48
|
+
}
|
|
49
|
+
function _isNativeReflectConstruct() {
|
|
50
|
+
try {
|
|
51
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
52
|
+
} catch (t) {}
|
|
53
|
+
return (_isNativeReflectConstruct = function () {
|
|
54
|
+
return !!t;
|
|
55
|
+
})();
|
|
56
|
+
}
|
|
57
|
+
function _iterableToArray(r) {
|
|
58
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
59
|
+
}
|
|
60
|
+
function _nonIterableSpread() {
|
|
61
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
62
|
+
}
|
|
63
|
+
function _possibleConstructorReturn(t, e) {
|
|
64
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
65
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
66
|
+
return _assertThisInitialized(t);
|
|
67
|
+
}
|
|
68
|
+
function _setPrototypeOf(t, e) {
|
|
69
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
70
|
+
return t.__proto__ = e, t;
|
|
71
|
+
}, _setPrototypeOf(t, e);
|
|
72
|
+
}
|
|
73
|
+
function _toConsumableArray(r) {
|
|
74
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
75
|
+
}
|
|
76
|
+
function _toPrimitive(t, r) {
|
|
77
|
+
if ("object" != typeof t || !t) return t;
|
|
78
|
+
var e = t[Symbol.toPrimitive];
|
|
79
|
+
if (void 0 !== e) {
|
|
80
|
+
var i = e.call(t, r || "default");
|
|
81
|
+
if ("object" != typeof i) return i;
|
|
82
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
83
|
+
}
|
|
84
|
+
return ("string" === r ? String : Number)(t);
|
|
85
|
+
}
|
|
86
|
+
function _toPropertyKey(t) {
|
|
87
|
+
var i = _toPrimitive(t, "string");
|
|
88
|
+
return "symbol" == typeof i ? i : i + "";
|
|
89
|
+
}
|
|
90
|
+
function _unsupportedIterableToArray(r, a) {
|
|
91
|
+
if (r) {
|
|
92
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
93
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
94
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function zeroPad(value) {
|
|
99
|
+
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
100
|
+
var strValue = String(value);
|
|
101
|
+
if (length === 0) return strValue;
|
|
102
|
+
var match = strValue.match(/(.*?)([0-9]+)(.*)/);
|
|
103
|
+
var prefix = match ? match[1] : '';
|
|
104
|
+
var suffix = match ? match[3] : '';
|
|
105
|
+
var strNo = match ? match[2] : strValue;
|
|
106
|
+
var paddedNo = strNo.length >= length ? strNo : (_toConsumableArray(Array(length)).map(function () {
|
|
107
|
+
return '0';
|
|
108
|
+
}).join('') + strNo).slice(length * -1);
|
|
109
|
+
return "".concat(prefix).concat(paddedNo).concat(suffix);
|
|
110
|
+
}
|
|
111
|
+
var timeDeltaFormatOptionsDefaults = {
|
|
112
|
+
daysInHours: false,
|
|
113
|
+
zeroPadTime: 2
|
|
114
|
+
};
|
|
115
|
+
function calcTimeDelta(date) {
|
|
116
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
117
|
+
var _options$now = options.now,
|
|
118
|
+
now = _options$now === void 0 ? Date.now : _options$now,
|
|
119
|
+
_options$precision = options.precision,
|
|
120
|
+
precision = _options$precision === void 0 ? 0 : _options$precision,
|
|
121
|
+
controlled = options.controlled,
|
|
122
|
+
_options$offsetTime = options.offsetTime,
|
|
123
|
+
offsetTime = _options$offsetTime === void 0 ? 0 : _options$offsetTime,
|
|
124
|
+
overtime = options.overtime;
|
|
125
|
+
var startTimestamp;
|
|
126
|
+
if (typeof date === 'string') {
|
|
127
|
+
startTimestamp = new Date(date).getTime();
|
|
128
|
+
} else if (date instanceof Date) {
|
|
129
|
+
startTimestamp = date.getTime();
|
|
130
|
+
} else {
|
|
131
|
+
startTimestamp = date;
|
|
132
|
+
}
|
|
133
|
+
if (!controlled) {
|
|
134
|
+
startTimestamp += offsetTime;
|
|
135
|
+
}
|
|
136
|
+
var timeLeft = controlled ? startTimestamp : startTimestamp - now();
|
|
137
|
+
var clampedPrecision = Math.min(20, Math.max(0, precision));
|
|
138
|
+
var total = Math.round(parseFloat(((overtime ? timeLeft : Math.max(0, timeLeft)) / 1000).toFixed(clampedPrecision)) * 1000);
|
|
139
|
+
var seconds = Math.abs(total) / 1000;
|
|
140
|
+
return {
|
|
141
|
+
total: total,
|
|
142
|
+
days: Math.floor(seconds / (3600 * 24)),
|
|
143
|
+
hours: Math.floor(seconds / 3600 % 24),
|
|
144
|
+
minutes: Math.floor(seconds / 60 % 60),
|
|
145
|
+
seconds: Math.floor(seconds % 60),
|
|
146
|
+
milliseconds: Number((seconds % 1 * 1000).toFixed()),
|
|
147
|
+
completed: total <= 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function formatTimeDelta(timeDelta, options) {
|
|
151
|
+
var days = timeDelta.days,
|
|
152
|
+
hours = timeDelta.hours,
|
|
153
|
+
minutes = timeDelta.minutes,
|
|
154
|
+
seconds = timeDelta.seconds;
|
|
155
|
+
var _Object$assign = Object.assign(Object.assign({}, timeDeltaFormatOptionsDefaults), options),
|
|
156
|
+
daysInHours = _Object$assign.daysInHours,
|
|
157
|
+
zeroPadTime = _Object$assign.zeroPadTime,
|
|
158
|
+
_Object$assign$zeroPa = _Object$assign.zeroPadDays,
|
|
159
|
+
zeroPadDays = _Object$assign$zeroPa === void 0 ? zeroPadTime : _Object$assign$zeroPa;
|
|
160
|
+
var zeroPadTimeLength = Math.min(2, zeroPadTime);
|
|
161
|
+
var formattedHours = daysInHours ? zeroPad(hours + days * 24, zeroPadTime) : zeroPad(hours, zeroPadTimeLength);
|
|
162
|
+
return {
|
|
163
|
+
days: daysInHours ? '' : zeroPad(days, zeroPadDays),
|
|
164
|
+
hours: formattedHours,
|
|
165
|
+
minutes: zeroPad(minutes, zeroPadTimeLength),
|
|
166
|
+
seconds: zeroPad(seconds, zeroPadTimeLength)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var Countdown = function (_React$Component) {
|
|
171
|
+
function Countdown() {
|
|
172
|
+
var _this;
|
|
173
|
+
_classCallCheck(this, Countdown);
|
|
174
|
+
_this = _callSuper(this, Countdown, arguments);
|
|
175
|
+
_this.state = {
|
|
176
|
+
count: _this.props.count || 3
|
|
177
|
+
};
|
|
178
|
+
_this.startCountdown = function () {
|
|
179
|
+
_this.interval = window.setInterval(function () {
|
|
180
|
+
var count = _this.state.count - 1;
|
|
181
|
+
if (count === 0) {
|
|
182
|
+
_this.stopCountdown();
|
|
183
|
+
_this.props.onComplete && _this.props.onComplete();
|
|
184
|
+
} else {
|
|
185
|
+
_this.setState(function (prevState) {
|
|
186
|
+
return {
|
|
187
|
+
count: prevState.count - 1
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}, 1000);
|
|
192
|
+
};
|
|
193
|
+
_this.stopCountdown = function () {
|
|
194
|
+
clearInterval(_this.interval);
|
|
195
|
+
};
|
|
196
|
+
_this.addTime = function (seconds) {
|
|
197
|
+
_this.stopCountdown();
|
|
198
|
+
_this.setState(function (prevState) {
|
|
199
|
+
return {
|
|
200
|
+
count: prevState.count + seconds
|
|
201
|
+
};
|
|
202
|
+
}, _this.startCountdown);
|
|
203
|
+
};
|
|
204
|
+
return _this;
|
|
205
|
+
}
|
|
206
|
+
_inherits(Countdown, _React$Component);
|
|
207
|
+
return _createClass(Countdown, [{
|
|
208
|
+
key: "componentDidMount",
|
|
209
|
+
value: function componentDidMount() {
|
|
210
|
+
this.startCountdown();
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "componentWillUnmount",
|
|
214
|
+
value: function componentWillUnmount() {
|
|
215
|
+
clearInterval(this.interval);
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "render",
|
|
219
|
+
value: function render() {
|
|
220
|
+
return this.props.children ? cloneElement(this.props.children, {
|
|
221
|
+
count: this.state.count
|
|
222
|
+
}) : null;
|
|
223
|
+
}
|
|
224
|
+
}]);
|
|
225
|
+
}(Component);
|
|
226
|
+
Countdown.propTypes = {};
|
|
227
|
+
|
|
228
|
+
var Countdown$1 = function (_React$Component) {
|
|
229
|
+
function Countdown$1(props) {
|
|
230
|
+
var _this;
|
|
231
|
+
_classCallCheck(this, Countdown$1);
|
|
232
|
+
_this = _callSuper(this, Countdown$1, [props]);
|
|
233
|
+
_this.mounted = false;
|
|
234
|
+
_this.initialTimestamp = _this.calcOffsetStartTimestamp();
|
|
235
|
+
_this.offsetStartTimestamp = _this.props.autoStart ? 0 : _this.initialTimestamp;
|
|
236
|
+
_this.offsetTime = 0;
|
|
237
|
+
_this.legacyMode = false;
|
|
238
|
+
_this.legacyCountdownRef = null;
|
|
239
|
+
_this.tick = function () {
|
|
240
|
+
var timeDelta = _this.calcTimeDelta();
|
|
241
|
+
var callback = timeDelta.completed && !_this.props.overtime ? undefined : _this.props.onTick;
|
|
242
|
+
_this.setTimeDeltaState(timeDelta, undefined, callback);
|
|
243
|
+
};
|
|
244
|
+
_this.setLegacyCountdownRef = function (ref) {
|
|
245
|
+
_this.legacyCountdownRef = ref;
|
|
246
|
+
};
|
|
247
|
+
_this.start = function () {
|
|
248
|
+
if (_this.isStarted()) return;
|
|
249
|
+
var prevOffsetStartTimestamp = _this.offsetStartTimestamp;
|
|
250
|
+
_this.offsetStartTimestamp = 0;
|
|
251
|
+
_this.offsetTime += prevOffsetStartTimestamp ? _this.calcOffsetStartTimestamp() - prevOffsetStartTimestamp : 0;
|
|
252
|
+
var timeDelta = _this.calcTimeDelta();
|
|
253
|
+
_this.setTimeDeltaState(timeDelta, "STARTED", _this.props.onStart);
|
|
254
|
+
if (!_this.props.controlled && (!timeDelta.completed || _this.props.overtime)) {
|
|
255
|
+
_this.clearTimer();
|
|
256
|
+
_this.interval = window.setInterval(_this.tick, _this.props.intervalDelay);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
_this.pause = function () {
|
|
260
|
+
if (_this.isPaused()) return;
|
|
261
|
+
_this.clearTimer();
|
|
262
|
+
_this.offsetStartTimestamp = _this.calcOffsetStartTimestamp();
|
|
263
|
+
_this.setTimeDeltaState(_this.state.timeDelta, "PAUSED", _this.props.onPause);
|
|
264
|
+
};
|
|
265
|
+
_this.stop = function () {
|
|
266
|
+
if (_this.isStopped()) return;
|
|
267
|
+
_this.clearTimer();
|
|
268
|
+
_this.offsetStartTimestamp = _this.calcOffsetStartTimestamp();
|
|
269
|
+
_this.offsetTime = _this.offsetStartTimestamp - _this.initialTimestamp;
|
|
270
|
+
_this.setTimeDeltaState(_this.calcTimeDelta(), "STOPPED", _this.props.onStop);
|
|
271
|
+
};
|
|
272
|
+
_this.isStarted = function () {
|
|
273
|
+
return _this.isStatus("STARTED");
|
|
274
|
+
};
|
|
275
|
+
_this.isPaused = function () {
|
|
276
|
+
return _this.isStatus("PAUSED");
|
|
277
|
+
};
|
|
278
|
+
_this.isStopped = function () {
|
|
279
|
+
return _this.isStatus("STOPPED");
|
|
280
|
+
};
|
|
281
|
+
_this.isCompleted = function () {
|
|
282
|
+
return _this.isStatus("COMPLETED");
|
|
283
|
+
};
|
|
284
|
+
if (props.date) {
|
|
285
|
+
var timeDelta = _this.calcTimeDelta();
|
|
286
|
+
_this.state = {
|
|
287
|
+
timeDelta: timeDelta,
|
|
288
|
+
status: timeDelta.completed ? "COMPLETED" : "STOPPED"
|
|
289
|
+
};
|
|
290
|
+
} else {
|
|
291
|
+
_this.legacyMode = true;
|
|
292
|
+
}
|
|
293
|
+
return _this;
|
|
294
|
+
}
|
|
295
|
+
_inherits(Countdown$1, _React$Component);
|
|
296
|
+
return _createClass(Countdown$1, [{
|
|
297
|
+
key: "componentDidMount",
|
|
298
|
+
value: function componentDidMount() {
|
|
299
|
+
if (this.legacyMode) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
this.mounted = true;
|
|
303
|
+
if (this.props.onMount) this.props.onMount(this.calcTimeDelta());
|
|
304
|
+
if (this.props.autoStart) this.start();
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
key: "componentDidUpdate",
|
|
308
|
+
value: function componentDidUpdate(prevProps) {
|
|
309
|
+
if (this.legacyMode) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (this.props.date !== prevProps.date) {
|
|
313
|
+
this.initialTimestamp = this.calcOffsetStartTimestamp();
|
|
314
|
+
this.offsetStartTimestamp = this.initialTimestamp;
|
|
315
|
+
this.offsetTime = 0;
|
|
316
|
+
this.setTimeDeltaState(this.calcTimeDelta());
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}, {
|
|
320
|
+
key: "componentWillUnmount",
|
|
321
|
+
value: function componentWillUnmount() {
|
|
322
|
+
if (this.legacyMode) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.mounted = false;
|
|
326
|
+
this.clearTimer();
|
|
327
|
+
}
|
|
328
|
+
}, {
|
|
329
|
+
key: "calcTimeDelta",
|
|
330
|
+
value: function calcTimeDelta$1() {
|
|
331
|
+
var _this$props = this.props,
|
|
332
|
+
date = _this$props.date,
|
|
333
|
+
now = _this$props.now,
|
|
334
|
+
precision = _this$props.precision,
|
|
335
|
+
controlled = _this$props.controlled,
|
|
336
|
+
overtime = _this$props.overtime;
|
|
337
|
+
return calcTimeDelta(date, {
|
|
338
|
+
now: now,
|
|
339
|
+
precision: precision,
|
|
340
|
+
controlled: controlled,
|
|
341
|
+
offsetTime: this.offsetTime,
|
|
342
|
+
overtime: overtime
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: "calcOffsetStartTimestamp",
|
|
347
|
+
value: function calcOffsetStartTimestamp() {
|
|
348
|
+
return Date.now();
|
|
349
|
+
}
|
|
350
|
+
}, {
|
|
351
|
+
key: "addTime",
|
|
352
|
+
value: function addTime(seconds) {
|
|
353
|
+
this.legacyCountdownRef.addTime(seconds);
|
|
354
|
+
}
|
|
355
|
+
}, {
|
|
356
|
+
key: "clearTimer",
|
|
357
|
+
value: function clearTimer() {
|
|
358
|
+
window.clearInterval(this.interval);
|
|
359
|
+
}
|
|
360
|
+
}, {
|
|
361
|
+
key: "isStatus",
|
|
362
|
+
value: function isStatus(status) {
|
|
363
|
+
return this.state.status === status;
|
|
364
|
+
}
|
|
365
|
+
}, {
|
|
366
|
+
key: "setTimeDeltaState",
|
|
367
|
+
value: function setTimeDeltaState(timeDelta, status, callback) {
|
|
368
|
+
var _this2 = this;
|
|
369
|
+
if (!this.mounted) return;
|
|
370
|
+
var completing = timeDelta.completed && !this.state.timeDelta.completed;
|
|
371
|
+
var completedOnStart = timeDelta.completed && status === "STARTED";
|
|
372
|
+
if (completing && !this.props.overtime) {
|
|
373
|
+
this.clearTimer();
|
|
374
|
+
}
|
|
375
|
+
var onDone = function onDone() {
|
|
376
|
+
if (callback) callback(_this2.state.timeDelta);
|
|
377
|
+
if (_this2.props.onComplete && (completing || completedOnStart)) {
|
|
378
|
+
_this2.props.onComplete(timeDelta, completedOnStart);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
return this.setState(function (prevState) {
|
|
382
|
+
var newStatus = status || prevState.status;
|
|
383
|
+
if (timeDelta.completed && !_this2.props.overtime) {
|
|
384
|
+
newStatus = "COMPLETED";
|
|
385
|
+
} else if (!status && newStatus === "COMPLETED") {
|
|
386
|
+
newStatus = "STOPPED";
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
timeDelta: timeDelta,
|
|
390
|
+
status: newStatus
|
|
391
|
+
};
|
|
392
|
+
}, onDone);
|
|
393
|
+
}
|
|
394
|
+
}, {
|
|
395
|
+
key: "getApi",
|
|
396
|
+
value: function getApi() {
|
|
397
|
+
return this.api = this.api || {
|
|
398
|
+
start: this.start,
|
|
399
|
+
pause: this.pause,
|
|
400
|
+
stop: this.stop,
|
|
401
|
+
isStarted: this.isStarted,
|
|
402
|
+
isPaused: this.isPaused,
|
|
403
|
+
isStopped: this.isStopped,
|
|
404
|
+
isCompleted: this.isCompleted
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "getRenderProps",
|
|
409
|
+
value: function getRenderProps() {
|
|
410
|
+
var _this$props2 = this.props,
|
|
411
|
+
daysInHours = _this$props2.daysInHours,
|
|
412
|
+
zeroPadTime = _this$props2.zeroPadTime,
|
|
413
|
+
zeroPadDays = _this$props2.zeroPadDays;
|
|
414
|
+
var timeDelta = this.state.timeDelta;
|
|
415
|
+
return Object.assign(Object.assign({}, timeDelta), {
|
|
416
|
+
api: this.getApi(),
|
|
417
|
+
props: this.props,
|
|
418
|
+
formatted: formatTimeDelta(timeDelta, {
|
|
419
|
+
daysInHours: daysInHours,
|
|
420
|
+
zeroPadTime: zeroPadTime,
|
|
421
|
+
zeroPadDays: zeroPadDays
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}, {
|
|
426
|
+
key: "render",
|
|
427
|
+
value: function render() {
|
|
428
|
+
if (this.legacyMode) {
|
|
429
|
+
var _this$props3 = this.props,
|
|
430
|
+
count = _this$props3.count,
|
|
431
|
+
_children = _this$props3.children,
|
|
432
|
+
onComplete = _this$props3.onComplete;
|
|
433
|
+
return createElement(Countdown, {
|
|
434
|
+
ref: this.setLegacyCountdownRef,
|
|
435
|
+
count: count,
|
|
436
|
+
onComplete: onComplete
|
|
437
|
+
}, _children);
|
|
438
|
+
}
|
|
439
|
+
var _this$props4 = this.props,
|
|
440
|
+
className = _this$props4.className,
|
|
441
|
+
overtime = _this$props4.overtime,
|
|
442
|
+
children = _this$props4.children,
|
|
443
|
+
renderer = _this$props4.renderer;
|
|
444
|
+
var renderProps = this.getRenderProps();
|
|
445
|
+
if (renderer) {
|
|
446
|
+
return renderer(renderProps);
|
|
447
|
+
}
|
|
448
|
+
if (children && this.state.timeDelta.completed && !overtime) {
|
|
449
|
+
return cloneElement(children, {
|
|
450
|
+
countdown: renderProps
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
var _renderProps$formatte = renderProps.formatted,
|
|
454
|
+
days = _renderProps$formatte.days,
|
|
455
|
+
hours = _renderProps$formatte.hours,
|
|
456
|
+
minutes = _renderProps$formatte.minutes,
|
|
457
|
+
seconds = _renderProps$formatte.seconds;
|
|
458
|
+
return createElement("span", {
|
|
459
|
+
className: className
|
|
460
|
+
}, renderProps.total < 0 ? '-' : '', days, days ? ':' : '', hours, ":", minutes, ":", seconds);
|
|
461
|
+
}
|
|
462
|
+
}]);
|
|
463
|
+
}(Component);
|
|
464
|
+
Countdown$1.defaultProps = Object.assign(Object.assign({}, timeDeltaFormatOptionsDefaults), {
|
|
465
|
+
controlled: false,
|
|
466
|
+
intervalDelay: 1000,
|
|
467
|
+
precision: 0,
|
|
468
|
+
autoStart: true
|
|
469
|
+
});
|
|
470
|
+
Countdown$1.propTypes = {};
|
|
471
|
+
|
|
472
|
+
export default Countdown$1;
|
|
473
|
+
export { calcTimeDelta, formatTimeDelta, zeroPad };
|