@lobehub/ui 2.8.1 → 2.8.3
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var _excluded = ["className", "style", "avatars", "size", "cornerShape", "avatarShape"];
|
|
4
|
+
var _excluded = ["className", "style", "avatars", "size", "grid", "cornerShape", "avatarShape"];
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
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; }
|
|
@@ -9,11 +9,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
9
9
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
10
|
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; }
|
|
11
11
|
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; }
|
|
12
|
+
import { cva } from 'class-variance-authority';
|
|
12
13
|
import { memo, useMemo } from 'react';
|
|
13
14
|
import Avatar from "../Avatar";
|
|
14
15
|
import Block from "../Block";
|
|
15
16
|
import Grid from "../Grid";
|
|
16
|
-
import { getSmoothCornersMaskStyle } from "../utils/smoothCorners";
|
|
17
17
|
import { useStyles } from "./style";
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
19
|
var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -23,6 +23,8 @@ var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
|
|
|
23
23
|
avatars = _ref$avatars === void 0 ? [] : _ref$avatars,
|
|
24
24
|
_ref$size = _ref.size,
|
|
25
25
|
size = _ref$size === void 0 ? 32 : _ref$size,
|
|
26
|
+
_ref$grid = _ref.grid,
|
|
27
|
+
grid = _ref$grid === void 0 ? 2 : _ref$grid,
|
|
26
28
|
_ref$cornerShape = _ref.cornerShape,
|
|
27
29
|
cornerShape = _ref$cornerShape === void 0 ? 'squircle' : _ref$cornerShape,
|
|
28
30
|
_ref$avatarShape = _ref.avatarShape,
|
|
@@ -31,41 +33,64 @@ var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
|
|
|
31
33
|
var _useStyles = useStyles(),
|
|
32
34
|
cx = _useStyles.cx,
|
|
33
35
|
styles = _useStyles.styles;
|
|
34
|
-
var smoothCornersMask = useMemo(function () {
|
|
35
|
-
return getSmoothCornersMaskStyle(cornerShape);
|
|
36
|
-
}, [cornerShape]);
|
|
37
36
|
var calcSize = useMemo(function () {
|
|
37
|
+
var length = avatars.length;
|
|
38
|
+
var isAutoGrid = grid === 'auto';
|
|
39
|
+
var gridSize = isAutoGrid ? length > 4 ? 3 : 2 : grid;
|
|
38
40
|
var isCircle = cornerShape === 'circle';
|
|
39
|
-
var avatarSize = Math.floor(size /
|
|
40
|
-
var gapSize = Math.floor((size - avatarSize *
|
|
41
|
+
var avatarSize = Math.floor(size / gridSize * (isCircle ? 0.65 : 0.75));
|
|
42
|
+
var gapSize = Math.floor((size - avatarSize * gridSize) / (isCircle ? 6 : 4));
|
|
41
43
|
return {
|
|
42
44
|
avatarSize: avatarSize,
|
|
43
45
|
gapSize: gapSize,
|
|
44
|
-
|
|
46
|
+
gridSize: gridSize,
|
|
47
|
+
gridWidth: avatarSize * gridSize + gapSize,
|
|
45
48
|
maxItemWidth: avatarSize - 1
|
|
46
49
|
};
|
|
47
|
-
}, [size, cornerShape]);
|
|
50
|
+
}, [avatars, grid, size, cornerShape]);
|
|
51
|
+
var calcAvatars = useMemo(function () {
|
|
52
|
+
return avatars === null || avatars === void 0 ? void 0 : avatars.slice(0, calcSize.gridSize * calcSize.gridSize);
|
|
53
|
+
}, [avatars, calcSize.gridSize]);
|
|
54
|
+
var variants = useMemo(function () {
|
|
55
|
+
return cva(styles.root, {
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
cornerShape: 'squircle'
|
|
58
|
+
},
|
|
59
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
60
|
+
variants: {
|
|
61
|
+
cornerShape: {
|
|
62
|
+
circle: styles.circle,
|
|
63
|
+
ios: styles.ios,
|
|
64
|
+
sharp: styles.sharp,
|
|
65
|
+
smooth: styles.smooth,
|
|
66
|
+
square: styles.square,
|
|
67
|
+
squircle: styles.squircle
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
71
|
+
});
|
|
72
|
+
}, [styles]);
|
|
48
73
|
return /*#__PURE__*/_jsx(Block, _objectSpread(_objectSpread({
|
|
49
74
|
align: 'center',
|
|
50
|
-
className: cx(
|
|
75
|
+
className: cx(variants({
|
|
76
|
+
cornerShape: cornerShape
|
|
77
|
+
}), className),
|
|
51
78
|
height: size,
|
|
52
79
|
justify: 'center',
|
|
53
|
-
style:
|
|
80
|
+
style: style,
|
|
54
81
|
width: size
|
|
55
82
|
}, rest), {}, {
|
|
56
83
|
children: /*#__PURE__*/_jsx(Grid, {
|
|
57
84
|
gap: calcSize.gapSize,
|
|
58
|
-
maxItemWidth:
|
|
59
|
-
rows:
|
|
85
|
+
maxItemWidth: 0,
|
|
86
|
+
rows: calcSize.gridSize,
|
|
60
87
|
width: calcSize.gridWidth,
|
|
61
|
-
children:
|
|
62
|
-
if (typeof item === 'string') {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}, index);
|
|
68
|
-
}
|
|
88
|
+
children: calcAvatars.map(function (item, index) {
|
|
89
|
+
if (typeof item === 'string') return /*#__PURE__*/_jsx(Avatar, {
|
|
90
|
+
avatar: item,
|
|
91
|
+
shape: avatarShape,
|
|
92
|
+
size: calcSize.avatarSize
|
|
93
|
+
}, index);
|
|
69
94
|
return /*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, item), {}, {
|
|
70
95
|
shape: avatarShape,
|
|
71
96
|
size: calcSize.avatarSize
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
|
|
2
|
+
circle: import("antd-style").SerializedStyles;
|
|
3
|
+
ios: import("antd-style").SerializedStyles;
|
|
2
4
|
root: import("antd-style").SerializedStyles;
|
|
5
|
+
sharp: import("antd-style").SerializedStyles;
|
|
6
|
+
smooth: import("antd-style").SerializedStyles;
|
|
7
|
+
square: import("antd-style").SerializedStyles;
|
|
8
|
+
squircle: import("antd-style").SerializedStyles;
|
|
3
9
|
}>;
|
package/es/GroupAvatar/style.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
var _templateObject;
|
|
1
|
+
var _templateObject, _templateObject2;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
|
+
import { SMOOTH_CORNER_MASKS } from "../utils/smoothCorners";
|
|
4
5
|
export var useStyles = createStyles(function (_ref) {
|
|
5
6
|
var css = _ref.css;
|
|
7
|
+
var baseRoot = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n flex: none;\n\n /* Fallback for browsers without mask support */\n border-radius: 15%;\n\n /* Apply smooth corners mask with fallback */\n @supports (mask-image: url('data:image/svg+xml;base64,')) {\n border-radius: 0;\n }\n "])));
|
|
8
|
+
var createCornerVariant = function createCornerVariant(cornerType) {
|
|
9
|
+
return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n mask-image: url('", "');\n mask-position: center;\n mask-repeat: no-repeat;\n mask-size: 100% 100%;\n "])), SMOOTH_CORNER_MASKS[cornerType]);
|
|
10
|
+
};
|
|
6
11
|
return {
|
|
7
|
-
|
|
12
|
+
circle: createCornerVariant('circle'),
|
|
13
|
+
ios: createCornerVariant('ios'),
|
|
14
|
+
root: baseRoot,
|
|
15
|
+
sharp: createCornerVariant('sharp'),
|
|
16
|
+
smooth: createCornerVariant('smooth'),
|
|
17
|
+
square: createCornerVariant('square'),
|
|
18
|
+
squircle: createCornerVariant('squircle')
|
|
8
19
|
};
|
|
9
20
|
});
|
package/es/GroupAvatar/type.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface GroupAvatarProps extends Omit<BlockProps, 'width' | 'height' |
|
|
|
7
7
|
avatarShape?: AvatarProps['shape'];
|
|
8
8
|
avatars?: AvatarItem[];
|
|
9
9
|
cornerShape?: keyof typeof SMOOTH_CORNER_MASKS;
|
|
10
|
+
grid?: 2 | 3 | 'auto';
|
|
10
11
|
ref?: Ref<HTMLDivElement>;
|
|
11
12
|
size?: number;
|
|
12
13
|
}
|