@arcblock/ux 2.13.29 → 2.13.31
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.d.ts +3 -2
- package/lib/RelativeTime/index.js +41 -27
- package/package.json +6 -6
- package/src/RelativeTime/index.tsx +46 -25
@@ -10,6 +10,7 @@ export interface RelativeTimeProps {
|
|
10
10
|
tz?: string;
|
11
11
|
relativeRange?: number;
|
12
12
|
enableTooltip?: boolean;
|
13
|
-
|
13
|
+
useShortTimezone?: boolean;
|
14
|
+
disableTimezone?: boolean;
|
14
15
|
}
|
15
|
-
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip,
|
16
|
+
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip, useShortTimezone, disableTimezone, ...rest }: RelativeTimeProps): import("react/jsx-runtime").JSX.Element;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { Box, Tooltip } from '@mui/material';
|
3
|
-
import { useState } from 'react';
|
3
|
+
import { useState, useMemo } from 'react';
|
4
4
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
5
5
|
import dayjs from 'dayjs';
|
6
6
|
import 'dayjs/locale/zh-cn';
|
@@ -36,10 +36,16 @@ dayjs.updateLocale('zh-cn', {
|
|
36
36
|
setDateTool(dayjs);
|
37
37
|
const translations = {
|
38
38
|
en: {
|
39
|
-
utc: '
|
39
|
+
utc: 'UTC Timezone',
|
40
|
+
local: 'Local Timezone',
|
41
|
+
shortUTC: 'UTC',
|
42
|
+
shortLocal: 'Local'
|
40
43
|
},
|
41
44
|
zh: {
|
42
|
-
utc: '
|
45
|
+
utc: 'UTC 时区',
|
46
|
+
local: '本地时区',
|
47
|
+
shortUTC: 'UTC',
|
48
|
+
shortLocal: '本地'
|
43
49
|
}
|
44
50
|
};
|
45
51
|
function useRelativeTime({
|
@@ -134,9 +140,16 @@ function UTCChip({
|
|
134
140
|
sign,
|
135
141
|
hoursOffset,
|
136
142
|
setIsUtc,
|
137
|
-
|
143
|
+
useShortTimezone = true
|
138
144
|
}) {
|
139
|
-
const
|
145
|
+
const text = useMemo(() => {
|
146
|
+
const UTC = useShortTimezone ? 'shortUTC' : 'utc';
|
147
|
+
const LOCAL = useShortTimezone ? 'shortLocal' : 'local';
|
148
|
+
if (isUtc) {
|
149
|
+
return `${translations[locale][UTC]}`;
|
150
|
+
}
|
151
|
+
return `${translations[locale][LOCAL]}`;
|
152
|
+
}, [locale, useShortTimezone, isUtc]);
|
140
153
|
return /*#__PURE__*/_jsx(Box, {
|
141
154
|
component: "span",
|
142
155
|
sx: {
|
@@ -150,7 +163,7 @@ function UTCChip({
|
|
150
163
|
lineHeight: 1
|
151
164
|
},
|
152
165
|
onClick: () => setIsUtc(r => !r),
|
153
|
-
children:
|
166
|
+
children: text
|
154
167
|
});
|
155
168
|
}
|
156
169
|
export default function RelativeTime({
|
@@ -163,7 +176,8 @@ export default function RelativeTime({
|
|
163
176
|
tz,
|
164
177
|
relativeRange,
|
165
178
|
enableTooltip = true,
|
166
|
-
|
179
|
+
useShortTimezone = false,
|
180
|
+
disableTimezone = false,
|
167
181
|
...rest
|
168
182
|
}) {
|
169
183
|
const {
|
@@ -190,10 +204,9 @@ export default function RelativeTime({
|
|
190
204
|
placement: "top-end",
|
191
205
|
enterTouchDelay: 0,
|
192
206
|
children: /*#__PURE__*/_jsxs(Box, {
|
193
|
-
display: "flex",
|
207
|
+
display: "inline-flex",
|
194
208
|
alignItems: "center",
|
195
209
|
gap: 0.5,
|
196
|
-
width: "max-content",
|
197
210
|
...rest,
|
198
211
|
children: [/*#__PURE__*/_jsx(Box, {
|
199
212
|
component: "span",
|
@@ -212,19 +225,21 @@ export default function RelativeTime({
|
|
212
225
|
color: 'text.secondary'
|
213
226
|
},
|
214
227
|
children: relativeString
|
215
|
-
}), /*#__PURE__*/
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
+
}), !disableTimezone && /*#__PURE__*/_jsxs(_Fragment, {
|
229
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
230
|
+
component: "span",
|
231
|
+
sx: {
|
232
|
+
color: 'inherit'
|
233
|
+
},
|
234
|
+
children: "\xB7"
|
235
|
+
}), /*#__PURE__*/_jsx(UTCChip, {
|
236
|
+
locale: locale,
|
237
|
+
isUtc: isUtc,
|
238
|
+
sign: sign,
|
239
|
+
hoursOffset: hoursOffset,
|
240
|
+
setIsUtc: setIsUtc,
|
241
|
+
useShortTimezone: useShortTimezone
|
242
|
+
})]
|
228
243
|
})]
|
229
244
|
})
|
230
245
|
});
|
@@ -234,21 +249,20 @@ export default function RelativeTime({
|
|
234
249
|
placement: "top-end",
|
235
250
|
enterTouchDelay: 0,
|
236
251
|
children: /*#__PURE__*/_jsxs(Box, {
|
237
|
-
display: "flex",
|
252
|
+
display: "inline-flex",
|
238
253
|
alignItems: "center",
|
239
254
|
gap: 1,
|
240
|
-
width: "max-content",
|
241
255
|
children: [/*#__PURE__*/_jsx(Box, {
|
242
256
|
component: "span",
|
243
257
|
...rest,
|
244
258
|
children: innerContent
|
245
|
-
}), type === 'utc' && /*#__PURE__*/_jsx(UTCChip, {
|
259
|
+
}), type === 'utc' && !disableTimezone && /*#__PURE__*/_jsx(UTCChip, {
|
246
260
|
locale: locale,
|
247
261
|
isUtc: isUtc,
|
248
262
|
sign: sign,
|
249
263
|
hoursOffset: hoursOffset,
|
250
264
|
setIsUtc: setIsUtc,
|
251
|
-
|
265
|
+
useShortTimezone: useShortTimezone
|
252
266
|
})]
|
253
267
|
})
|
254
268
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.31",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -71,14 +71,14 @@
|
|
71
71
|
"react": ">=18.2.0",
|
72
72
|
"react-router-dom": ">=6.22.3"
|
73
73
|
},
|
74
|
-
"gitHead": "
|
74
|
+
"gitHead": "66ef51b4b217d15985838eb2c058ec833c07e1cd",
|
75
75
|
"dependencies": {
|
76
76
|
"@arcblock/did-motif": "^1.1.13",
|
77
|
-
"@arcblock/icons": "^2.13.
|
78
|
-
"@arcblock/nft-display": "^2.13.
|
79
|
-
"@arcblock/react-hooks": "^2.13.
|
77
|
+
"@arcblock/icons": "^2.13.31",
|
78
|
+
"@arcblock/nft-display": "^2.13.31",
|
79
|
+
"@arcblock/react-hooks": "^2.13.31",
|
80
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
81
|
-
"@blocklet/theme": "^2.13.
|
81
|
+
"@blocklet/theme": "^2.13.31",
|
82
82
|
"@fontsource/roboto": "~5.1.1",
|
83
83
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
84
84
|
"@iconify-icons/logos": "^1.2.36",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Box, Tooltip } from '@mui/material';
|
2
|
-
import { useState } from 'react';
|
2
|
+
import { useState, useMemo } from 'react';
|
3
3
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
4
4
|
import dayjs from 'dayjs';
|
5
5
|
import 'dayjs/locale/zh-cn';
|
@@ -36,12 +36,18 @@ dayjs.updateLocale('zh-cn', {
|
|
36
36
|
// FIXME: @@ 此处不能真正的将 relativeTime 设置为支持中文
|
37
37
|
setDateTool(dayjs);
|
38
38
|
|
39
|
-
const translations: Record<Locale, { utc: string }> = {
|
39
|
+
const translations: Record<Locale, { utc: string; local: string; shortUTC: string; shortLocal: string }> = {
|
40
40
|
en: {
|
41
|
-
utc: '
|
41
|
+
utc: 'UTC Timezone',
|
42
|
+
local: 'Local Timezone',
|
43
|
+
shortUTC: 'UTC',
|
44
|
+
shortLocal: 'Local',
|
42
45
|
},
|
43
46
|
zh: {
|
44
|
-
utc: '
|
47
|
+
utc: 'UTC 时区',
|
48
|
+
local: '本地时区',
|
49
|
+
shortUTC: 'UTC',
|
50
|
+
shortLocal: '本地',
|
45
51
|
},
|
46
52
|
};
|
47
53
|
|
@@ -55,7 +61,8 @@ export interface RelativeTimeProps {
|
|
55
61
|
tz?: string;
|
56
62
|
relativeRange?: number;
|
57
63
|
enableTooltip?: boolean;
|
58
|
-
|
64
|
+
useShortTimezone?: boolean;
|
65
|
+
disableTimezone?: boolean;
|
59
66
|
}
|
60
67
|
|
61
68
|
function useRelativeTime({
|
@@ -145,16 +152,25 @@ function UTCChip({
|
|
145
152
|
sign,
|
146
153
|
hoursOffset,
|
147
154
|
setIsUtc,
|
148
|
-
|
155
|
+
useShortTimezone = true,
|
149
156
|
}: {
|
150
157
|
locale: Locale;
|
151
158
|
isUtc?: boolean;
|
152
159
|
sign: string;
|
153
160
|
hoursOffset: number;
|
154
161
|
setIsUtc: (data: any) => void;
|
155
|
-
|
162
|
+
useShortTimezone?: boolean;
|
156
163
|
}) {
|
157
|
-
const
|
164
|
+
const text = useMemo(() => {
|
165
|
+
const UTC = useShortTimezone ? 'shortUTC' : 'utc';
|
166
|
+
const LOCAL = useShortTimezone ? 'shortLocal' : 'local';
|
167
|
+
|
168
|
+
if (isUtc) {
|
169
|
+
return `${translations[locale][UTC]}`;
|
170
|
+
}
|
171
|
+
|
172
|
+
return `${translations[locale][LOCAL]}`;
|
173
|
+
}, [locale, useShortTimezone, isUtc]);
|
158
174
|
|
159
175
|
return (
|
160
176
|
<Box
|
@@ -170,7 +186,7 @@ function UTCChip({
|
|
170
186
|
lineHeight: 1,
|
171
187
|
}}
|
172
188
|
onClick={() => setIsUtc((r: any) => !r)}>
|
173
|
-
{
|
189
|
+
{text}
|
174
190
|
</Box>
|
175
191
|
);
|
176
192
|
}
|
@@ -185,7 +201,8 @@ export default function RelativeTime({
|
|
185
201
|
tz,
|
186
202
|
relativeRange,
|
187
203
|
enableTooltip = true,
|
188
|
-
|
204
|
+
useShortTimezone = false,
|
205
|
+
disableTimezone = false,
|
189
206
|
...rest
|
190
207
|
}: RelativeTimeProps) {
|
191
208
|
const { innerContent, popContent, isUtc, setIsUtc, sign, hoursOffset, relativeString } = useRelativeTime({
|
@@ -202,7 +219,7 @@ export default function RelativeTime({
|
|
202
219
|
if (type === 'all') {
|
203
220
|
return (
|
204
221
|
<Tooltip title={undefined} placement="top-end" enterTouchDelay={0}>
|
205
|
-
<Box display="flex" alignItems="center" gap={0.5}
|
222
|
+
<Box display="inline-flex" alignItems="center" gap={0.5} {...rest}>
|
206
223
|
<Box component="span" {...rest} sx={{}}>
|
207
224
|
{innerContent}
|
208
225
|
</Box>
|
@@ -215,18 +232,22 @@ export default function RelativeTime({
|
|
215
232
|
{relativeString}
|
216
233
|
</Box>
|
217
234
|
|
218
|
-
|
219
|
-
|
220
|
-
|
235
|
+
{!disableTimezone && (
|
236
|
+
<>
|
237
|
+
<Box component="span" sx={{ color: 'inherit' }}>
|
238
|
+
·
|
239
|
+
</Box>
|
221
240
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
241
|
+
<UTCChip
|
242
|
+
locale={locale}
|
243
|
+
isUtc={isUtc}
|
244
|
+
sign={sign}
|
245
|
+
hoursOffset={hoursOffset}
|
246
|
+
setIsUtc={setIsUtc}
|
247
|
+
useShortTimezone={useShortTimezone}
|
248
|
+
/>
|
249
|
+
</>
|
250
|
+
)}
|
230
251
|
</Box>
|
231
252
|
</Tooltip>
|
232
253
|
);
|
@@ -234,19 +255,19 @@ export default function RelativeTime({
|
|
234
255
|
|
235
256
|
return (
|
236
257
|
<Tooltip title={enableTooltip ? popContent : undefined} placement="top-end" enterTouchDelay={0}>
|
237
|
-
<Box display="flex" alignItems="center" gap={1}
|
258
|
+
<Box display="inline-flex" alignItems="center" gap={1}>
|
238
259
|
<Box component="span" {...rest}>
|
239
260
|
{innerContent}
|
240
261
|
</Box>
|
241
262
|
|
242
|
-
{type === 'utc' && (
|
263
|
+
{type === 'utc' && !disableTimezone && (
|
243
264
|
<UTCChip
|
244
265
|
locale={locale}
|
245
266
|
isUtc={isUtc}
|
246
267
|
sign={sign}
|
247
268
|
hoursOffset={hoursOffset}
|
248
269
|
setIsUtc={setIsUtc}
|
249
|
-
|
270
|
+
useShortTimezone={useShortTimezone}
|
250
271
|
/>
|
251
272
|
)}
|
252
273
|
</Box>
|