@arcblock/ux 2.0.2 → 2.0.5

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.
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = RelativeTime;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));
13
+
14
+ var _dayjs = _interopRequireDefault(require("dayjs"));
15
+
16
+ require("dayjs/locale/zh-cn");
17
+
18
+ var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
19
+
20
+ var _localizedFormat = _interopRequireDefault(require("dayjs/plugin/localizedFormat"));
21
+
22
+ var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
23
+
24
+ var _timezone = _interopRequireDefault(require("dayjs/plugin/timezone"));
25
+
26
+ var _updateLocale = _interopRequireDefault(require("dayjs/plugin/updateLocale"));
27
+
28
+ var _Util = require("../Util");
29
+
30
+ const _excluded = ["value", "locale", "withoutSuffix", "from", "to"];
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
35
+
36
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
37
+
38
+ _dayjs.default.extend(_localizedFormat.default);
39
+
40
+ _dayjs.default.extend(_utc.default);
41
+
42
+ _dayjs.default.extend(_timezone.default);
43
+
44
+ _dayjs.default.extend(_updateLocale.default);
45
+
46
+ _dayjs.default.extend(_relativeTime.default);
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
+
67
+ (0, _Util.setDateTool)(_dayjs.default);
68
+
69
+ function RelativeTime(_ref) {
70
+ let {
71
+ value,
72
+ locale,
73
+ withoutSuffix,
74
+ from,
75
+ to
76
+ } = _ref,
77
+ rest = _objectWithoutProperties(_ref, _excluded);
78
+
79
+ if (!value) {
80
+ return '-';
81
+ }
82
+
83
+ const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
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
+
94
+ return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
95
+ title: (0, _Util.formatToDatetime)(value, {
96
+ locale: localeOption
97
+ }),
98
+ placement: "top-end",
99
+ enterTouchDelay: 0
100
+ }, /*#__PURE__*/_react.default.createElement("span", rest, innerContent));
101
+ }
102
+
103
+ RelativeTime.propTypes = {
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])
109
+ };
110
+ RelativeTime.defaultProps = {
111
+ locale: 'en',
112
+ withoutSuffix: false,
113
+ from: '',
114
+ to: ''
115
+ };
package/lib/index.js CHANGED
@@ -105,6 +105,12 @@ Object.defineProperty(exports, "Logo", {
105
105
  return _Logo.default;
106
106
  }
107
107
  });
108
+ Object.defineProperty(exports, "RelativeTime", {
109
+ enumerable: true,
110
+ get: function get() {
111
+ return _RelativeTime.default;
112
+ }
113
+ });
108
114
  Object.defineProperty(exports, "Tabs", {
109
115
  enumerable: true,
110
116
  get: function get() {
@@ -222,6 +228,8 @@ var _selector = _interopRequireDefault(require("./Locale/selector"));
222
228
 
223
229
  var _Logo = _interopRequireDefault(require("./Logo"));
224
230
 
231
+ var _RelativeTime = _interopRequireDefault(require("./RelativeTime"));
232
+
225
233
  var _Tabs = _interopRequireDefault(require("./Tabs"));
226
234
 
227
235
  var _Tag = _interopRequireDefault(require("./Tag"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.0.2",
3
+ "version": "2.0.5",
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.10.6",
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": "319d3e6d884b5f79311edca8aab7a9ed17a17b74",
55
+ "gitHead": "639eab0c9b2030d317a671f2aea6ec47972b6050",
57
56
  "dependencies": {
58
- "@arcblock/icons": "^2.0.2",
59
- "@arcblock/react-hooks": "^2.0.2",
57
+ "@arcblock/icons": "^2.0.5",
58
+ "@arcblock/react-hooks": "^2.0.5",
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",
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import relativeTime from 'dayjs/plugin/relativeTime';
4
+ import dayjs from 'dayjs';
5
+ import 'dayjs/locale/zh-cn';
6
+ import Tooltip from '@mui/material/Tooltip';
7
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
8
+ import utc from 'dayjs/plugin/utc';
9
+ import timezone from 'dayjs/plugin/timezone';
10
+ import updateLocale from 'dayjs/plugin/updateLocale';
11
+ import { formatToDatetime, setDateTool } from '../Util';
12
+
13
+ dayjs.extend(localizedFormat);
14
+ dayjs.extend(utc);
15
+ dayjs.extend(timezone);
16
+ dayjs.extend(updateLocale);
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
+ });
36
+ setDateTool(dayjs);
37
+
38
+ export default function RelativeTime({ value, locale, withoutSuffix, from, to, ...rest }) {
39
+ if (!value) {
40
+ return '-';
41
+ }
42
+
43
+ const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
44
+
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
+ }
54
+
55
+ return (
56
+ <Tooltip
57
+ title={formatToDatetime(value, { locale: localeOption })}
58
+ placement="top-end"
59
+ enterTouchDelay={0}>
60
+ <span {...rest}>{innerContent}</span>
61
+ </Tooltip>
62
+ );
63
+ }
64
+
65
+ RelativeTime.propTypes = {
66
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
67
+ locale: PropTypes.string,
68
+ withoutSuffix: PropTypes.bool,
69
+ from: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
70
+ to: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
71
+ };
72
+
73
+ RelativeTime.defaultProps = {
74
+ locale: 'en',
75
+ withoutSuffix: false,
76
+ from: '',
77
+ to: '',
78
+ };
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ import Footer from './Footer';
14
14
  import Icon from './Icon';
15
15
  import LocaleSelector from './Locale/selector';
16
16
  import Logo from './Logo';
17
+ import RelativeTime from './RelativeTime';
17
18
  import Tabs from './Tabs';
18
19
  import Tag from './Tag';
19
20
  import Terminal from './Terminal';
@@ -48,6 +49,7 @@ export {
48
49
  LocaleSelector,
49
50
  Logo,
50
51
  Tabs,
52
+ RelativeTime,
51
53
  Tag,
52
54
  Terminal,
53
55
  TerminalPlayer,