@aloudata/aloudata-design 2.16.0 → 2.17.0
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/dist/Avatar/component/Avatar/helper.d.ts +11 -0
- package/dist/Avatar/component/Avatar/helper.js +83 -0
- package/dist/Avatar/component/Avatar/index.d.ts +7 -8
- package/dist/Avatar/component/Avatar/index.js +55 -27
- package/dist/Avatar/component/Avatar/type.d.ts +22 -0
- package/dist/Avatar/component/Avatar/type.js +16 -0
- package/dist/Avatar/style/index.less +4 -33
- package/dist/User/index.js +1 -1
- package/dist/ald.min.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TAvatarSize } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* 根据头像大小获取合适的字体大小和缩放样式
|
|
4
|
+
* @param size 头像大小,可以是预设值或数字
|
|
5
|
+
* @returns 包含fontSize和可能的transform样式的对象
|
|
6
|
+
*/
|
|
7
|
+
export declare const getFontSize: (size: TAvatarSize | number) => {
|
|
8
|
+
fontSize: number;
|
|
9
|
+
transform?: string | undefined;
|
|
10
|
+
fontWeight?: number | undefined;
|
|
11
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AVATAR_SIZE_MAP, AVATAR_SIZE_TO_FONT_SIZE } from "./type";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 根据头像大小获取合适的字体大小和缩放样式
|
|
5
|
+
* @param size 头像大小,可以是预设值或数字
|
|
6
|
+
* @returns 包含fontSize和可能的transform样式的对象
|
|
7
|
+
*/
|
|
8
|
+
export var getFontSize = function getFontSize(size) {
|
|
9
|
+
// 1. 将TAvatarSize转换为像素值
|
|
10
|
+
var pixelSize = typeof size === 'number' ? size : AVATAR_SIZE_MAP[size] || 32;
|
|
11
|
+
|
|
12
|
+
// 2. 计算合适的字体大小
|
|
13
|
+
var fontSize;
|
|
14
|
+
|
|
15
|
+
// 2.1 先检查映射表中是否有对应值
|
|
16
|
+
if (pixelSize in AVATAR_SIZE_TO_FONT_SIZE) {
|
|
17
|
+
fontSize = AVATAR_SIZE_TO_FONT_SIZE[pixelSize];
|
|
18
|
+
} else {
|
|
19
|
+
// 2.2 如果没有对应值,根据区间确定合适的字体大小
|
|
20
|
+
|
|
21
|
+
// 定义关键区间点
|
|
22
|
+
var sizeBenchmarks = Object.keys(AVATAR_SIZE_TO_FONT_SIZE).map(Number).sort(function (a, b) {
|
|
23
|
+
return a - b;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// 如果小于最小基准点
|
|
27
|
+
if (pixelSize < sizeBenchmarks[0]) {
|
|
28
|
+
// 对于非常小的尺寸,使用比例计算,但不小于6px
|
|
29
|
+
fontSize = Math.max(6, Math.floor(pixelSize / 2));
|
|
30
|
+
// 确保为偶数
|
|
31
|
+
fontSize = fontSize % 2 === 0 ? fontSize : fontSize - 1;
|
|
32
|
+
}
|
|
33
|
+
// 如果大于最大基准点
|
|
34
|
+
else if (pixelSize > sizeBenchmarks[sizeBenchmarks.length - 1]) {
|
|
35
|
+
// 对于特大尺寸,使用简单的比例计算,确保单调增长
|
|
36
|
+
var largestSize = sizeBenchmarks[sizeBenchmarks.length - 1];
|
|
37
|
+
var largestFontSize = AVATAR_SIZE_TO_FONT_SIZE[largestSize];
|
|
38
|
+
var ratio = largestFontSize / largestSize;
|
|
39
|
+
fontSize = Math.floor(pixelSize * ratio);
|
|
40
|
+
|
|
41
|
+
// 确保为偶数
|
|
42
|
+
fontSize = fontSize % 2 === 0 ? fontSize : fontSize - 1;
|
|
43
|
+
}
|
|
44
|
+
// 在两个基准点之间
|
|
45
|
+
else {
|
|
46
|
+
// 找到最近的两个基准点
|
|
47
|
+
var lowerIndex = 0;
|
|
48
|
+
for (var i = 0; i < sizeBenchmarks.length - 1; i++) {
|
|
49
|
+
if (pixelSize >= sizeBenchmarks[i] && pixelSize < sizeBenchmarks[i + 1]) {
|
|
50
|
+
lowerIndex = i;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var lowerSize = sizeBenchmarks[lowerIndex];
|
|
55
|
+
var upperSize = sizeBenchmarks[lowerIndex + 1];
|
|
56
|
+
var lowerFontSize = AVATAR_SIZE_TO_FONT_SIZE[lowerSize];
|
|
57
|
+
var upperFontSize = AVATAR_SIZE_TO_FONT_SIZE[upperSize];
|
|
58
|
+
|
|
59
|
+
// 线性插值计算
|
|
60
|
+
var _ratio = (pixelSize - lowerSize) / (upperSize - lowerSize);
|
|
61
|
+
fontSize = Math.floor(lowerFontSize + _ratio * (upperFontSize - lowerFontSize));
|
|
62
|
+
|
|
63
|
+
// 确保为偶数
|
|
64
|
+
fontSize = fontSize % 2 === 0 ? fontSize : fontSize - 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 3. 处理小于12px的字体
|
|
69
|
+
if (fontSize < 12) {
|
|
70
|
+
var scale = fontSize / 12;
|
|
71
|
+
return {
|
|
72
|
+
fontSize: 12,
|
|
73
|
+
transform: "scale(".concat(scale, ")"),
|
|
74
|
+
fontWeight: 600
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 4. 返回结果
|
|
79
|
+
return {
|
|
80
|
+
fontSize: fontSize,
|
|
81
|
+
fontWeight: 500
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AvatarProps as antdAvatarProps } from 'antd/lib/avatar/avatar';
|
|
2
2
|
import Group from 'antd/lib/avatar/group';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
type TSize = 'large' | 'middle' | 'small' | number;
|
|
4
|
+
import { TAvatarSize } from './type';
|
|
6
5
|
export interface IAvatarProps extends Omit<antdAvatarProps, 'size'> {
|
|
7
6
|
/**
|
|
8
7
|
* @description 指定头像的形状
|
|
@@ -65,17 +64,17 @@ export interface IAvatarProps extends Omit<antdAvatarProps, 'size'> {
|
|
|
65
64
|
*/
|
|
66
65
|
onError?: () => boolean;
|
|
67
66
|
/**
|
|
68
|
-
* @description 头像的大小,可以显示的设置数字或者预设的大小值
|
|
67
|
+
* @description 头像的大小,可以显示的设置数字或者预设的大小值 40 32 28
|
|
69
68
|
* @type 'large' | 'middle' | 'small' | number
|
|
70
69
|
* @default middle
|
|
71
70
|
*/
|
|
72
|
-
size?:
|
|
71
|
+
size?: TAvatarSize;
|
|
73
72
|
/**
|
|
74
|
-
* @description
|
|
75
|
-
* @type
|
|
76
|
-
* @default
|
|
73
|
+
* @description 头像的类型
|
|
74
|
+
* @type 'default' | 'user' | 'userGroup'
|
|
75
|
+
* @default default
|
|
77
76
|
*/
|
|
78
|
-
|
|
77
|
+
type?: 'user' | 'userGroup' | 'count';
|
|
79
78
|
}
|
|
80
79
|
interface ICompoundedComponent extends React.ForwardRefExoticComponent<IAvatarProps & React.RefAttributes<HTMLElement>> {
|
|
81
80
|
Group: typeof Group;
|
|
@@ -1,48 +1,76 @@
|
|
|
1
|
-
var _excluded = ["size", "
|
|
1
|
+
var _excluded = ["size", "children", "src", "icon", "type"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
3
|
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; }
|
|
4
4
|
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; }
|
|
5
5
|
import InternalAvatar from 'antd/lib/avatar/avatar';
|
|
6
|
-
import classNames from 'classnames';
|
|
7
6
|
import * as React from 'react';
|
|
8
7
|
import { User } from "../../../Icon";
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import { useCallback, useMemo } from 'react';
|
|
10
|
+
import { AVATAR_SIZE_MAP, AVATAR_TYPE_TO_BG_COLOR } from "./type";
|
|
11
|
+
import { getFontSize } from "./helper";
|
|
12
|
+
import classNames from 'classnames';
|
|
9
13
|
var ZERO = 0;
|
|
10
14
|
var Avatar = function Avatar(props) {
|
|
11
15
|
var _props$size = props.size,
|
|
12
16
|
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
13
|
-
_props$showFullValue = props.showFullValue,
|
|
14
|
-
showFullValue = _props$showFullValue === void 0 ? false : _props$showFullValue,
|
|
15
17
|
children = props.children,
|
|
16
18
|
src = props.src,
|
|
19
|
+
icon = props.icon,
|
|
20
|
+
type = props.type,
|
|
17
21
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
defaultAvatarClassName = 'ald-avatar-default';
|
|
22
|
-
}
|
|
23
|
-
if (['large', 'small', 'mini'].includes("".concat(avatarSize))) {
|
|
24
|
-
return classNames('ald-avatar', defaultAvatarClassName, "ald-avatar-".concat(avatarSize));
|
|
22
|
+
var getSize = useCallback(function () {
|
|
23
|
+
if (typeof size === 'number') {
|
|
24
|
+
return size;
|
|
25
25
|
}
|
|
26
|
-
return
|
|
27
|
-
};
|
|
28
|
-
var getChildren = function
|
|
29
|
-
if (
|
|
26
|
+
return AVATAR_SIZE_MAP[size] || 32;
|
|
27
|
+
}, [size]);
|
|
28
|
+
var getChildren = useCallback(function () {
|
|
29
|
+
if (typeof children === 'string') {
|
|
30
30
|
return children[ZERO].toLocaleUpperCase();
|
|
31
31
|
}
|
|
32
32
|
return children;
|
|
33
|
-
};
|
|
34
|
-
var
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
}, [children]);
|
|
34
|
+
var bgColor = useMemo(function () {
|
|
35
|
+
if (type) {
|
|
36
|
+
return AVATAR_TYPE_TO_BG_COLOR[type];
|
|
37
|
+
}
|
|
38
|
+
return AVATAR_TYPE_TO_BG_COLOR.user;
|
|
39
|
+
}, [type]);
|
|
40
|
+
var fontColor = useMemo(function () {
|
|
41
|
+
if (type === 'count') {
|
|
42
|
+
return '#1F2937';
|
|
43
|
+
}
|
|
44
|
+
return '#fff';
|
|
45
|
+
}, [type]);
|
|
46
|
+
var innerIcon = useMemo(function () {
|
|
47
|
+
if (icon) {
|
|
48
|
+
return icon;
|
|
49
|
+
}
|
|
50
|
+
if (!_.isNil(children)) {
|
|
51
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
52
|
+
style: {
|
|
53
|
+
backgroundColor: bgColor,
|
|
54
|
+
color: fontColor,
|
|
55
|
+
height: '100%',
|
|
56
|
+
width: '100%',
|
|
57
|
+
display: 'flex',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
justifyContent: 'center'
|
|
60
|
+
}
|
|
61
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
62
|
+
style: getFontSize(getSize())
|
|
63
|
+
}, getChildren()));
|
|
39
64
|
}
|
|
40
|
-
return
|
|
41
|
-
|
|
65
|
+
return /*#__PURE__*/React.createElement(User, {
|
|
66
|
+
size: getSize()
|
|
67
|
+
});
|
|
68
|
+
}, [icon, getSize, children, getChildren, bgColor, fontColor]);
|
|
42
69
|
return /*#__PURE__*/React.createElement(InternalAvatar, _extends({}, restProps, {
|
|
43
|
-
size:
|
|
44
|
-
className: classNames(
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
size: getSize(),
|
|
71
|
+
className: classNames(restProps.className, 'ald-avatar'),
|
|
72
|
+
icon: innerIcon,
|
|
73
|
+
src: src
|
|
74
|
+
}));
|
|
47
75
|
};
|
|
48
76
|
export default Avatar;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type TAvatarSize = 'large' | 'middle' | 'small' | number;
|
|
2
|
+
export type { GroupProps } from 'antd/lib/avatar/group';
|
|
3
|
+
export declare const AVATAR_SIZE_MAP: {
|
|
4
|
+
large: number;
|
|
5
|
+
middle: number;
|
|
6
|
+
small: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const AVATAR_SIZE_TO_FONT_SIZE: {
|
|
9
|
+
16: number;
|
|
10
|
+
20: number;
|
|
11
|
+
24: number;
|
|
12
|
+
28: number;
|
|
13
|
+
32: number;
|
|
14
|
+
40: number;
|
|
15
|
+
48: number;
|
|
16
|
+
64: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const AVATAR_TYPE_TO_BG_COLOR: {
|
|
19
|
+
user: string;
|
|
20
|
+
userGroup: string;
|
|
21
|
+
count: string;
|
|
22
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var _AVATAR_SIZE_TO_FONT_;
|
|
2
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
export var AVATAR_SIZE_MAP = {
|
|
7
|
+
large: 40,
|
|
8
|
+
middle: 32,
|
|
9
|
+
small: 28
|
|
10
|
+
};
|
|
11
|
+
export var AVATAR_SIZE_TO_FONT_SIZE = (_AVATAR_SIZE_TO_FONT_ = {}, _defineProperty(_AVATAR_SIZE_TO_FONT_, 16, 8), _defineProperty(_AVATAR_SIZE_TO_FONT_, 20, 10), _defineProperty(_AVATAR_SIZE_TO_FONT_, 24, 10), _defineProperty(_AVATAR_SIZE_TO_FONT_, 28, 12), _defineProperty(_AVATAR_SIZE_TO_FONT_, 32, 12), _defineProperty(_AVATAR_SIZE_TO_FONT_, 40, 14), _defineProperty(_AVATAR_SIZE_TO_FONT_, 48, 16), _defineProperty(_AVATAR_SIZE_TO_FONT_, 64, 24), _AVATAR_SIZE_TO_FONT_);
|
|
12
|
+
export var AVATAR_TYPE_TO_BG_COLOR = {
|
|
13
|
+
user: '#1D4ED8',
|
|
14
|
+
userGroup: '#15803D',
|
|
15
|
+
count: '#E5E7EB'
|
|
16
|
+
};
|
|
@@ -1,41 +1,12 @@
|
|
|
1
1
|
@import '../../style/index.less';
|
|
2
2
|
|
|
3
3
|
.ald-avatar.ald-avatar {
|
|
4
|
-
color: @ND0;
|
|
5
4
|
background-color: #fff;
|
|
5
|
+
color: #1f2937;
|
|
6
6
|
border: 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
&-large {
|
|
13
|
-
width: 40px;
|
|
14
|
-
height: 40px;
|
|
15
|
-
font-size: 20px;
|
|
16
|
-
line-height: 40px;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
&-middle {
|
|
20
|
-
width: 32px;
|
|
21
|
-
height: 32px;
|
|
22
|
-
font-size: 16px;
|
|
23
|
-
line-height: 32px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&-small {
|
|
27
|
-
width: 28px;
|
|
28
|
-
height: 28px;
|
|
29
|
-
font-size: 14px;
|
|
30
|
-
line-height: 28px;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&-mini {
|
|
34
|
-
width: 24px;
|
|
35
|
-
height: 24px;
|
|
36
|
-
font-size: 12px;
|
|
37
|
-
line-height: 24px;
|
|
38
|
-
}
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
39
10
|
}
|
|
40
11
|
|
|
41
12
|
.ant-avatar-group {
|
package/dist/User/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function User(_ref) {
|
|
|
21
21
|
className: 'ald-user-avatar',
|
|
22
22
|
src: src,
|
|
23
23
|
size: getAvatarSize(size || 'middle')
|
|
24
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
24
|
+
}, nickname), /*#__PURE__*/React.createElement("div", {
|
|
25
25
|
className: classNames('ald-user-text', nicknameClassName)
|
|
26
26
|
}, nickname));
|
|
27
27
|
}
|