|
| 1 | +"use strict"; |
| 2 | +var __assign = (this && this.__assign) || function () { |
| 3 | + __assign = Object.assign || function(t) { |
| 4 | + for (var s, i = 1, n = arguments.length; i < n; i++) { |
| 5 | + s = arguments[i]; |
| 6 | + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) |
| 7 | + t[p] = s[p]; |
| 8 | + } |
| 9 | + return t; |
| 10 | + }; |
| 11 | + return __assign.apply(this, arguments); |
| 12 | +}; |
| 13 | +var __rest = (this && this.__rest) || function (s, e) { |
| 14 | + var t = {}; |
| 15 | + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) |
| 16 | + t[p] = s[p]; |
| 17 | + if (s != null && typeof Object.getOwnPropertySymbols === "function") |
| 18 | + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { |
| 19 | + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) |
| 20 | + t[p[i]] = s[p[i]]; |
| 21 | + } |
| 22 | + return t; |
| 23 | +}; |
| 24 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 25 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 26 | +}; |
| 27 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 28 | +var react_1 = __importDefault(require("react")); |
| 29 | +var material_1 = require("@mui/material"); |
| 30 | +var Countdown = function (_a) { |
| 31 | + var seconds = _a.seconds, _b = _a.start, start = _b === void 0 ? true : _b, onEnd = _a.onEnd, typographyProps = __rest(_a, ["seconds", "start", "onEnd"]); |
| 32 | + seconds = Math.floor(seconds); |
| 33 | + var _c = react_1.default.useState(seconds < 0 ? 0 : seconds), _seconds = _c[0], _setSeconds = _c[1]; |
| 34 | + var _d = react_1.default.useState(!start), end = _d[0], setEnd = _d[1]; |
| 35 | + react_1.default.useEffect(function () { |
| 36 | + if (!end) { |
| 37 | + if (_seconds > 0) { |
| 38 | + setTimeout(function () { _setSeconds(_seconds - 1); }, 1000); |
| 39 | + } |
| 40 | + else { |
| 41 | + setEnd(true); |
| 42 | + onEnd(); |
| 43 | + } |
| 44 | + } |
| 45 | + }, [_seconds]); |
| 46 | + seconds = Math.floor(_seconds % 60); |
| 47 | + var minutes = Math.floor(_seconds / 60); |
| 48 | + return react_1.default.createElement(react_1.default.Fragment, null, _seconds > 0 && |
| 49 | + react_1.default.createElement(material_1.Typography, __assign({}, typographyProps), |
| 50 | + minutes > 0 && ("".concat(minutes, " ").concat(minutes > 1 ? 'mins' : 'min', " ")), |
| 51 | + seconds > 0 && ("".concat(seconds, " ").concat(seconds > 1 ? 'secs' : 'sec')))); |
| 52 | +}; |
| 53 | +exports.default = Countdown; |
0 commit comments