@kopexa/avatar 1.0.1 → 1.0.2
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-group.context.d.mts +13 -0
- package/dist/avatar-group.context.d.ts +13 -0
- package/dist/avatar-group.context.js +37 -0
- package/dist/avatar-group.context.mjs +9 -0
- package/dist/avatar-group.d.mts +14 -0
- package/dist/avatar-group.d.ts +14 -0
- package/dist/avatar-group.js +306 -0
- package/dist/avatar-group.mjs +11 -0
- package/dist/avatar.d.mts +7 -17
- package/dist/avatar.d.ts +7 -17
- package/dist/avatar.js +135 -63
- package/dist/avatar.mjs +3 -1
- package/dist/chunk-CI55TF4E.mjs +118 -0
- package/dist/chunk-FBUAHX2S.mjs +13 -0
- package/dist/chunk-HBUPEI6X.mjs +30 -0
- package/dist/chunk-J37VYVJO.mjs +83 -0
- package/dist/chunk-KPWT5YIU.mjs +67 -0
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +231 -65
- package/dist/index.mjs +9 -2
- package/dist/use-avatar-group.d.mts +51 -0
- package/dist/use-avatar-group.d.ts +51 -0
- package/dist/use-avatar-group.js +104 -0
- package/dist/use-avatar-group.mjs +7 -0
- package/dist/use-avatar.d.mts +136 -0
- package/dist/use-avatar.d.ts +136 -0
- package/dist/use-avatar.js +141 -0
- package/dist/use-avatar.mjs +8 -0
- package/package.json +4 -4
- package/dist/chunk-EVKHBB7E.mjs +0 -109
package/dist/index.js
CHANGED
|
@@ -31,83 +31,156 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
Avatar: () => Avatar
|
|
34
|
+
Avatar: () => Avatar,
|
|
35
|
+
AvatarGroup: () => AvatarGroup
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(index_exports);
|
|
37
38
|
|
|
38
39
|
// src/avatar.tsx
|
|
40
|
+
var import_shared_utils2 = require("@kopexa/shared-utils");
|
|
41
|
+
var AvatarPrimitive = __toESM(require("@radix-ui/react-avatar"));
|
|
42
|
+
|
|
43
|
+
// src/use-avatar.ts
|
|
39
44
|
var import_shared_utils = require("@kopexa/shared-utils");
|
|
40
45
|
var import_theme = require("@kopexa/theme");
|
|
41
|
-
var AvatarPrimitive = __toESM(require("@radix-ui/react-avatar"));
|
|
42
46
|
var import_react = require("react");
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
|
|
48
|
+
// src/avatar-group.context.ts
|
|
49
|
+
var import_react_utils = require("@kopexa/react-utils");
|
|
50
|
+
var [AvatarGroupProvider, useAvatarGroupContext] = (0, import_react_utils.createContext)({
|
|
51
|
+
name: "AvatarGroupContext",
|
|
52
|
+
strict: false
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/use-avatar.ts
|
|
56
|
+
function useAvatar(originalProps = {}) {
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
|
+
const groupContext = useAvatarGroupContext();
|
|
59
|
+
const isInGroup = !!groupContext;
|
|
45
60
|
const {
|
|
46
|
-
|
|
47
|
-
size,
|
|
48
|
-
radius,
|
|
49
|
-
name,
|
|
50
|
-
color,
|
|
61
|
+
ref,
|
|
51
62
|
src,
|
|
52
|
-
|
|
53
|
-
isBordered,
|
|
54
|
-
isDisabled,
|
|
55
|
-
imgRef,
|
|
63
|
+
name,
|
|
56
64
|
classNames,
|
|
57
|
-
alt,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
65
|
+
alt = name || "avatar",
|
|
66
|
+
imgRef: imgRefProp,
|
|
67
|
+
color = (_a = groupContext == null ? void 0 : groupContext.color) != null ? _a : "default",
|
|
68
|
+
radius = (_b = groupContext == null ? void 0 : groupContext.radius) != null ? _b : "full",
|
|
69
|
+
size = (_c = groupContext == null ? void 0 : groupContext.size) != null ? _c : "md",
|
|
70
|
+
isBordered = (_d = groupContext == null ? void 0 : groupContext.isBordered) != null ? _d : false,
|
|
71
|
+
isDisabled = (_e = groupContext == null ? void 0 : groupContext.isDisabled) != null ? _e : false,
|
|
72
|
+
className,
|
|
73
|
+
onError,
|
|
74
|
+
onLoadingStatusChange,
|
|
75
|
+
...otherProps
|
|
76
|
+
} = originalProps;
|
|
77
|
+
const [status, setStatus] = (0, import_react.useState)("idle");
|
|
78
|
+
const handleLoadingStatusChange = (0, import_react.useCallback)(
|
|
79
|
+
(status2) => {
|
|
80
|
+
onLoadingStatusChange == null ? void 0 : onLoadingStatusChange(status2);
|
|
81
|
+
setStatus(status2);
|
|
82
|
+
},
|
|
83
|
+
[onLoadingStatusChange]
|
|
62
84
|
);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
const slots = (0, import_react.useMemo)(
|
|
86
|
+
() => {
|
|
87
|
+
var _a2;
|
|
88
|
+
return (0, import_theme.avatar)({
|
|
89
|
+
color,
|
|
90
|
+
radius,
|
|
91
|
+
size,
|
|
92
|
+
isBordered,
|
|
93
|
+
isDisabled,
|
|
94
|
+
isInGroup,
|
|
95
|
+
isInGridGroup: (_a2 = groupContext == null ? void 0 : groupContext.isGrid) != null ? _a2 : false
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
[
|
|
99
|
+
color,
|
|
100
|
+
radius,
|
|
101
|
+
size,
|
|
102
|
+
isBordered,
|
|
103
|
+
isDisabled,
|
|
104
|
+
isInGroup,
|
|
105
|
+
groupContext == null ? void 0 : groupContext.isGrid
|
|
106
|
+
]
|
|
107
|
+
);
|
|
108
|
+
const baseStyles = (0, import_shared_utils.cn)(classNames == null ? void 0 : classNames.root, className);
|
|
109
|
+
const getAvatarProps = (0, import_react.useCallback)(
|
|
110
|
+
(props = {}) => ({
|
|
111
|
+
ref,
|
|
71
112
|
"data-slot": "avatar",
|
|
72
|
-
className:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
src,
|
|
80
|
-
"data-status": status,
|
|
81
|
-
className: styles.img(),
|
|
82
|
-
onLoadingStatusChange: handleLoadingStatusChange,
|
|
83
|
-
ref: imgRef,
|
|
84
|
-
alt
|
|
85
|
-
}
|
|
86
|
-
),
|
|
87
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarPrimitive.Fallback, { "data-slot": "avatar-fallback", children: name ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
88
|
-
"span",
|
|
89
|
-
{
|
|
90
|
-
className: styles.name({
|
|
91
|
-
className: classNames == null ? void 0 : classNames.name
|
|
92
|
-
}),
|
|
93
|
-
role: "img",
|
|
94
|
-
"aria-label": alt,
|
|
95
|
-
children: (0, import_shared_utils.getInitials)(name)
|
|
96
|
-
}
|
|
97
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
|
-
"span",
|
|
99
|
-
{
|
|
100
|
-
className: styles.icon({
|
|
101
|
-
className: classNames == null ? void 0 : classNames.icon
|
|
102
|
-
}),
|
|
103
|
-
role: "img",
|
|
104
|
-
"aria-label": alt,
|
|
105
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarIcon, {})
|
|
106
|
-
}
|
|
107
|
-
) })
|
|
108
|
-
]
|
|
109
|
-
}
|
|
113
|
+
className: slots.root({
|
|
114
|
+
class: (0, import_shared_utils.cn)(baseStyles, props == null ? void 0 : props.className)
|
|
115
|
+
}),
|
|
116
|
+
...otherProps
|
|
117
|
+
}),
|
|
118
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we want to memoize this
|
|
119
|
+
[slots, baseStyles, otherProps, ref]
|
|
110
120
|
);
|
|
121
|
+
const getImageProps = (0, import_react.useCallback)(
|
|
122
|
+
() => ({
|
|
123
|
+
"data-slot": "avatar-image",
|
|
124
|
+
"data-status": status,
|
|
125
|
+
src,
|
|
126
|
+
onLoadingStatusChange: handleLoadingStatusChange,
|
|
127
|
+
ref: imgRefProp,
|
|
128
|
+
alt,
|
|
129
|
+
onError,
|
|
130
|
+
className: slots.img({
|
|
131
|
+
class: classNames == null ? void 0 : classNames.img
|
|
132
|
+
})
|
|
133
|
+
}),
|
|
134
|
+
[
|
|
135
|
+
status,
|
|
136
|
+
src,
|
|
137
|
+
handleLoadingStatusChange,
|
|
138
|
+
imgRefProp,
|
|
139
|
+
alt,
|
|
140
|
+
slots.img,
|
|
141
|
+
classNames == null ? void 0 : classNames.img,
|
|
142
|
+
onError
|
|
143
|
+
]
|
|
144
|
+
);
|
|
145
|
+
return {
|
|
146
|
+
src,
|
|
147
|
+
alt,
|
|
148
|
+
slots,
|
|
149
|
+
classNames,
|
|
150
|
+
name,
|
|
151
|
+
getAvatarProps,
|
|
152
|
+
getImageProps
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/avatar.tsx
|
|
157
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
158
|
+
var Avatar = (props) => {
|
|
159
|
+
const { alt, getAvatarProps, getImageProps, slots, classNames, name } = useAvatar(props);
|
|
160
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AvatarPrimitive.Root, { ...getAvatarProps(), children: [
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarPrimitive.Image, { ...getImageProps() }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarPrimitive.Fallback, { "data-slot": "avatar-fallback", children: name ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
+
"span",
|
|
164
|
+
{
|
|
165
|
+
className: slots.name({
|
|
166
|
+
className: classNames == null ? void 0 : classNames.name
|
|
167
|
+
}),
|
|
168
|
+
role: "img",
|
|
169
|
+
"aria-label": alt,
|
|
170
|
+
children: (0, import_shared_utils2.getInitials)(name)
|
|
171
|
+
}
|
|
172
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
|
+
"span",
|
|
174
|
+
{
|
|
175
|
+
className: slots.icon({
|
|
176
|
+
className: classNames == null ? void 0 : classNames.icon
|
|
177
|
+
}),
|
|
178
|
+
role: "img",
|
|
179
|
+
"aria-label": alt,
|
|
180
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarIcon, {})
|
|
181
|
+
}
|
|
182
|
+
) })
|
|
183
|
+
] });
|
|
111
184
|
};
|
|
112
185
|
var AvatarIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
113
186
|
"svg",
|
|
@@ -136,7 +209,100 @@ var AvatarIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
|
136
209
|
]
|
|
137
210
|
}
|
|
138
211
|
);
|
|
212
|
+
|
|
213
|
+
// src/use-avatar-group.ts
|
|
214
|
+
var import_react_utils2 = require("@kopexa/react-utils");
|
|
215
|
+
var import_shared_utils3 = require("@kopexa/shared-utils");
|
|
216
|
+
var import_theme2 = require("@kopexa/theme");
|
|
217
|
+
var import_react2 = require("react");
|
|
218
|
+
function useAvatarGroup(props = {}) {
|
|
219
|
+
const {
|
|
220
|
+
ref,
|
|
221
|
+
max = 5,
|
|
222
|
+
total,
|
|
223
|
+
size,
|
|
224
|
+
color,
|
|
225
|
+
radius,
|
|
226
|
+
children,
|
|
227
|
+
isBordered,
|
|
228
|
+
isDisabled,
|
|
229
|
+
isGrid,
|
|
230
|
+
className,
|
|
231
|
+
classNames,
|
|
232
|
+
...otherProps
|
|
233
|
+
} = props;
|
|
234
|
+
const context = (0, import_react2.useMemo)(
|
|
235
|
+
() => ({
|
|
236
|
+
size,
|
|
237
|
+
color,
|
|
238
|
+
radius,
|
|
239
|
+
isGrid,
|
|
240
|
+
isBordered,
|
|
241
|
+
isDisabled
|
|
242
|
+
}),
|
|
243
|
+
[size, color, radius, isGrid, isBordered, isDisabled]
|
|
244
|
+
);
|
|
245
|
+
const slots = (0, import_react2.useMemo)(
|
|
246
|
+
() => (0, import_theme2.avatarGroup)({ className, isGrid }),
|
|
247
|
+
[className, isGrid]
|
|
248
|
+
);
|
|
249
|
+
const validChildren = (0, import_react_utils2.getValidChildren)(children);
|
|
250
|
+
const childrenWithinMax = max ? validChildren.slice(0, max) : validChildren;
|
|
251
|
+
const remainingCount = total ? total : max != null ? validChildren.length - max : -1;
|
|
252
|
+
const clones = childrenWithinMax.map((child, index) => {
|
|
253
|
+
const isFirstAvatar = index === 0;
|
|
254
|
+
const isLastAvatar = index === childrenWithinMax.length - 1;
|
|
255
|
+
const childProps = {
|
|
256
|
+
className: (0, import_shared_utils3.cn)(
|
|
257
|
+
isFirstAvatar ? "ms-0" : !isGrid ? "-ms-2" : "",
|
|
258
|
+
isLastAvatar && remainingCount < 1 ? "hover:-translate-x-0" : ""
|
|
259
|
+
)
|
|
260
|
+
};
|
|
261
|
+
return (0, import_react2.cloneElement)(child, (0, import_shared_utils3.compact)(childProps));
|
|
262
|
+
});
|
|
263
|
+
const getAvatarGroupProps = () => {
|
|
264
|
+
return {
|
|
265
|
+
ref,
|
|
266
|
+
className: slots.base({
|
|
267
|
+
class: (0, import_shared_utils3.cn)(classNames == null ? void 0 : classNames.base, className)
|
|
268
|
+
}),
|
|
269
|
+
role: "group",
|
|
270
|
+
...otherProps
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
const getAvatarGroupCountProps = () => {
|
|
274
|
+
return {
|
|
275
|
+
className: slots.count({
|
|
276
|
+
class: classNames == null ? void 0 : classNames.count
|
|
277
|
+
})
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
return {
|
|
281
|
+
context,
|
|
282
|
+
remainingCount,
|
|
283
|
+
clones,
|
|
284
|
+
getAvatarGroupProps,
|
|
285
|
+
getAvatarGroupCountProps
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/avatar-group.tsx
|
|
290
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
291
|
+
function AvatarGroup(props) {
|
|
292
|
+
const {
|
|
293
|
+
clones,
|
|
294
|
+
context,
|
|
295
|
+
remainingCount,
|
|
296
|
+
getAvatarGroupCountProps,
|
|
297
|
+
getAvatarGroupProps
|
|
298
|
+
} = useAvatarGroup(props);
|
|
299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getAvatarGroupProps(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(AvatarGroupProvider, { value: context, children: [
|
|
300
|
+
clones,
|
|
301
|
+
remainingCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Avatar, { ...getAvatarGroupCountProps(), name: `+${remainingCount}` })
|
|
302
|
+
] }) });
|
|
303
|
+
}
|
|
139
304
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
305
|
0 && (module.exports = {
|
|
141
|
-
Avatar
|
|
306
|
+
Avatar,
|
|
307
|
+
AvatarGroup
|
|
142
308
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
AvatarGroup
|
|
4
|
+
} from "./chunk-HBUPEI6X.mjs";
|
|
2
5
|
import {
|
|
3
6
|
Avatar
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KPWT5YIU.mjs";
|
|
8
|
+
import "./chunk-J37VYVJO.mjs";
|
|
9
|
+
import "./chunk-CI55TF4E.mjs";
|
|
10
|
+
import "./chunk-FBUAHX2S.mjs";
|
|
5
11
|
export {
|
|
6
|
-
Avatar
|
|
12
|
+
Avatar,
|
|
13
|
+
AvatarGroup
|
|
7
14
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { PropGetter } from '@kopexa/react-utils';
|
|
4
|
+
import { SlotsToClasses, AvatarGroupSlots, AvatarGroupVariantProps } from '@kopexa/theme';
|
|
5
|
+
import { AvatarProps } from './avatar.mjs';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import './use-avatar.mjs';
|
|
8
|
+
import 'tailwind-variants';
|
|
9
|
+
|
|
10
|
+
type Props = ComponentProps<"div"> & {
|
|
11
|
+
/**
|
|
12
|
+
* The maximum number of visible avatars
|
|
13
|
+
* @default 5
|
|
14
|
+
*/
|
|
15
|
+
max?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Control the number of avatar not visible
|
|
18
|
+
*/
|
|
19
|
+
total?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Classname or List of classes to change the classNames of the avatar group.
|
|
22
|
+
* if `className` is passed, it will be added to the base slot.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* <AvatarGroup classNames={{
|
|
27
|
+
* base: "base-classes",
|
|
28
|
+
* count: "count-classes"
|
|
29
|
+
* }} />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
classNames?: SlotsToClasses<AvatarGroupSlots>;
|
|
33
|
+
};
|
|
34
|
+
type UseAvatarGroupProps = Props & Omit<AvatarGroupVariantProps, "children"> & Partial<Pick<AvatarProps, "size" | "color" | "radius" | "isDisabled" | "isBordered">>;
|
|
35
|
+
type ContextType = {
|
|
36
|
+
size?: AvatarProps["size"];
|
|
37
|
+
color?: AvatarProps["color"];
|
|
38
|
+
radius?: AvatarProps["radius"];
|
|
39
|
+
isGrid?: boolean;
|
|
40
|
+
isBordered?: AvatarProps["isBordered"];
|
|
41
|
+
isDisabled?: AvatarProps["isDisabled"];
|
|
42
|
+
};
|
|
43
|
+
declare function useAvatarGroup(props?: UseAvatarGroupProps): {
|
|
44
|
+
context: ContextType;
|
|
45
|
+
remainingCount: number;
|
|
46
|
+
clones: react.ReactElement<unknown, string | react.JSXElementConstructor<any>>[];
|
|
47
|
+
getAvatarGroupProps: PropGetter;
|
|
48
|
+
getAvatarGroupCountProps: () => AvatarProps;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { type ContextType, type UseAvatarGroupProps, useAvatarGroup };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { PropGetter } from '@kopexa/react-utils';
|
|
4
|
+
import { SlotsToClasses, AvatarGroupSlots, AvatarGroupVariantProps } from '@kopexa/theme';
|
|
5
|
+
import { AvatarProps } from './avatar.js';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import './use-avatar.js';
|
|
8
|
+
import 'tailwind-variants';
|
|
9
|
+
|
|
10
|
+
type Props = ComponentProps<"div"> & {
|
|
11
|
+
/**
|
|
12
|
+
* The maximum number of visible avatars
|
|
13
|
+
* @default 5
|
|
14
|
+
*/
|
|
15
|
+
max?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Control the number of avatar not visible
|
|
18
|
+
*/
|
|
19
|
+
total?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Classname or List of classes to change the classNames of the avatar group.
|
|
22
|
+
* if `className` is passed, it will be added to the base slot.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* <AvatarGroup classNames={{
|
|
27
|
+
* base: "base-classes",
|
|
28
|
+
* count: "count-classes"
|
|
29
|
+
* }} />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
classNames?: SlotsToClasses<AvatarGroupSlots>;
|
|
33
|
+
};
|
|
34
|
+
type UseAvatarGroupProps = Props & Omit<AvatarGroupVariantProps, "children"> & Partial<Pick<AvatarProps, "size" | "color" | "radius" | "isDisabled" | "isBordered">>;
|
|
35
|
+
type ContextType = {
|
|
36
|
+
size?: AvatarProps["size"];
|
|
37
|
+
color?: AvatarProps["color"];
|
|
38
|
+
radius?: AvatarProps["radius"];
|
|
39
|
+
isGrid?: boolean;
|
|
40
|
+
isBordered?: AvatarProps["isBordered"];
|
|
41
|
+
isDisabled?: AvatarProps["isDisabled"];
|
|
42
|
+
};
|
|
43
|
+
declare function useAvatarGroup(props?: UseAvatarGroupProps): {
|
|
44
|
+
context: ContextType;
|
|
45
|
+
remainingCount: number;
|
|
46
|
+
clones: react.ReactElement<unknown, string | react.JSXElementConstructor<any>>[];
|
|
47
|
+
getAvatarGroupProps: PropGetter;
|
|
48
|
+
getAvatarGroupCountProps: () => AvatarProps;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { type ContextType, type UseAvatarGroupProps, useAvatarGroup };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/use-avatar-group.ts
|
|
22
|
+
var use_avatar_group_exports = {};
|
|
23
|
+
__export(use_avatar_group_exports, {
|
|
24
|
+
useAvatarGroup: () => useAvatarGroup
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(use_avatar_group_exports);
|
|
27
|
+
var import_react_utils = require("@kopexa/react-utils");
|
|
28
|
+
var import_shared_utils = require("@kopexa/shared-utils");
|
|
29
|
+
var import_theme = require("@kopexa/theme");
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
function useAvatarGroup(props = {}) {
|
|
32
|
+
const {
|
|
33
|
+
ref,
|
|
34
|
+
max = 5,
|
|
35
|
+
total,
|
|
36
|
+
size,
|
|
37
|
+
color,
|
|
38
|
+
radius,
|
|
39
|
+
children,
|
|
40
|
+
isBordered,
|
|
41
|
+
isDisabled,
|
|
42
|
+
isGrid,
|
|
43
|
+
className,
|
|
44
|
+
classNames,
|
|
45
|
+
...otherProps
|
|
46
|
+
} = props;
|
|
47
|
+
const context = (0, import_react.useMemo)(
|
|
48
|
+
() => ({
|
|
49
|
+
size,
|
|
50
|
+
color,
|
|
51
|
+
radius,
|
|
52
|
+
isGrid,
|
|
53
|
+
isBordered,
|
|
54
|
+
isDisabled
|
|
55
|
+
}),
|
|
56
|
+
[size, color, radius, isGrid, isBordered, isDisabled]
|
|
57
|
+
);
|
|
58
|
+
const slots = (0, import_react.useMemo)(
|
|
59
|
+
() => (0, import_theme.avatarGroup)({ className, isGrid }),
|
|
60
|
+
[className, isGrid]
|
|
61
|
+
);
|
|
62
|
+
const validChildren = (0, import_react_utils.getValidChildren)(children);
|
|
63
|
+
const childrenWithinMax = max ? validChildren.slice(0, max) : validChildren;
|
|
64
|
+
const remainingCount = total ? total : max != null ? validChildren.length - max : -1;
|
|
65
|
+
const clones = childrenWithinMax.map((child, index) => {
|
|
66
|
+
const isFirstAvatar = index === 0;
|
|
67
|
+
const isLastAvatar = index === childrenWithinMax.length - 1;
|
|
68
|
+
const childProps = {
|
|
69
|
+
className: (0, import_shared_utils.cn)(
|
|
70
|
+
isFirstAvatar ? "ms-0" : !isGrid ? "-ms-2" : "",
|
|
71
|
+
isLastAvatar && remainingCount < 1 ? "hover:-translate-x-0" : ""
|
|
72
|
+
)
|
|
73
|
+
};
|
|
74
|
+
return (0, import_react.cloneElement)(child, (0, import_shared_utils.compact)(childProps));
|
|
75
|
+
});
|
|
76
|
+
const getAvatarGroupProps = () => {
|
|
77
|
+
return {
|
|
78
|
+
ref,
|
|
79
|
+
className: slots.base({
|
|
80
|
+
class: (0, import_shared_utils.cn)(classNames == null ? void 0 : classNames.base, className)
|
|
81
|
+
}),
|
|
82
|
+
role: "group",
|
|
83
|
+
...otherProps
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const getAvatarGroupCountProps = () => {
|
|
87
|
+
return {
|
|
88
|
+
className: slots.count({
|
|
89
|
+
class: classNames == null ? void 0 : classNames.count
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
context,
|
|
95
|
+
remainingCount,
|
|
96
|
+
clones,
|
|
97
|
+
getAvatarGroupProps,
|
|
98
|
+
getAvatarGroupCountProps
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
useAvatarGroup
|
|
104
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as tailwind_variants from 'tailwind-variants';
|
|
2
|
+
import { PropGetter } from '@kopexa/react-utils';
|
|
3
|
+
import { SlotsToClasses, AvatarSlots, AvatarVariantProps } from '@kopexa/theme';
|
|
4
|
+
import { ComponentProps, RefObject } from 'react';
|
|
5
|
+
|
|
6
|
+
interface Props extends ComponentProps<"span"> {
|
|
7
|
+
/**
|
|
8
|
+
* Ref to the Image DOM node.
|
|
9
|
+
*/
|
|
10
|
+
imgRef?: RefObject<HTMLImageElement | null>;
|
|
11
|
+
/**
|
|
12
|
+
* The name of the person in the avatar. -
|
|
13
|
+
* if **src** has loaded, the name will be used as the **alt** attribute of the **img**
|
|
14
|
+
* - If **src** is not loaded, the name will be used to create the initials
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Image source.
|
|
19
|
+
*/
|
|
20
|
+
src?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Image alt text.
|
|
23
|
+
*/
|
|
24
|
+
alt?: string;
|
|
25
|
+
classNames?: SlotsToClasses<AvatarSlots>;
|
|
26
|
+
onLoadingStatusChange?: (status: ImageStatus) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Function called when image failed to load
|
|
29
|
+
*/
|
|
30
|
+
onError?: () => void;
|
|
31
|
+
}
|
|
32
|
+
type UseAvatarProps = Props & Omit<AvatarVariantProps, "children" | "isInGroup" | "isInGridGroup">;
|
|
33
|
+
type ImageStatus = "idle" | "loading" | "loaded" | "error";
|
|
34
|
+
declare function useAvatar(originalProps?: UseAvatarProps): {
|
|
35
|
+
src: string | undefined;
|
|
36
|
+
alt: string;
|
|
37
|
+
slots: {
|
|
38
|
+
root: (slotProps?: ({
|
|
39
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
40
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
41
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
42
|
+
isBordered?: boolean | undefined;
|
|
43
|
+
isDisabled?: boolean | undefined;
|
|
44
|
+
isInGroup?: boolean | undefined;
|
|
45
|
+
isInGridGroup?: boolean | undefined;
|
|
46
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
47
|
+
img: (slotProps?: ({
|
|
48
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
49
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
50
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
51
|
+
isBordered?: boolean | undefined;
|
|
52
|
+
isDisabled?: boolean | undefined;
|
|
53
|
+
isInGroup?: boolean | undefined;
|
|
54
|
+
isInGridGroup?: boolean | undefined;
|
|
55
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
56
|
+
fallback: (slotProps?: ({
|
|
57
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
58
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
59
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
60
|
+
isBordered?: boolean | undefined;
|
|
61
|
+
isDisabled?: boolean | undefined;
|
|
62
|
+
isInGroup?: boolean | undefined;
|
|
63
|
+
isInGridGroup?: boolean | undefined;
|
|
64
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
65
|
+
name: (slotProps?: ({
|
|
66
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
67
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
68
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
69
|
+
isBordered?: boolean | undefined;
|
|
70
|
+
isDisabled?: boolean | undefined;
|
|
71
|
+
isInGroup?: boolean | undefined;
|
|
72
|
+
isInGridGroup?: boolean | undefined;
|
|
73
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
74
|
+
icon: (slotProps?: ({
|
|
75
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
76
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
77
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
78
|
+
isBordered?: boolean | undefined;
|
|
79
|
+
isDisabled?: boolean | undefined;
|
|
80
|
+
isInGroup?: boolean | undefined;
|
|
81
|
+
isInGridGroup?: boolean | undefined;
|
|
82
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
83
|
+
} & {
|
|
84
|
+
root: (slotProps?: ({
|
|
85
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
86
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
87
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
88
|
+
isBordered?: boolean | undefined;
|
|
89
|
+
isDisabled?: boolean | undefined;
|
|
90
|
+
isInGroup?: boolean | undefined;
|
|
91
|
+
isInGridGroup?: boolean | undefined;
|
|
92
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
93
|
+
img: (slotProps?: ({
|
|
94
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
95
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
96
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
97
|
+
isBordered?: boolean | undefined;
|
|
98
|
+
isDisabled?: boolean | undefined;
|
|
99
|
+
isInGroup?: boolean | undefined;
|
|
100
|
+
isInGridGroup?: boolean | undefined;
|
|
101
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
102
|
+
fallback: (slotProps?: ({
|
|
103
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
104
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
105
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
106
|
+
isBordered?: boolean | undefined;
|
|
107
|
+
isDisabled?: boolean | undefined;
|
|
108
|
+
isInGroup?: boolean | undefined;
|
|
109
|
+
isInGridGroup?: boolean | undefined;
|
|
110
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
111
|
+
name: (slotProps?: ({
|
|
112
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
113
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
114
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
115
|
+
isBordered?: boolean | undefined;
|
|
116
|
+
isDisabled?: boolean | undefined;
|
|
117
|
+
isInGroup?: boolean | undefined;
|
|
118
|
+
isInGridGroup?: boolean | undefined;
|
|
119
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
120
|
+
icon: (slotProps?: ({
|
|
121
|
+
size?: "md" | "sm" | "lg" | undefined;
|
|
122
|
+
radius?: "none" | "md" | "full" | "sm" | "lg" | undefined;
|
|
123
|
+
color?: "default" | "primary" | "secondary" | "success" | "warning" | "destructive" | undefined;
|
|
124
|
+
isBordered?: boolean | undefined;
|
|
125
|
+
isDisabled?: boolean | undefined;
|
|
126
|
+
isInGroup?: boolean | undefined;
|
|
127
|
+
isInGridGroup?: boolean | undefined;
|
|
128
|
+
} & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
|
|
129
|
+
} & {};
|
|
130
|
+
classNames: SlotsToClasses<"name" | "img" | "root" | "fallback" | "icon"> | undefined;
|
|
131
|
+
name: string | undefined;
|
|
132
|
+
getAvatarProps: PropGetter;
|
|
133
|
+
getImageProps: PropGetter;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export { type ImageStatus, type UseAvatarProps, useAvatar };
|