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