Latest updates from IceHrmPro
This commit is contained in:
22
web/node_modules/antd/es/statistic/Countdown.d.ts
generated
vendored
Normal file
22
web/node_modules/antd/es/statistic/Countdown.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as React from 'react';
|
||||
import { StatisticProps } from './Statistic';
|
||||
import { countdownValueType, FormatConfig } from './utils';
|
||||
interface CountdownProps extends StatisticProps {
|
||||
value?: countdownValueType;
|
||||
format?: string;
|
||||
onFinish?: () => void;
|
||||
}
|
||||
declare class Countdown extends React.Component<CountdownProps, {}> {
|
||||
static defaultProps: Partial<CountdownProps>;
|
||||
countdownId?: number;
|
||||
componentDidMount(): void;
|
||||
componentDidUpdate(): void;
|
||||
componentWillUnmount(): void;
|
||||
syncTimer: () => void;
|
||||
startTimer: () => void;
|
||||
stopTimer: () => void;
|
||||
formatCountdown: (value: React.ReactText, config: FormatConfig) => string;
|
||||
valueRender: (node: React.ReactElement<HTMLDivElement, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>) => React.ReactElement<HTMLDivElement, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default Countdown;
|
||||
129
web/node_modules/antd/es/statistic/Countdown.js
generated
vendored
Normal file
129
web/node_modules/antd/es/statistic/Countdown.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
import * as React from 'react';
|
||||
import Statistic from './Statistic';
|
||||
import { formatCountdown } from './utils';
|
||||
var REFRESH_INTERVAL = 1000 / 30;
|
||||
|
||||
function getTime(value) {
|
||||
return new Date(value).getTime();
|
||||
}
|
||||
|
||||
var Countdown = /*#__PURE__*/function (_React$Component) {
|
||||
_inherits(Countdown, _React$Component);
|
||||
|
||||
var _super = _createSuper(Countdown);
|
||||
|
||||
function Countdown() {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Countdown);
|
||||
|
||||
_this = _super.apply(this, arguments);
|
||||
|
||||
_this.syncTimer = function () {
|
||||
var value = _this.props.value;
|
||||
var timestamp = getTime(value);
|
||||
|
||||
if (timestamp >= Date.now()) {
|
||||
_this.startTimer();
|
||||
} else {
|
||||
_this.stopTimer();
|
||||
}
|
||||
};
|
||||
|
||||
_this.startTimer = function () {
|
||||
if (_this.countdownId) return;
|
||||
_this.countdownId = window.setInterval(function () {
|
||||
_this.forceUpdate();
|
||||
}, REFRESH_INTERVAL);
|
||||
};
|
||||
|
||||
_this.stopTimer = function () {
|
||||
var _this$props = _this.props,
|
||||
onFinish = _this$props.onFinish,
|
||||
value = _this$props.value;
|
||||
|
||||
if (_this.countdownId) {
|
||||
clearInterval(_this.countdownId);
|
||||
_this.countdownId = undefined;
|
||||
var timestamp = getTime(value);
|
||||
|
||||
if (onFinish && timestamp < Date.now()) {
|
||||
onFinish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_this.formatCountdown = function (value, config) {
|
||||
var format = _this.props.format;
|
||||
return formatCountdown(value, _extends(_extends({}, config), {
|
||||
format: format
|
||||
}));
|
||||
}; // Countdown do not need display the timestamp
|
||||
|
||||
|
||||
_this.valueRender = function (node) {
|
||||
return React.cloneElement(node, {
|
||||
title: undefined
|
||||
});
|
||||
};
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Countdown, [{
|
||||
key: "componentDidMount",
|
||||
value: function componentDidMount() {
|
||||
this.syncTimer();
|
||||
}
|
||||
}, {
|
||||
key: "componentDidUpdate",
|
||||
value: function componentDidUpdate() {
|
||||
this.syncTimer();
|
||||
}
|
||||
}, {
|
||||
key: "componentWillUnmount",
|
||||
value: function componentWillUnmount() {
|
||||
this.stopTimer();
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
return /*#__PURE__*/React.createElement(Statistic, _extends({
|
||||
valueRender: this.valueRender
|
||||
}, this.props, {
|
||||
formatter: this.formatCountdown
|
||||
}));
|
||||
}
|
||||
}]);
|
||||
|
||||
return Countdown;
|
||||
}(React.Component);
|
||||
|
||||
Countdown.defaultProps = {
|
||||
format: 'HH:mm:ss'
|
||||
};
|
||||
export default Countdown;
|
||||
7
web/node_modules/antd/es/statistic/Number.d.ts
generated
vendored
Normal file
7
web/node_modules/antd/es/statistic/Number.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { valueType, FormatConfig } from './utils';
|
||||
interface NumberProps extends FormatConfig {
|
||||
value: valueType;
|
||||
}
|
||||
declare const StatisticNumber: React.FC<NumberProps>;
|
||||
export default StatisticNumber;
|
||||
55
web/node_modules/antd/es/statistic/Number.js
generated
vendored
Normal file
55
web/node_modules/antd/es/statistic/Number.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import * as React from 'react';
|
||||
import padEnd from 'lodash/padEnd';
|
||||
|
||||
var StatisticNumber = function StatisticNumber(props) {
|
||||
var value = props.value,
|
||||
formatter = props.formatter,
|
||||
precision = props.precision,
|
||||
decimalSeparator = props.decimalSeparator,
|
||||
_props$groupSeparator = props.groupSeparator,
|
||||
groupSeparator = _props$groupSeparator === void 0 ? '' : _props$groupSeparator,
|
||||
prefixCls = props.prefixCls;
|
||||
var valueNode;
|
||||
|
||||
if (typeof formatter === 'function') {
|
||||
// Customize formatter
|
||||
valueNode = formatter(value);
|
||||
} else {
|
||||
// Internal formatter
|
||||
var val = String(value);
|
||||
var cells = val.match(/^(-?)(\d*)(\.(\d+))?$/); // Process if illegal number
|
||||
|
||||
if (!cells || val === '-') {
|
||||
valueNode = val;
|
||||
} else {
|
||||
var negative = cells[1];
|
||||
|
||||
var _int = cells[2] || '0';
|
||||
|
||||
var decimal = cells[4] || '';
|
||||
_int = _int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
|
||||
|
||||
if (typeof precision === 'number') {
|
||||
decimal = padEnd(decimal, precision, '0').slice(0, precision);
|
||||
}
|
||||
|
||||
if (decimal) {
|
||||
decimal = "".concat(decimalSeparator).concat(decimal);
|
||||
}
|
||||
|
||||
valueNode = [/*#__PURE__*/React.createElement("span", {
|
||||
key: "int",
|
||||
className: "".concat(prefixCls, "-content-value-int")
|
||||
}, negative, _int), decimal && /*#__PURE__*/React.createElement("span", {
|
||||
key: "decimal",
|
||||
className: "".concat(prefixCls, "-content-value-decimal")
|
||||
}, decimal)];
|
||||
}
|
||||
}
|
||||
|
||||
return /*#__PURE__*/React.createElement("span", {
|
||||
className: "".concat(prefixCls, "-content-value")
|
||||
}, valueNode);
|
||||
};
|
||||
|
||||
export default StatisticNumber;
|
||||
19
web/node_modules/antd/es/statistic/Statistic.d.ts
generated
vendored
Normal file
19
web/node_modules/antd/es/statistic/Statistic.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import Countdown from './Countdown';
|
||||
import { valueType, FormatConfig } from './utils';
|
||||
interface StatisticComponent {
|
||||
Countdown: typeof Countdown;
|
||||
}
|
||||
export interface StatisticProps extends FormatConfig {
|
||||
prefixCls?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
value?: valueType;
|
||||
valueStyle?: React.CSSProperties;
|
||||
valueRender?: (node: React.ReactNode) => React.ReactNode;
|
||||
title?: React.ReactNode;
|
||||
prefix?: React.ReactNode;
|
||||
suffix?: React.ReactNode;
|
||||
}
|
||||
declare const WrapperStatistic: React.FC<StatisticProps> & StatisticComponent;
|
||||
export default WrapperStatistic;
|
||||
53
web/node_modules/antd/es/statistic/Statistic.js
generated
vendored
Normal file
53
web/node_modules/antd/es/statistic/Statistic.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
||||
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { withConfigConsumer } from '../config-provider/context';
|
||||
import StatisticNumber from './Number';
|
||||
|
||||
var Statistic = function Statistic(props) {
|
||||
var prefixCls = props.prefixCls,
|
||||
className = props.className,
|
||||
style = props.style,
|
||||
valueStyle = props.valueStyle,
|
||||
_props$value = props.value,
|
||||
value = _props$value === void 0 ? 0 : _props$value,
|
||||
title = props.title,
|
||||
valueRender = props.valueRender,
|
||||
prefix = props.prefix,
|
||||
suffix = props.suffix,
|
||||
direction = props.direction;
|
||||
var valueNode = /*#__PURE__*/React.createElement(StatisticNumber, _extends({}, props, {
|
||||
value: value
|
||||
}));
|
||||
|
||||
if (valueRender) {
|
||||
valueNode = valueRender(valueNode);
|
||||
}
|
||||
|
||||
var cls = classNames(prefixCls, className, _defineProperty({}, "".concat(prefixCls, "-rtl"), direction === 'rtl'));
|
||||
return /*#__PURE__*/React.createElement("div", {
|
||||
className: cls,
|
||||
style: style
|
||||
}, title && /*#__PURE__*/React.createElement("div", {
|
||||
className: "".concat(prefixCls, "-title")
|
||||
}, title), /*#__PURE__*/React.createElement("div", {
|
||||
style: valueStyle,
|
||||
className: "".concat(prefixCls, "-content")
|
||||
}, prefix && /*#__PURE__*/React.createElement("span", {
|
||||
className: "".concat(prefixCls, "-content-prefix")
|
||||
}, prefix), valueNode, suffix && /*#__PURE__*/React.createElement("span", {
|
||||
className: "".concat(prefixCls, "-content-suffix")
|
||||
}, suffix)));
|
||||
};
|
||||
|
||||
Statistic.defaultProps = {
|
||||
decimalSeparator: '.',
|
||||
groupSeparator: ','
|
||||
};
|
||||
var WrapperStatistic = withConfigConsumer({
|
||||
prefixCls: 'statistic'
|
||||
})(Statistic);
|
||||
export default WrapperStatistic;
|
||||
2
web/node_modules/antd/es/statistic/index.d.ts
generated
vendored
Normal file
2
web/node_modules/antd/es/statistic/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import Statistic from './Statistic';
|
||||
export default Statistic;
|
||||
4
web/node_modules/antd/es/statistic/index.js
generated
vendored
Normal file
4
web/node_modules/antd/es/statistic/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import Statistic from './Statistic';
|
||||
import Countdown from './Countdown';
|
||||
Statistic.Countdown = Countdown;
|
||||
export default Statistic;
|
||||
2
web/node_modules/antd/es/statistic/style/css.js
generated
vendored
Normal file
2
web/node_modules/antd/es/statistic/style/css.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import '../../style/index.css';
|
||||
import './index.css';
|
||||
52
web/node_modules/antd/es/statistic/style/index.css
generated
vendored
Normal file
52
web/node_modules/antd/es/statistic/style/index.css
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/* stylelint-disable at-rule-empty-line-before,at-rule-name-space-after,at-rule-no-unknown */
|
||||
/* stylelint-disable no-duplicate-selectors */
|
||||
/* stylelint-disable */
|
||||
/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */
|
||||
.ant-statistic {
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: rgba(0, 0, 0, 0.65);
|
||||
font-size: 14px;
|
||||
font-variant: tabular-nums;
|
||||
line-height: 1.5715;
|
||||
list-style: none;
|
||||
-webkit-font-feature-settings: 'tnum';
|
||||
font-feature-settings: 'tnum';
|
||||
}
|
||||
.ant-statistic-title {
|
||||
margin-bottom: 4px;
|
||||
color: rgba(0, 0, 0, 0.45);
|
||||
font-size: 14px;
|
||||
}
|
||||
.ant-statistic-content {
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
font-size: 24px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
||||
}
|
||||
.ant-statistic-content-value-decimal {
|
||||
font-size: 16px;
|
||||
}
|
||||
.ant-statistic-content-prefix,
|
||||
.ant-statistic-content-suffix {
|
||||
display: inline-block;
|
||||
}
|
||||
.ant-statistic-content-prefix {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.ant-statistic-content-suffix {
|
||||
margin-left: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
.ant-statistic-rtl {
|
||||
direction: rtl;
|
||||
}
|
||||
.ant-statistic-rtl .ant-statistic-content-prefix {
|
||||
margin-right: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.ant-statistic-rtl .ant-statistic-content-suffix {
|
||||
margin-right: 4px;
|
||||
margin-left: 0;
|
||||
}
|
||||
2
web/node_modules/antd/es/statistic/style/index.d.ts
generated
vendored
Normal file
2
web/node_modules/antd/es/statistic/style/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import '../../style/index.less';
|
||||
import './index.less';
|
||||
2
web/node_modules/antd/es/statistic/style/index.js
generated
vendored
Normal file
2
web/node_modules/antd/es/statistic/style/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import '../../style/index.less';
|
||||
import './index.less';
|
||||
42
web/node_modules/antd/es/statistic/style/index.less
generated
vendored
Normal file
42
web/node_modules/antd/es/statistic/style/index.less
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
@import '../../style/themes/index';
|
||||
@import '../../style/mixins/index';
|
||||
|
||||
@statistic-prefix-cls: ~'@{ant-prefix}-statistic';
|
||||
|
||||
.@{statistic-prefix-cls} {
|
||||
.reset-component;
|
||||
|
||||
&-title {
|
||||
margin-bottom: @margin-xss;
|
||||
color: @text-color-secondary;
|
||||
font-size: @statistic-title-font-size;
|
||||
}
|
||||
|
||||
&-content {
|
||||
color: @heading-color;
|
||||
font-size: @statistic-content-font-size;
|
||||
font-family: @statistic-font-family;
|
||||
|
||||
&-value {
|
||||
&-decimal {
|
||||
font-size: @statistic-unit-font-size;
|
||||
}
|
||||
}
|
||||
|
||||
&-prefix,
|
||||
&-suffix {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&-prefix {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
&-suffix {
|
||||
margin-left: 4px;
|
||||
font-size: @statistic-unit-font-size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@import './rtl';
|
||||
26
web/node_modules/antd/es/statistic/style/rtl.less
generated
vendored
Normal file
26
web/node_modules/antd/es/statistic/style/rtl.less
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
@import '../../style/themes/index';
|
||||
@import '../../style/mixins/index';
|
||||
|
||||
@statistic-prefix-cls: ~'@{ant-prefix}-statistic';
|
||||
|
||||
.@{statistic-prefix-cls} {
|
||||
&-rtl {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
&-content {
|
||||
&-prefix {
|
||||
.@{statistic-prefix-cls}-rtl & {
|
||||
margin-right: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
&-suffix {
|
||||
.@{statistic-prefix-cls}-rtl & {
|
||||
margin-right: 4px;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
web/node_modules/antd/es/statistic/utils.d.ts
generated
vendored
Normal file
16
web/node_modules/antd/es/statistic/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
export declare type valueType = number | string;
|
||||
export declare type countdownValueType = valueType | string;
|
||||
export declare type Formatter = false | 'number' | 'countdown' | ((value: valueType, config?: FormatConfig) => React.ReactNode);
|
||||
export interface FormatConfig {
|
||||
formatter?: Formatter;
|
||||
decimalSeparator?: string;
|
||||
groupSeparator?: string;
|
||||
precision?: number;
|
||||
prefixCls?: string;
|
||||
}
|
||||
export interface CountdownFormatConfig extends FormatConfig {
|
||||
format?: string;
|
||||
}
|
||||
export declare function formatTimeStr(duration: number, format: string): string;
|
||||
export declare function formatCountdown(value: countdownValueType, config: CountdownFormatConfig): string;
|
||||
53
web/node_modules/antd/es/statistic/utils.js
generated
vendored
Normal file
53
web/node_modules/antd/es/statistic/utils.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
import padStart from 'lodash/padStart'; // Countdown
|
||||
|
||||
var timeUnits = [['Y', 1000 * 60 * 60 * 24 * 365], ['M', 1000 * 60 * 60 * 24 * 30], ['D', 1000 * 60 * 60 * 24], ['H', 1000 * 60 * 60], ['m', 1000 * 60], ['s', 1000], ['S', 1]];
|
||||
export function formatTimeStr(duration, format) {
|
||||
var leftDuration = duration;
|
||||
var escapeRegex = /\[[^\]]*]/g;
|
||||
var keepList = (format.match(escapeRegex) || []).map(function (str) {
|
||||
return str.slice(1, -1);
|
||||
});
|
||||
var templateText = format.replace(escapeRegex, '[]');
|
||||
var replacedText = timeUnits.reduce(function (current, _ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
name = _ref2[0],
|
||||
unit = _ref2[1];
|
||||
|
||||
if (current.indexOf(name) !== -1) {
|
||||
var value = Math.floor(leftDuration / unit);
|
||||
leftDuration -= value * unit;
|
||||
return current.replace(new RegExp("".concat(name, "+"), 'g'), function (match) {
|
||||
var len = match.length;
|
||||
return padStart(value.toString(), len, '0');
|
||||
});
|
||||
}
|
||||
|
||||
return current;
|
||||
}, templateText);
|
||||
var index = 0;
|
||||
return replacedText.replace(escapeRegex, function () {
|
||||
var match = keepList[index];
|
||||
index += 1;
|
||||
return match;
|
||||
});
|
||||
}
|
||||
export function formatCountdown(value, config) {
|
||||
var _config$format = config.format,
|
||||
format = _config$format === void 0 ? '' : _config$format;
|
||||
var target = new Date(value).getTime();
|
||||
var current = Date.now();
|
||||
var diff = Math.max(target - current, 0);
|
||||
return formatTimeStr(diff, format);
|
||||
}
|
||||
Reference in New Issue
Block a user