@heroui/avatar 2.2.7 → 2.2.8

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,207 +0,0 @@
1
- import * as tailwind_variants from 'tailwind-variants';
2
- import * as react from 'react';
3
- import * as _heroui_system from '@heroui/system';
4
- import { PropGetter, DOMAttributes, DOMElement, HTMLHeroUIProps } from '@heroui/system';
5
- import { AvatarVariantProps, SlotsToClasses, AvatarSlots } from '@heroui/theme';
6
- import { ReactRef } from '@heroui/react-utils';
7
-
8
- interface Props extends HTMLHeroUIProps<"span"> {
9
- /**
10
- * Ref to the DOM node.
11
- */
12
- ref?: ReactRef<HTMLSpanElement | null>;
13
- /**
14
- * Ref to the Image DOM node.
15
- */
16
- imgRef?: ReactRef<HTMLImageElement>;
17
- /**
18
- * The name of the person in the avatar. -
19
- * if **src** has loaded, the name will be used as the **alt** attribute of the **img**
20
- * - If **src** is not loaded, the name will be used to create the initials
21
- */
22
- name?: string;
23
- /**
24
- * Image source.
25
- */
26
- src?: string;
27
- /**
28
- * Image alt text.
29
- */
30
- alt?: string;
31
- icon?: React.ReactNode;
32
- /**
33
- * Whether the avatar can be focused.
34
- * @default false
35
- */
36
- isFocusable?: boolean;
37
- /**
38
- * If `true`, the fallback logic will be skipped.
39
- * @default false
40
- */
41
- ignoreFallback?: boolean;
42
- /**
43
- * If `false`, the avatar will show the background color while loading.
44
- */
45
- showFallback?: boolean;
46
- /**
47
- * Function to get the initials to display
48
- */
49
- getInitials?: (name: string) => string;
50
- /**
51
- * Custom fallback component.
52
- */
53
- fallback?: React.ReactNode;
54
- /**
55
- * Function called when image failed to load
56
- */
57
- onError?: () => void;
58
- /**
59
- * The component used to render the image.
60
- * @default "img"
61
- */
62
- ImgComponent?: React.ElementType;
63
- /**
64
- * Props to pass to the image component.
65
- */
66
- imgProps?: React.ImgHTMLAttributes<HTMLImageElement>;
67
- /**
68
- * Classname or List of classes to change the classNames of the avatar.
69
- * if `className` is passed, it will be added to the base slot.
70
- *
71
- * @example
72
- * ```ts
73
- * <Avatar classNames={{
74
- * base:"base-classes",
75
- * img: "image-classes",
76
- * name: "name-classes",
77
- * icon: "icon-classes",
78
- * fallback: "fallback-classes"
79
- * }} />
80
- * ```
81
- */
82
- classNames?: SlotsToClasses<AvatarSlots>;
83
- }
84
- type UseAvatarProps = Props & Omit<AvatarVariantProps, "children" | "isInGroup" | "isInGridGroup">;
85
- declare function useAvatar(originalProps?: UseAvatarProps): {
86
- Component: _heroui_system.As<any>;
87
- ImgComponent: react.ElementType<any>;
88
- src: string | undefined;
89
- alt: string;
90
- icon: react.ReactNode;
91
- name: string | undefined;
92
- imgRef: react.RefObject<HTMLImageElement>;
93
- slots: {
94
- base: (slotProps?: ({
95
- size?: "sm" | "md" | "lg" | undefined;
96
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
97
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
98
- isBordered?: boolean | undefined;
99
- isDisabled?: boolean | undefined;
100
- isInGroup?: boolean | undefined;
101
- isInGridGroup?: boolean | undefined;
102
- disableAnimation?: boolean | undefined;
103
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
104
- img: (slotProps?: ({
105
- size?: "sm" | "md" | "lg" | undefined;
106
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
107
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
108
- isBordered?: boolean | undefined;
109
- isDisabled?: boolean | undefined;
110
- isInGroup?: boolean | undefined;
111
- isInGridGroup?: boolean | undefined;
112
- disableAnimation?: boolean | undefined;
113
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
114
- fallback: (slotProps?: ({
115
- size?: "sm" | "md" | "lg" | undefined;
116
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
117
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
118
- isBordered?: boolean | undefined;
119
- isDisabled?: boolean | undefined;
120
- isInGroup?: boolean | undefined;
121
- isInGridGroup?: boolean | undefined;
122
- disableAnimation?: boolean | undefined;
123
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
124
- name: (slotProps?: ({
125
- size?: "sm" | "md" | "lg" | undefined;
126
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
127
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
128
- isBordered?: boolean | undefined;
129
- isDisabled?: boolean | undefined;
130
- isInGroup?: boolean | undefined;
131
- isInGridGroup?: boolean | undefined;
132
- disableAnimation?: boolean | undefined;
133
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
134
- icon: (slotProps?: ({
135
- size?: "sm" | "md" | "lg" | undefined;
136
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
137
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
138
- isBordered?: boolean | undefined;
139
- isDisabled?: boolean | undefined;
140
- isInGroup?: boolean | undefined;
141
- isInGridGroup?: boolean | undefined;
142
- disableAnimation?: boolean | undefined;
143
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
144
- } & {
145
- base: (slotProps?: ({
146
- size?: "sm" | "md" | "lg" | undefined;
147
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
148
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
149
- isBordered?: boolean | undefined;
150
- isDisabled?: boolean | undefined;
151
- isInGroup?: boolean | undefined;
152
- isInGridGroup?: boolean | undefined;
153
- disableAnimation?: boolean | undefined;
154
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
155
- img: (slotProps?: ({
156
- size?: "sm" | "md" | "lg" | undefined;
157
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
158
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
159
- isBordered?: boolean | undefined;
160
- isDisabled?: boolean | undefined;
161
- isInGroup?: boolean | undefined;
162
- isInGridGroup?: boolean | undefined;
163
- disableAnimation?: boolean | undefined;
164
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
165
- fallback: (slotProps?: ({
166
- size?: "sm" | "md" | "lg" | undefined;
167
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
168
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
169
- isBordered?: boolean | undefined;
170
- isDisabled?: boolean | undefined;
171
- isInGroup?: boolean | undefined;
172
- isInGridGroup?: boolean | undefined;
173
- disableAnimation?: boolean | undefined;
174
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
175
- name: (slotProps?: ({
176
- size?: "sm" | "md" | "lg" | undefined;
177
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
178
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
179
- isBordered?: boolean | undefined;
180
- isDisabled?: boolean | undefined;
181
- isInGroup?: boolean | undefined;
182
- isInGridGroup?: boolean | undefined;
183
- disableAnimation?: boolean | undefined;
184
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
185
- icon: (slotProps?: ({
186
- size?: "sm" | "md" | "lg" | undefined;
187
- color?: "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined;
188
- radius?: "sm" | "md" | "lg" | "none" | "full" | undefined;
189
- isBordered?: boolean | undefined;
190
- isDisabled?: boolean | undefined;
191
- isInGroup?: boolean | undefined;
192
- isInGridGroup?: boolean | undefined;
193
- disableAnimation?: boolean | undefined;
194
- } & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
195
- } & {};
196
- classNames: SlotsToClasses<"name" | "base" | "img" | "icon" | "fallback"> | undefined;
197
- fallback: react.ReactNode;
198
- isImgLoaded: boolean;
199
- showFallback: boolean;
200
- ignoreFallback: boolean;
201
- getInitials: (text: string) => string;
202
- getAvatarProps: PropGetter<Record<string, unknown>, DOMAttributes<DOMElement>>;
203
- getImageProps: PropGetter<Record<string, unknown>, DOMAttributes<DOMElement>>;
204
- };
205
- type UseAvatarReturn = ReturnType<typeof useAvatar>;
206
-
207
- export { UseAvatarProps, UseAvatarReturn, useAvatar };
@@ -1,167 +0,0 @@
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_theme = require("@heroui/theme");
28
- var import_system = require("@heroui/system");
29
- var import_utils = require("@react-aria/utils");
30
- var import_react_utils2 = require("@heroui/react-utils");
31
- var import_shared_utils = require("@heroui/shared-utils");
32
- var import_focus = require("@react-aria/focus");
33
- var import_react = require("react");
34
- var import_use_image = require("@heroui/use-image");
35
- var import_interactions = require("@react-aria/interactions");
36
-
37
- // src/avatar-group-context.ts
38
- var import_react_utils = require("@heroui/react-utils");
39
- var [AvatarGroupProvider, useAvatarGroupContext] = (0, import_react_utils.createContext)({
40
- name: "AvatarGroupContext",
41
- strict: false
42
- });
43
-
44
- // src/use-avatar.ts
45
- function useAvatar(originalProps = {}) {
46
- var _a, _b, _c, _d, _e, _f;
47
- const globalContext = (0, import_system.useProviderContext)();
48
- const groupContext = useAvatarGroupContext();
49
- const isInGroup = !!groupContext;
50
- const {
51
- as,
52
- ref,
53
- src,
54
- name,
55
- icon,
56
- classNames,
57
- fallback,
58
- alt = name || "avatar",
59
- imgRef: imgRefProp,
60
- color = (_a = groupContext == null ? void 0 : groupContext.color) != null ? _a : "default",
61
- radius = (_b = groupContext == null ? void 0 : groupContext.radius) != null ? _b : "full",
62
- size = (_c = groupContext == null ? void 0 : groupContext.size) != null ? _c : "md",
63
- isBordered = (_d = groupContext == null ? void 0 : groupContext.isBordered) != null ? _d : false,
64
- isDisabled = (_e = groupContext == null ? void 0 : groupContext.isDisabled) != null ? _e : false,
65
- isFocusable = false,
66
- getInitials = import_shared_utils.safeText,
67
- ignoreFallback = false,
68
- showFallback: showFallbackProp = false,
69
- ImgComponent = "img",
70
- imgProps,
71
- className,
72
- onError,
73
- disableAnimation: disableAnimationProp,
74
- ...otherProps
75
- } = originalProps;
76
- const Component = as || "span";
77
- const domRef = (0, import_react_utils2.useDOMRef)(ref);
78
- const imgRef = (0, import_react_utils2.useDOMRef)(imgRefProp);
79
- const { isFocusVisible, isFocused, focusProps } = (0, import_focus.useFocusRing)();
80
- const { isHovered, hoverProps } = (0, import_interactions.useHover)({ isDisabled });
81
- const disableAnimation = (_f = disableAnimationProp != null ? disableAnimationProp : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _f : false;
82
- const imageStatus = (0, import_use_image.useImage)({ src, onError, ignoreFallback });
83
- const isImgLoaded = imageStatus === "loaded";
84
- const shouldFilterDOMProps = typeof ImgComponent === "string";
85
- const showFallback = (!src || !isImgLoaded) && showFallbackProp;
86
- const slots = (0, import_react.useMemo)(
87
- () => {
88
- var _a2;
89
- return (0, import_theme.avatar)({
90
- color,
91
- radius,
92
- size,
93
- isBordered,
94
- isDisabled,
95
- isInGroup,
96
- disableAnimation,
97
- isInGridGroup: (_a2 = groupContext == null ? void 0 : groupContext.isGrid) != null ? _a2 : false
98
- });
99
- },
100
- [
101
- color,
102
- radius,
103
- size,
104
- isBordered,
105
- isDisabled,
106
- disableAnimation,
107
- isInGroup,
108
- groupContext == null ? void 0 : groupContext.isGrid
109
- ]
110
- );
111
- const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
112
- const canBeFocused = (0, import_react.useMemo)(() => {
113
- return isFocusable || as === "button";
114
- }, [isFocusable, as]);
115
- const getAvatarProps = (0, import_react.useCallback)(
116
- (props = {}) => ({
117
- ref: domRef,
118
- tabIndex: canBeFocused ? 0 : -1,
119
- "data-hover": (0, import_shared_utils.dataAttr)(isHovered),
120
- "data-focus": (0, import_shared_utils.dataAttr)(isFocused),
121
- "data-focus-visible": (0, import_shared_utils.dataAttr)(isFocusVisible),
122
- className: slots.base({
123
- class: (0, import_shared_utils.clsx)(baseStyles, props == null ? void 0 : props.className)
124
- }),
125
- ...(0, import_utils.mergeProps)(otherProps, hoverProps, canBeFocused ? focusProps : {})
126
- }),
127
- [canBeFocused, slots, baseStyles, focusProps, otherProps]
128
- );
129
- const getImageProps = (0, import_react.useCallback)(
130
- (props = {}) => ({
131
- ref: imgRef,
132
- src,
133
- "data-loaded": (0, import_shared_utils.dataAttr)(isImgLoaded),
134
- className: slots.img({ class: classNames == null ? void 0 : classNames.img }),
135
- ...(0, import_utils.mergeProps)(
136
- imgProps,
137
- props,
138
- (0, import_react_utils2.filterDOMProps)({ disableAnimation }, {
139
- enabled: shouldFilterDOMProps
140
- })
141
- )
142
- }),
143
- [slots, isImgLoaded, imgProps, disableAnimation, src, imgRef, shouldFilterDOMProps]
144
- );
145
- return {
146
- Component,
147
- ImgComponent,
148
- src,
149
- alt,
150
- icon,
151
- name,
152
- imgRef,
153
- slots,
154
- classNames,
155
- fallback,
156
- isImgLoaded,
157
- showFallback,
158
- ignoreFallback,
159
- getInitials,
160
- getAvatarProps,
161
- getImageProps
162
- };
163
- }
164
- // Annotate the CommonJS export names for ESM import in node:
165
- 0 && (module.exports = {
166
- useAvatar
167
- });
@@ -1,8 +0,0 @@
1
- "use client";
2
- import {
3
- useAvatar
4
- } from "./chunk-LTC67JRI.mjs";
5
- import "./chunk-JUJ53SJZ.mjs";
6
- export {
7
- useAvatar
8
- };