@arcblock/ux 2.13.47 → 2.13.48
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 -1
- package/lib/RelativeTime/index.js +18 -13
- package/package.json +8 -7
- package/src/RelativeTime/index.tsx +26 -28
@@ -1,3 +1,4 @@
|
|
1
|
+
import { TooltipProps } from '@mui/material';
|
1
2
|
import 'dayjs/locale/zh-cn';
|
2
3
|
import type { Locale } from '../type';
|
3
4
|
export interface RelativeTimeProps {
|
@@ -12,5 +13,6 @@ export interface RelativeTimeProps {
|
|
12
13
|
enableTooltip?: boolean;
|
13
14
|
useShortTimezone?: boolean;
|
14
15
|
disableTimezone?: boolean;
|
16
|
+
placement?: TooltipProps['placement'];
|
15
17
|
}
|
16
|
-
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip, useShortTimezone, disableTimezone, ...rest }: RelativeTimeProps): import("react/jsx-runtime").JSX.Element;
|
18
|
+
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip, useShortTimezone, disableTimezone, placement, ...rest }: RelativeTimeProps): import("react/jsx-runtime").JSX.Element;
|
@@ -1,6 +1,6 @@
|
|
1
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 {
|
3
|
+
import { useEffect, useMemo } from 'react';
|
4
4
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
5
5
|
import dayjs from 'dayjs';
|
6
6
|
import 'dayjs/locale/zh-cn';
|
@@ -8,6 +8,7 @@ import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
8
8
|
import utc from 'dayjs/plugin/utc';
|
9
9
|
import timezone from 'dayjs/plugin/timezone';
|
10
10
|
import updateLocale from 'dayjs/plugin/updateLocale';
|
11
|
+
import { create } from 'zustand';
|
11
12
|
import { formatToDatetime, setDateTool } from '../Util';
|
12
13
|
dayjs.extend(localizedFormat);
|
13
14
|
dayjs.extend(utc);
|
@@ -48,6 +49,12 @@ const translations = {
|
|
48
49
|
shortLocal: '当前时区'
|
49
50
|
}
|
50
51
|
};
|
52
|
+
const useUtcStore = create(set => ({
|
53
|
+
isUtc: false,
|
54
|
+
setIsUtc: isUtc => set({
|
55
|
+
isUtc
|
56
|
+
})
|
57
|
+
}));
|
51
58
|
function useRelativeTime({
|
52
59
|
value,
|
53
60
|
locale = 'en',
|
@@ -63,7 +70,12 @@ function useRelativeTime({
|
|
63
70
|
const sign = timeZoneOffset > 0 ? '-' : '+';
|
64
71
|
const hoursOffset = Math.abs(timeZoneOffset) / 60;
|
65
72
|
const isLocalUtc = timeZoneOffset === 0;
|
66
|
-
const
|
73
|
+
const isUtc = useUtcStore(state => state.isUtc);
|
74
|
+
const setIsUtc = useUtcStore(state => state.setIsUtc);
|
75
|
+
useEffect(() => {
|
76
|
+
setIsUtc(isLocalUtc);
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
78
|
+
}, [isLocalUtc]);
|
67
79
|
if (!value) {
|
68
80
|
return {
|
69
81
|
innerContent: '-',
|
@@ -137,8 +149,6 @@ function useRelativeTime({
|
|
137
149
|
function UTCChip({
|
138
150
|
locale,
|
139
151
|
isUtc,
|
140
|
-
sign,
|
141
|
-
hoursOffset,
|
142
152
|
setIsUtc,
|
143
153
|
useShortTimezone = true
|
144
154
|
}) {
|
@@ -162,7 +172,7 @@ function UTCChip({
|
|
162
172
|
padding: '4px 8px',
|
163
173
|
lineHeight: 1
|
164
174
|
},
|
165
|
-
onClick: () => setIsUtc(
|
175
|
+
onClick: () => setIsUtc(!isUtc),
|
166
176
|
children: text
|
167
177
|
});
|
168
178
|
}
|
@@ -178,6 +188,7 @@ export default function RelativeTime({
|
|
178
188
|
enableTooltip = true,
|
179
189
|
useShortTimezone = false,
|
180
190
|
disableTimezone = false,
|
191
|
+
placement = 'top-end',
|
181
192
|
...rest
|
182
193
|
}) {
|
183
194
|
const {
|
@@ -185,8 +196,6 @@ export default function RelativeTime({
|
|
185
196
|
popContent,
|
186
197
|
isUtc,
|
187
198
|
setIsUtc,
|
188
|
-
sign,
|
189
|
-
hoursOffset,
|
190
199
|
relativeString
|
191
200
|
} = useRelativeTime({
|
192
201
|
value,
|
@@ -201,7 +210,7 @@ export default function RelativeTime({
|
|
201
210
|
if (type === 'all') {
|
202
211
|
return /*#__PURE__*/_jsx(Tooltip, {
|
203
212
|
title: undefined,
|
204
|
-
placement:
|
213
|
+
placement: placement,
|
205
214
|
enterTouchDelay: 0,
|
206
215
|
children: /*#__PURE__*/_jsxs(Box, {
|
207
216
|
display: "inline-flex",
|
@@ -235,8 +244,6 @@ export default function RelativeTime({
|
|
235
244
|
}), /*#__PURE__*/_jsx(UTCChip, {
|
236
245
|
locale: locale,
|
237
246
|
isUtc: isUtc,
|
238
|
-
sign: sign,
|
239
|
-
hoursOffset: hoursOffset,
|
240
247
|
setIsUtc: setIsUtc,
|
241
248
|
useShortTimezone: useShortTimezone
|
242
249
|
})]
|
@@ -246,7 +253,7 @@ export default function RelativeTime({
|
|
246
253
|
}
|
247
254
|
return /*#__PURE__*/_jsx(Tooltip, {
|
248
255
|
title: enableTooltip ? popContent : undefined,
|
249
|
-
placement:
|
256
|
+
placement: placement,
|
250
257
|
enterTouchDelay: 0,
|
251
258
|
children: /*#__PURE__*/_jsxs(Box, {
|
252
259
|
display: "inline-flex",
|
@@ -259,8 +266,6 @@ export default function RelativeTime({
|
|
259
266
|
}), type === 'utc' && !disableTimezone && /*#__PURE__*/_jsx(UTCChip, {
|
260
267
|
locale: locale,
|
261
268
|
isUtc: isUtc,
|
262
|
-
sign: sign,
|
263
|
-
hoursOffset: hoursOffset,
|
264
269
|
setIsUtc: setIsUtc,
|
265
270
|
useShortTimezone: useShortTimezone
|
266
271
|
})]
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.48",
|
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": "e6639ffcaa28acbebef892a278fe609fc24ee365",
|
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.48",
|
78
|
+
"@arcblock/nft-display": "^2.13.48",
|
79
|
+
"@arcblock/react-hooks": "^2.13.48",
|
80
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
81
|
-
"@blocklet/theme": "^2.13.
|
81
|
+
"@blocklet/theme": "^2.13.48",
|
82
82
|
"@fontsource/roboto": "~5.1.1",
|
83
83
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
84
84
|
"@iconify-icons/logos": "^1.2.36",
|
@@ -129,6 +129,7 @@
|
|
129
129
|
"type-fest": "^4.28.0",
|
130
130
|
"validator": "^13.9.0",
|
131
131
|
"versor": "^0.0.4",
|
132
|
-
"webfontloader": "^1.6.28"
|
132
|
+
"webfontloader": "^1.6.28",
|
133
|
+
"zustand": "^5.0.5"
|
133
134
|
}
|
134
135
|
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Box, Tooltip } from '@mui/material';
|
2
|
-
import {
|
1
|
+
import { Box, Tooltip, TooltipProps } from '@mui/material';
|
2
|
+
import { useEffect, useMemo } from 'react';
|
3
3
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
4
4
|
import dayjs from 'dayjs';
|
5
5
|
import 'dayjs/locale/zh-cn';
|
@@ -7,6 +7,7 @@ import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
7
7
|
import utc from 'dayjs/plugin/utc';
|
8
8
|
import timezone from 'dayjs/plugin/timezone';
|
9
9
|
import updateLocale from 'dayjs/plugin/updateLocale';
|
10
|
+
import { create } from 'zustand';
|
10
11
|
import { formatToDatetime, setDateTool } from '../Util';
|
11
12
|
import type { Locale } from '../type';
|
12
13
|
|
@@ -51,6 +52,12 @@ const translations: Record<Locale, { utc: string; local: string; shortUTC: strin
|
|
51
52
|
},
|
52
53
|
};
|
53
54
|
|
55
|
+
type UtcState = { isUtc: boolean; setIsUtc: (isUtc: boolean) => void };
|
56
|
+
const useUtcStore = create<UtcState>((set) => ({
|
57
|
+
isUtc: false,
|
58
|
+
setIsUtc: (isUtc: boolean) => set({ isUtc }),
|
59
|
+
}));
|
60
|
+
|
54
61
|
export interface RelativeTimeProps {
|
55
62
|
value: string | number;
|
56
63
|
locale?: Locale;
|
@@ -63,6 +70,7 @@ export interface RelativeTimeProps {
|
|
63
70
|
enableTooltip?: boolean;
|
64
71
|
useShortTimezone?: boolean;
|
65
72
|
disableTimezone?: boolean;
|
73
|
+
placement?: TooltipProps['placement'];
|
66
74
|
}
|
67
75
|
|
68
76
|
function useRelativeTime({
|
@@ -89,7 +97,14 @@ function useRelativeTime({
|
|
89
97
|
const sign = timeZoneOffset > 0 ? '-' : '+';
|
90
98
|
const hoursOffset = Math.abs(timeZoneOffset) / 60;
|
91
99
|
const isLocalUtc = timeZoneOffset === 0;
|
92
|
-
|
100
|
+
|
101
|
+
const isUtc = useUtcStore((state) => state.isUtc);
|
102
|
+
const setIsUtc = useUtcStore((state) => state.setIsUtc);
|
103
|
+
|
104
|
+
useEffect(() => {
|
105
|
+
setIsUtc(isLocalUtc);
|
106
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
107
|
+
}, [isLocalUtc]);
|
93
108
|
|
94
109
|
if (!value) {
|
95
110
|
return { innerContent: '-', popContent: '-', isUtc, setIsUtc, sign, hoursOffset };
|
@@ -149,16 +164,12 @@ function useRelativeTime({
|
|
149
164
|
function UTCChip({
|
150
165
|
locale,
|
151
166
|
isUtc,
|
152
|
-
sign,
|
153
|
-
hoursOffset,
|
154
167
|
setIsUtc,
|
155
168
|
useShortTimezone = true,
|
156
169
|
}: {
|
157
170
|
locale: Locale;
|
158
171
|
isUtc?: boolean;
|
159
|
-
|
160
|
-
hoursOffset: number;
|
161
|
-
setIsUtc: (data: any) => void;
|
172
|
+
setIsUtc: (data: boolean) => void;
|
162
173
|
useShortTimezone?: boolean;
|
163
174
|
}) {
|
164
175
|
const text = useMemo(() => {
|
@@ -185,7 +196,7 @@ function UTCChip({
|
|
185
196
|
padding: '4px 8px',
|
186
197
|
lineHeight: 1,
|
187
198
|
}}
|
188
|
-
onClick={() => setIsUtc(
|
199
|
+
onClick={() => setIsUtc(!isUtc)}>
|
189
200
|
{text}
|
190
201
|
</Box>
|
191
202
|
);
|
@@ -203,9 +214,10 @@ export default function RelativeTime({
|
|
203
214
|
enableTooltip = true,
|
204
215
|
useShortTimezone = false,
|
205
216
|
disableTimezone = false,
|
217
|
+
placement = 'top-end',
|
206
218
|
...rest
|
207
219
|
}: RelativeTimeProps) {
|
208
|
-
const { innerContent, popContent, isUtc, setIsUtc,
|
220
|
+
const { innerContent, popContent, isUtc, setIsUtc, relativeString } = useRelativeTime({
|
209
221
|
value,
|
210
222
|
locale,
|
211
223
|
withoutSuffix,
|
@@ -218,7 +230,7 @@ export default function RelativeTime({
|
|
218
230
|
|
219
231
|
if (type === 'all') {
|
220
232
|
return (
|
221
|
-
<Tooltip title={undefined} placement=
|
233
|
+
<Tooltip title={undefined} placement={placement} enterTouchDelay={0}>
|
222
234
|
<Box display="inline-flex" alignItems="center" gap={0.5} {...rest}>
|
223
235
|
<Box component="span" {...rest} sx={{}}>
|
224
236
|
{innerContent}
|
@@ -238,14 +250,7 @@ export default function RelativeTime({
|
|
238
250
|
·
|
239
251
|
</Box>
|
240
252
|
|
241
|
-
<UTCChip
|
242
|
-
locale={locale}
|
243
|
-
isUtc={isUtc}
|
244
|
-
sign={sign}
|
245
|
-
hoursOffset={hoursOffset}
|
246
|
-
setIsUtc={setIsUtc}
|
247
|
-
useShortTimezone={useShortTimezone}
|
248
|
-
/>
|
253
|
+
<UTCChip locale={locale} isUtc={isUtc} setIsUtc={setIsUtc} useShortTimezone={useShortTimezone} />
|
249
254
|
</>
|
250
255
|
)}
|
251
256
|
</Box>
|
@@ -254,21 +259,14 @@ export default function RelativeTime({
|
|
254
259
|
}
|
255
260
|
|
256
261
|
return (
|
257
|
-
<Tooltip title={enableTooltip ? popContent : undefined} placement=
|
262
|
+
<Tooltip title={enableTooltip ? popContent : undefined} placement={placement} enterTouchDelay={0}>
|
258
263
|
<Box display="inline-flex" alignItems="center" gap={1}>
|
259
264
|
<Box component="span" {...rest}>
|
260
265
|
{innerContent}
|
261
266
|
</Box>
|
262
267
|
|
263
268
|
{type === 'utc' && !disableTimezone && (
|
264
|
-
<UTCChip
|
265
|
-
locale={locale}
|
266
|
-
isUtc={isUtc}
|
267
|
-
sign={sign}
|
268
|
-
hoursOffset={hoursOffset}
|
269
|
-
setIsUtc={setIsUtc}
|
270
|
-
useShortTimezone={useShortTimezone}
|
271
|
-
/>
|
269
|
+
<UTCChip locale={locale} isUtc={isUtc} setIsUtc={setIsUtc} useShortTimezone={useShortTimezone} />
|
272
270
|
)}
|
273
271
|
</Box>
|
274
272
|
</Tooltip>
|