@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.
@@ -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 };
@@ -0,0 +1,141 @@
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.ts
22
+ var use_avatar_exports = {};
23
+ __export(use_avatar_exports, {
24
+ useAvatar: () => useAvatar
25
+ });
26
+ module.exports = __toCommonJS(use_avatar_exports);
27
+ var import_shared_utils = require("@kopexa/shared-utils");
28
+ var import_theme = require("@kopexa/theme");
29
+ var import_react = require("react");
30
+
31
+ // src/avatar-group.context.ts
32
+ var import_react_utils = require("@kopexa/react-utils");
33
+ var [AvatarGroupProvider, useAvatarGroupContext] = (0, import_react_utils.createContext)({
34
+ name: "AvatarGroupContext",
35
+ strict: false
36
+ });
37
+
38
+ // src/use-avatar.ts
39
+ function useAvatar(originalProps = {}) {
40
+ var _a, _b, _c, _d, _e;
41
+ const groupContext = useAvatarGroupContext();
42
+ const isInGroup = !!groupContext;
43
+ const {
44
+ ref,
45
+ src,
46
+ name,
47
+ classNames,
48
+ alt = name || "avatar",
49
+ imgRef: imgRefProp,
50
+ color = (_a = groupContext == null ? void 0 : groupContext.color) != null ? _a : "default",
51
+ radius = (_b = groupContext == null ? void 0 : groupContext.radius) != null ? _b : "full",
52
+ size = (_c = groupContext == null ? void 0 : groupContext.size) != null ? _c : "md",
53
+ isBordered = (_d = groupContext == null ? void 0 : groupContext.isBordered) != null ? _d : false,
54
+ isDisabled = (_e = groupContext == null ? void 0 : groupContext.isDisabled) != null ? _e : false,
55
+ className,
56
+ onError,
57
+ onLoadingStatusChange,
58
+ ...otherProps
59
+ } = originalProps;
60
+ const [status, setStatus] = (0, import_react.useState)("idle");
61
+ const handleLoadingStatusChange = (0, import_react.useCallback)(
62
+ (status2) => {
63
+ onLoadingStatusChange == null ? void 0 : onLoadingStatusChange(status2);
64
+ setStatus(status2);
65
+ },
66
+ [onLoadingStatusChange]
67
+ );
68
+ const slots = (0, import_react.useMemo)(
69
+ () => {
70
+ var _a2;
71
+ return (0, import_theme.avatar)({
72
+ color,
73
+ radius,
74
+ size,
75
+ isBordered,
76
+ isDisabled,
77
+ isInGroup,
78
+ isInGridGroup: (_a2 = groupContext == null ? void 0 : groupContext.isGrid) != null ? _a2 : false
79
+ });
80
+ },
81
+ [
82
+ color,
83
+ radius,
84
+ size,
85
+ isBordered,
86
+ isDisabled,
87
+ isInGroup,
88
+ groupContext == null ? void 0 : groupContext.isGrid
89
+ ]
90
+ );
91
+ const baseStyles = (0, import_shared_utils.cn)(classNames == null ? void 0 : classNames.root, className);
92
+ const getAvatarProps = (0, import_react.useCallback)(
93
+ (props = {}) => ({
94
+ ref,
95
+ "data-slot": "avatar",
96
+ className: slots.root({
97
+ class: (0, import_shared_utils.cn)(baseStyles, props == null ? void 0 : props.className)
98
+ }),
99
+ ...otherProps
100
+ }),
101
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we want to memoize this
102
+ [slots, baseStyles, otherProps, ref]
103
+ );
104
+ const getImageProps = (0, import_react.useCallback)(
105
+ () => ({
106
+ "data-slot": "avatar-image",
107
+ "data-status": status,
108
+ src,
109
+ onLoadingStatusChange: handleLoadingStatusChange,
110
+ ref: imgRefProp,
111
+ alt,
112
+ onError,
113
+ className: slots.img({
114
+ class: classNames == null ? void 0 : classNames.img
115
+ })
116
+ }),
117
+ [
118
+ status,
119
+ src,
120
+ handleLoadingStatusChange,
121
+ imgRefProp,
122
+ alt,
123
+ slots.img,
124
+ classNames == null ? void 0 : classNames.img,
125
+ onError
126
+ ]
127
+ );
128
+ return {
129
+ src,
130
+ alt,
131
+ slots,
132
+ classNames,
133
+ name,
134
+ getAvatarProps,
135
+ getImageProps
136
+ };
137
+ }
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ useAvatar
141
+ });
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import {
3
+ useAvatar
4
+ } from "./chunk-CI55TF4E.mjs";
5
+ import "./chunk-FBUAHX2S.mjs";
6
+ export {
7
+ useAvatar
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopexa/avatar",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "The Avatar component is used to represent a user, and displays the profile picture, initials or fallback icon.",
5
5
  "keywords": [
6
6
  "avatar"
@@ -28,12 +28,12 @@
28
28
  "motion": ">=12.23.6",
29
29
  "react": ">=19.0.0-rc.0",
30
30
  "react-dom": ">=19.0.0-rc.0",
31
- "@kopexa/theme": "1.5.2"
31
+ "@kopexa/theme": "1.5.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "@radix-ui/react-avatar": "^1.1.10",
35
- "@kopexa/react-utils": "2.0.3",
36
- "@kopexa/shared-utils": "1.1.3"
35
+ "@kopexa/react-utils": "2.0.4",
36
+ "@kopexa/shared-utils": "1.1.4"
37
37
  },
38
38
  "clean-package": "../../../clean-package.config.json",
39
39
  "module": "dist/index.mjs",
@@ -1,109 +0,0 @@
1
- "use client";
2
-
3
- // src/avatar.tsx
4
- import { getInitials } from "@kopexa/shared-utils";
5
- import {
6
- avatar
7
- } from "@kopexa/theme";
8
- import * as AvatarPrimitive from "@radix-ui/react-avatar";
9
- import { useState } from "react";
10
- import { jsx, jsxs } from "react/jsx-runtime";
11
- var Avatar = (props) => {
12
- const {
13
- className,
14
- size,
15
- radius,
16
- name,
17
- color,
18
- src,
19
- onLoadingStatusChange,
20
- isBordered,
21
- isDisabled,
22
- imgRef,
23
- classNames,
24
- alt,
25
- ...rest
26
- } = props;
27
- const [status, setStatus] = useState(
28
- "idle"
29
- );
30
- const styles = avatar({ size, radius, color, isBordered, isDisabled });
31
- const handleLoadingStatusChange = (status2) => {
32
- onLoadingStatusChange == null ? void 0 : onLoadingStatusChange(status2);
33
- setStatus(status2);
34
- };
35
- return /* @__PURE__ */ jsxs(
36
- AvatarPrimitive.Root,
37
- {
38
- "data-slot": "avatar",
39
- className: styles.root({ className }),
40
- ...rest,
41
- children: [
42
- /* @__PURE__ */ jsx(
43
- AvatarPrimitive.Image,
44
- {
45
- "data-slot": "avatar-image",
46
- src,
47
- "data-status": status,
48
- className: styles.img(),
49
- onLoadingStatusChange: handleLoadingStatusChange,
50
- ref: imgRef,
51
- alt
52
- }
53
- ),
54
- /* @__PURE__ */ jsx(AvatarPrimitive.Fallback, { "data-slot": "avatar-fallback", children: name ? /* @__PURE__ */ jsx(
55
- "span",
56
- {
57
- className: styles.name({
58
- className: classNames == null ? void 0 : classNames.name
59
- }),
60
- role: "img",
61
- "aria-label": alt,
62
- children: getInitials(name)
63
- }
64
- ) : /* @__PURE__ */ jsx(
65
- "span",
66
- {
67
- className: styles.icon({
68
- className: classNames == null ? void 0 : classNames.icon
69
- }),
70
- role: "img",
71
- "aria-label": alt,
72
- children: /* @__PURE__ */ jsx(AvatarIcon, {})
73
- }
74
- ) })
75
- ]
76
- }
77
- );
78
- };
79
- var AvatarIcon = () => /* @__PURE__ */ jsxs(
80
- "svg",
81
- {
82
- "aria-hidden": "true",
83
- fill: "none",
84
- height: "80%",
85
- role: "presentation",
86
- viewBox: "0 0 24 24",
87
- width: "80%",
88
- children: [
89
- /* @__PURE__ */ jsx(
90
- "path",
91
- {
92
- d: "M12 2C9.38 2 7.25 4.13 7.25 6.75C7.25 9.32 9.26 11.4 11.88 11.49C11.96 11.48 12.04 11.48 12.1 11.49C12.12 11.49 12.13 11.49 12.15 11.49C12.16 11.49 12.16 11.49 12.17 11.49C14.73 11.4 16.74 9.32 16.75 6.75C16.75 4.13 14.62 2 12 2Z",
93
- fill: "currentColor"
94
- }
95
- ),
96
- /* @__PURE__ */ jsx(
97
- "path",
98
- {
99
- d: "M17.0809 14.1489C14.2909 12.2889 9.74094 12.2889 6.93094 14.1489C5.66094 14.9989 4.96094 16.1489 4.96094 17.3789C4.96094 18.6089 5.66094 19.7489 6.92094 20.5889C8.32094 21.5289 10.1609 21.9989 12.0009 21.9989C13.8409 21.9989 15.6809 21.5289 17.0809 20.5889C18.3409 19.7389 19.0409 18.5989 19.0409 17.3589C19.0309 16.1289 18.3409 14.9889 17.0809 14.1489Z",
100
- fill: "currentColor"
101
- }
102
- )
103
- ]
104
- }
105
- );
106
-
107
- export {
108
- Avatar
109
- };