@arcblock/ux 2.12.64 → 2.12.70
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/Config/config-provider.js +9 -0
- package/lib/Config/index.d.ts +1 -0
- package/lib/Config/index.js +1 -0
- package/lib/Header/header.js +6 -2
- package/lib/Locale/selector.js +8 -18
- package/lib/NavMenu/style.js +10 -8
- package/lib/NavMenu/sub-item-group.js +6 -2
- package/lib/SessionBlocklet/index.js +7 -15
- package/lib/SessionUser/components/logged-in.js +4 -8
- package/lib/Theme/theme.d.ts +2 -0
- package/lib/Theme/theme.js +2 -1
- package/lib/UserCard/Cards/avatar-only.d.ts +8 -0
- package/lib/UserCard/Cards/avatar-only.js +34 -0
- package/lib/UserCard/Cards/basic-info.d.ts +9 -0
- package/lib/UserCard/Cards/basic-info.js +51 -0
- package/lib/UserCard/Cards/index.d.ts +8 -0
- package/lib/UserCard/Cards/index.js +24 -0
- package/lib/UserCard/Cards/name-only.d.ts +3 -0
- package/lib/UserCard/Cards/name-only.js +18 -0
- package/lib/UserCard/Container/card.d.ts +13 -0
- package/lib/UserCard/Container/card.js +46 -0
- package/lib/UserCard/Container/dialog.d.ts +9 -0
- package/lib/UserCard/Container/dialog.js +25 -0
- package/lib/UserCard/Content/basic.d.ts +7 -0
- package/lib/UserCard/Content/basic.js +139 -0
- package/lib/UserCard/Content/clock.d.ts +4 -0
- package/lib/UserCard/Content/clock.js +68 -0
- package/lib/UserCard/Content/left-layout.d.ts +16 -0
- package/lib/UserCard/Content/left-layout.js +33 -0
- package/lib/UserCard/Content/minimal.d.ts +15 -0
- package/lib/UserCard/Content/minimal.js +61 -0
- package/lib/UserCard/Content/tooltip-avatar.d.ts +15 -0
- package/lib/UserCard/Content/tooltip-avatar.js +61 -0
- package/lib/UserCard/components.d.ts +4 -0
- package/lib/UserCard/components.js +45 -0
- package/lib/UserCard/index.d.ts +5 -0
- package/lib/UserCard/index.js +74 -0
- package/lib/UserCard/types.d.ts +107 -0
- package/lib/UserCard/types.js +42 -0
- package/lib/UserCard/utils.d.ts +2 -0
- package/lib/UserCard/utils.js +19 -0
- package/lib/hooks/use-clock.d.ts +10 -0
- package/lib/hooks/use-clock.js +71 -0
- package/package.json +5 -5
- package/src/Config/config-provider.tsx +7 -0
- package/src/Config/index.ts +1 -0
- package/src/Header/header.tsx +2 -2
- package/src/Locale/selector.tsx +7 -14
- package/src/NavMenu/style.ts +8 -8
- package/src/NavMenu/sub-item-group.tsx +2 -2
- package/src/SessionBlocklet/index.tsx +7 -20
- package/src/SessionUser/components/logged-in.tsx +4 -6
- package/src/Theme/theme.ts +1 -0
- package/src/UserCard/Cards/avatar-only.tsx +38 -0
- package/src/UserCard/Cards/basic-info.tsx +50 -0
- package/src/UserCard/Cards/index.tsx +24 -0
- package/src/UserCard/Cards/name-only.tsx +17 -0
- package/src/UserCard/Container/card.tsx +52 -0
- package/src/UserCard/Container/dialog.tsx +30 -0
- package/src/UserCard/Content/basic.tsx +134 -0
- package/src/UserCard/Content/clock.tsx +63 -0
- package/src/UserCard/Content/left-layout.tsx +40 -0
- package/src/UserCard/Content/minimal.tsx +60 -0
- package/src/UserCard/Content/tooltip-avatar.tsx +55 -0
- package/src/UserCard/components.tsx +49 -0
- package/src/UserCard/index.tsx +63 -0
- package/src/UserCard/types.ts +129 -0
- package/src/UserCard/utils.ts +22 -0
- package/src/hooks/use-clock.tsx +61 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
2
|
+
import dayjs from 'dayjs';
|
3
|
+
import utc from 'dayjs/plugin/utc';
|
4
|
+
import timezonePlugin from 'dayjs/plugin/timezone';
|
5
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
6
|
+
import { formatToDatetime } from '@arcblock/ux/lib/Util';
|
7
|
+
import 'dayjs/locale/zh-cn';
|
8
|
+
import 'dayjs/locale/en';
|
9
|
+
|
10
|
+
dayjs.extend(utc);
|
11
|
+
dayjs.extend(timezonePlugin);
|
12
|
+
dayjs.extend(localizedFormat);
|
13
|
+
|
14
|
+
const currentTimezone = dayjs.tz.guess();
|
15
|
+
|
16
|
+
// 获取时间段
|
17
|
+
const getTimePhase = (hour: number) => {
|
18
|
+
if (hour >= 0 && hour < 6) return { phase: 'dawn', icon: '🌒' }; // 凌晨 00:00-05:59
|
19
|
+
if (hour >= 6 && hour < 12) return { phase: 'morning', icon: '🌞' }; // 上午 06:00-11:59
|
20
|
+
if (hour >= 12 && hour < 18) return { phase: 'afternoon', icon: '🌞' }; // 下午 12:00-17:59
|
21
|
+
return { phase: 'night', icon: '🌒' }; // 晚上 18:00-23:59
|
22
|
+
};
|
23
|
+
|
24
|
+
export default function useClock(timezone = currentTimezone, locale = 'zh') {
|
25
|
+
const getLatestTimeInfo = useCallback(() => {
|
26
|
+
const currentLocale = locale === 'zh' ? 'zh-cn' : 'en';
|
27
|
+
const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
|
28
|
+
dayjs.locale(currentLocale);
|
29
|
+
|
30
|
+
const now = dayjs().tz(timezone);
|
31
|
+
const hour = now.hour();
|
32
|
+
const { phase, icon } = getTimePhase(hour);
|
33
|
+
|
34
|
+
return {
|
35
|
+
formattedTime: now.format('LT'),
|
36
|
+
fullDateTime: formatToDatetime(now.toDate(), { tz: timezone, locale: localeOption }),
|
37
|
+
phase,
|
38
|
+
icon,
|
39
|
+
rawTime: now,
|
40
|
+
};
|
41
|
+
}, [timezone, locale]);
|
42
|
+
|
43
|
+
const [timeInfo, setTimeInfo] = useState(getLatestTimeInfo());
|
44
|
+
|
45
|
+
useEffect(() => {
|
46
|
+
// 立即更新一次,确保初始状态是最新的
|
47
|
+
setTimeInfo(getLatestTimeInfo());
|
48
|
+
|
49
|
+
// 设置定时器
|
50
|
+
const timerId = setInterval(() => {
|
51
|
+
setTimeInfo(getLatestTimeInfo());
|
52
|
+
}, 6000);
|
53
|
+
|
54
|
+
// 清理函数
|
55
|
+
return () => {
|
56
|
+
clearInterval(timerId);
|
57
|
+
};
|
58
|
+
}, [timezone, locale, getLatestTimeInfo]);
|
59
|
+
|
60
|
+
return timeInfo;
|
61
|
+
}
|