@arcblock/ux 2.0.4 → 2.0.7
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/lib/RelativeTime/index.js +47 -7
- package/package.json +5 -5
- package/src/RelativeTime/index.js +37 -4
|
@@ -23,9 +23,11 @@ var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
|
|
|
23
23
|
|
|
24
24
|
var _timezone = _interopRequireDefault(require("dayjs/plugin/timezone"));
|
|
25
25
|
|
|
26
|
+
var _updateLocale = _interopRequireDefault(require("dayjs/plugin/updateLocale"));
|
|
27
|
+
|
|
26
28
|
var _Util = require("../Util");
|
|
27
29
|
|
|
28
|
-
const _excluded = ["value", "locale"];
|
|
30
|
+
const _excluded = ["value", "locale", "withoutSuffix", "from", "to"];
|
|
29
31
|
|
|
30
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
33
|
|
|
@@ -39,14 +41,38 @@ _dayjs.default.extend(_utc.default);
|
|
|
39
41
|
|
|
40
42
|
_dayjs.default.extend(_timezone.default);
|
|
41
43
|
|
|
44
|
+
_dayjs.default.extend(_updateLocale.default);
|
|
45
|
+
|
|
42
46
|
_dayjs.default.extend(_relativeTime.default);
|
|
43
47
|
|
|
48
|
+
_dayjs.default.updateLocale('zh-cn', {
|
|
49
|
+
// copy with https://github.com/iamkun/dayjs/blob/dev/src/locale/zh-cn.js
|
|
50
|
+
relativeTime: {
|
|
51
|
+
future: '%s后',
|
|
52
|
+
past: '%s前',
|
|
53
|
+
s: '几秒',
|
|
54
|
+
m: '1 分钟',
|
|
55
|
+
mm: '%d 分钟',
|
|
56
|
+
h: '1 小时',
|
|
57
|
+
hh: '%d 小时',
|
|
58
|
+
d: '1 天',
|
|
59
|
+
dd: '%d 天',
|
|
60
|
+
M: '1 个月',
|
|
61
|
+
MM: '%d 个月',
|
|
62
|
+
y: '1 年',
|
|
63
|
+
yy: '%d 年'
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
44
67
|
(0, _Util.setDateTool)(_dayjs.default);
|
|
45
68
|
|
|
46
69
|
function RelativeTime(_ref) {
|
|
47
70
|
let {
|
|
48
71
|
value,
|
|
49
|
-
locale
|
|
72
|
+
locale,
|
|
73
|
+
withoutSuffix,
|
|
74
|
+
from,
|
|
75
|
+
to
|
|
50
76
|
} = _ref,
|
|
51
77
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
52
78
|
|
|
@@ -55,7 +81,16 @@ function RelativeTime(_ref) {
|
|
|
55
81
|
}
|
|
56
82
|
|
|
57
83
|
const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
|
|
58
|
-
|
|
84
|
+
let innerContent;
|
|
85
|
+
|
|
86
|
+
if (from) {
|
|
87
|
+
innerContent = (0, _dayjs.default)(value).locale(localeOption).from(from, withoutSuffix);
|
|
88
|
+
} else if (to) {
|
|
89
|
+
innerContent = (0, _dayjs.default)(value).locale(localeOption).to(to, withoutSuffix);
|
|
90
|
+
} else {
|
|
91
|
+
innerContent = (0, _dayjs.default)(value).locale(localeOption).fromNow(withoutSuffix);
|
|
92
|
+
}
|
|
93
|
+
|
|
59
94
|
return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
|
|
60
95
|
title: (0, _Util.formatToDatetime)(value, {
|
|
61
96
|
locale: localeOption
|
|
@@ -66,10 +101,15 @@ function RelativeTime(_ref) {
|
|
|
66
101
|
}
|
|
67
102
|
|
|
68
103
|
RelativeTime.propTypes = {
|
|
69
|
-
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
70
|
-
locale: _propTypes.default.string
|
|
104
|
+
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
|
|
105
|
+
locale: _propTypes.default.string,
|
|
106
|
+
withoutSuffix: _propTypes.default.bool,
|
|
107
|
+
from: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
108
|
+
to: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
71
109
|
};
|
|
72
110
|
RelativeTime.defaultProps = {
|
|
73
|
-
|
|
74
|
-
|
|
111
|
+
locale: 'en',
|
|
112
|
+
withoutSuffix: false,
|
|
113
|
+
from: '',
|
|
114
|
+
to: ''
|
|
75
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@babel/preset-react": "^7.8.3",
|
|
44
44
|
"babel-plugin-inline-react-svg": "^1.1.1",
|
|
45
45
|
"babel-plugin-styled-components": "^1.10.7",
|
|
46
|
-
"dayjs": "^1.11.2",
|
|
47
46
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
48
47
|
"jest": "^24.1.0",
|
|
49
48
|
"moment-timezone": "^0.5.33"
|
|
@@ -53,10 +52,10 @@
|
|
|
53
52
|
"react": ">=18.1.0",
|
|
54
53
|
"react-ga": "^2.7.0"
|
|
55
54
|
},
|
|
56
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "f5be0b3d27f13a1ffe3938a2b21344af6fff7712",
|
|
57
56
|
"dependencies": {
|
|
58
|
-
"@arcblock/icons": "^2.0.
|
|
59
|
-
"@arcblock/react-hooks": "^2.0.
|
|
57
|
+
"@arcblock/icons": "^2.0.7",
|
|
58
|
+
"@arcblock/react-hooks": "^2.0.7",
|
|
60
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
61
60
|
"@emotion/react": "^11.9.0",
|
|
62
61
|
"@emotion/styled": "^11.8.1",
|
|
@@ -69,6 +68,7 @@
|
|
|
69
68
|
"copy-to-clipboard": "^3.2.0",
|
|
70
69
|
"core-js": "^3.6.4",
|
|
71
70
|
"d3-geo": "^1.11.6",
|
|
71
|
+
"dayjs": "^1.11.2",
|
|
72
72
|
"devices.css": "^0.1.15",
|
|
73
73
|
"highlight.js": "^9.15.8",
|
|
74
74
|
"is-svg": "^4.3.1",
|
|
@@ -7,22 +7,50 @@ import Tooltip from '@mui/material/Tooltip';
|
|
|
7
7
|
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
8
8
|
import utc from 'dayjs/plugin/utc';
|
|
9
9
|
import timezone from 'dayjs/plugin/timezone';
|
|
10
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
10
11
|
import { formatToDatetime, setDateTool } from '../Util';
|
|
11
12
|
|
|
12
13
|
dayjs.extend(localizedFormat);
|
|
13
14
|
dayjs.extend(utc);
|
|
14
15
|
dayjs.extend(timezone);
|
|
16
|
+
dayjs.extend(updateLocale);
|
|
15
17
|
dayjs.extend(relativeTime);
|
|
18
|
+
dayjs.updateLocale('zh-cn', {
|
|
19
|
+
// copy with https://github.com/iamkun/dayjs/blob/dev/src/locale/zh-cn.js
|
|
20
|
+
relativeTime: {
|
|
21
|
+
future: '%s后',
|
|
22
|
+
past: '%s前',
|
|
23
|
+
s: '几秒',
|
|
24
|
+
m: '1 分钟',
|
|
25
|
+
mm: '%d 分钟',
|
|
26
|
+
h: '1 小时',
|
|
27
|
+
hh: '%d 小时',
|
|
28
|
+
d: '1 天',
|
|
29
|
+
dd: '%d 天',
|
|
30
|
+
M: '1 个月',
|
|
31
|
+
MM: '%d 个月',
|
|
32
|
+
y: '1 年',
|
|
33
|
+
yy: '%d 年',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
16
36
|
setDateTool(dayjs);
|
|
17
37
|
|
|
18
|
-
export default function RelativeTime({ value, locale, ...rest }) {
|
|
38
|
+
export default function RelativeTime({ value, locale, withoutSuffix, from, to, ...rest }) {
|
|
19
39
|
if (!value) {
|
|
20
40
|
return '-';
|
|
21
41
|
}
|
|
22
42
|
|
|
23
43
|
const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
|
|
24
44
|
|
|
25
|
-
|
|
45
|
+
let innerContent;
|
|
46
|
+
|
|
47
|
+
if (from) {
|
|
48
|
+
innerContent = dayjs(value).locale(localeOption).from(from, withoutSuffix);
|
|
49
|
+
} else if (to) {
|
|
50
|
+
innerContent = dayjs(value).locale(localeOption).to(to, withoutSuffix);
|
|
51
|
+
} else {
|
|
52
|
+
innerContent = dayjs(value).locale(localeOption).fromNow(withoutSuffix);
|
|
53
|
+
}
|
|
26
54
|
|
|
27
55
|
return (
|
|
28
56
|
<Tooltip
|
|
@@ -35,11 +63,16 @@ export default function RelativeTime({ value, locale, ...rest }) {
|
|
|
35
63
|
}
|
|
36
64
|
|
|
37
65
|
RelativeTime.propTypes = {
|
|
38
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
66
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
39
67
|
locale: PropTypes.string,
|
|
68
|
+
withoutSuffix: PropTypes.bool,
|
|
69
|
+
from: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
70
|
+
to: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
40
71
|
};
|
|
41
72
|
|
|
42
73
|
RelativeTime.defaultProps = {
|
|
43
|
-
value: '',
|
|
44
74
|
locale: 'en',
|
|
75
|
+
withoutSuffix: false,
|
|
76
|
+
from: '',
|
|
77
|
+
to: '',
|
|
45
78
|
};
|