@giteeteam/apps-team-components 1.0.10 → 1.0.11
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.
|
@@ -5,7 +5,7 @@ import { getBackgroundColor, getNameBadge } from '../utils';
|
|
|
5
5
|
import { avatarItemStyle, avatarStyle, defaultAvatarStyle } from './style';
|
|
6
6
|
const UserAvatar = React.memo(({ user, className }) => {
|
|
7
7
|
const avatarUrl = useMemo(() => { var _a; return (_a = user === null || user === void 0 ? void 0 : user.avatar) === null || _a === void 0 ? void 0 : _a.url; }, [user]);
|
|
8
|
-
const displayName = useMemo(() => (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.username), [user]);
|
|
8
|
+
const displayName = useMemo(() => (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.nickname) || (user === null || user === void 0 ? void 0 : user.username), [user]);
|
|
9
9
|
const userBadge = useMemo(() => getNameBadge(displayName), [displayName]);
|
|
10
10
|
return (_jsx(ClassNames, { children: ({ cx, css }) => {
|
|
11
11
|
return avatarUrl ? (_jsx("span", { className: cx('avatar-item', css(avatarItemStyle), css(avatarStyle), css(className)), style: { backgroundImage: `url(${avatarUrl})` } })) : (_jsx("span", { className: cx('avatar-item', css(avatarItemStyle), css(defaultAvatarStyle), css(className)), style: getBackgroundColor(userBadge), children: userBadge }));
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import dayjs from '../../lib/dayjs';
|
|
2
2
|
import { DATE_TIME_FORMAT, DATE_TIME_FORMAT_SEC } from '../../lib/global';
|
|
3
|
-
const zhReg = /[\u4e00-\u9fa5]/g;
|
|
4
3
|
export const getNameBadge = (name) => {
|
|
5
4
|
var _a;
|
|
6
5
|
if (!((_a = name === null || name === void 0 ? void 0 : name.trim) === null || _a === void 0 ? void 0 : _a.call(name)))
|
|
7
6
|
return null;
|
|
8
|
-
if (isChinese(name))
|
|
9
|
-
return name.slice(-1);
|
|
10
7
|
return name.slice(0, 1);
|
|
11
8
|
};
|
|
12
|
-
export const isChinese = (text) => zhReg.test(text);
|
|
13
9
|
const randomBackgroundColor = ['#5EA1FF', '#4BCC87', '#FFD15E', '#FF945E', '#A994FF'];
|
|
14
10
|
export const getBackgroundColor = (s) => {
|
|
15
11
|
const code = (s === null || s === void 0 ? void 0 : s.charCodeAt(0)) || 0;
|