@avyn/initials-avatar-react 1.0.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/index.cjs ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.tsx
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ InitialsAvatar: () => InitialsAvatar,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_react = require("react");
28
+ var import_initials_avatar = require("@avyn/initials-avatar");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ var DEFAULT_SIZE = 96;
31
+ var InitialsAvatar = ({
32
+ name,
33
+ alt,
34
+ as = "img",
35
+ className,
36
+ style,
37
+ title,
38
+ imgProps,
39
+ svgProps,
40
+ ...avatarOptions
41
+ }) => {
42
+ const size = avatarOptions.size ?? DEFAULT_SIZE;
43
+ const memoKey = (0, import_react.useMemo)(() => JSON.stringify(avatarOptions), [avatarOptions]);
44
+ const dataUri = (0, import_react.useMemo)(() => (0, import_initials_avatar.createAvatarDataUri)(name, avatarOptions), [name, memoKey]);
45
+ const svgMarkup = (0, import_react.useMemo)(() => (0, import_initials_avatar.createAvatarSvg)(name, avatarOptions), [name, memoKey]);
46
+ const fallbackAlt = alt ?? `Avatar for ${name || (0, import_initials_avatar.getInitials)(name)}`;
47
+ if (as === "svg") {
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
+ "span",
50
+ {
51
+ className,
52
+ style,
53
+ dangerouslySetInnerHTML: { __html: svgMarkup },
54
+ "aria-label": fallbackAlt,
55
+ role: "img",
56
+ ...svgProps
57
+ }
58
+ );
59
+ }
60
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
61
+ "img",
62
+ {
63
+ src: dataUri,
64
+ width: size,
65
+ height: size,
66
+ alt: fallbackAlt,
67
+ className,
68
+ style,
69
+ title,
70
+ ...imgProps
71
+ }
72
+ );
73
+ };
74
+ var index_default = InitialsAvatar;
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ InitialsAvatar
78
+ });
@@ -0,0 +1,25 @@
1
+ import React, { CSSProperties, ImgHTMLAttributes, HTMLAttributes } from 'react';
2
+ import { AvatarOptions } from '@avyn/initials-avatar';
3
+ export { AvatarOptions } from '@avyn/initials-avatar';
4
+
5
+ type InitialsAvatarProps = AvatarOptions & {
6
+ /** Name used to derive initials */
7
+ name: string;
8
+ /** Accessible alternative text; falls back to the provided name */
9
+ alt?: string;
10
+ /** Render as <img> (default) or inline <svg> */
11
+ as?: 'img' | 'svg';
12
+ /** Optional CSS class */
13
+ className?: string;
14
+ /** Optional style object */
15
+ style?: CSSProperties;
16
+ /** Optional title attribute */
17
+ title?: string;
18
+ /** Extra props passed to the underlying <img> element */
19
+ imgProps?: Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'title'>;
20
+ /** Extra props passed to the inline <span> wrapper */
21
+ svgProps?: Omit<HTMLAttributes<HTMLSpanElement>, 'dangerouslySetInnerHTML'>;
22
+ };
23
+ declare const InitialsAvatar: React.FC<InitialsAvatarProps>;
24
+
25
+ export { InitialsAvatar, type InitialsAvatarProps, InitialsAvatar as default };
@@ -0,0 +1,25 @@
1
+ import React, { CSSProperties, ImgHTMLAttributes, HTMLAttributes } from 'react';
2
+ import { AvatarOptions } from '@avyn/initials-avatar';
3
+ export { AvatarOptions } from '@avyn/initials-avatar';
4
+
5
+ type InitialsAvatarProps = AvatarOptions & {
6
+ /** Name used to derive initials */
7
+ name: string;
8
+ /** Accessible alternative text; falls back to the provided name */
9
+ alt?: string;
10
+ /** Render as <img> (default) or inline <svg> */
11
+ as?: 'img' | 'svg';
12
+ /** Optional CSS class */
13
+ className?: string;
14
+ /** Optional style object */
15
+ style?: CSSProperties;
16
+ /** Optional title attribute */
17
+ title?: string;
18
+ /** Extra props passed to the underlying <img> element */
19
+ imgProps?: Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'title'>;
20
+ /** Extra props passed to the inline <span> wrapper */
21
+ svgProps?: Omit<HTMLAttributes<HTMLSpanElement>, 'dangerouslySetInnerHTML'>;
22
+ };
23
+ declare const InitialsAvatar: React.FC<InitialsAvatarProps>;
24
+
25
+ export { InitialsAvatar, type InitialsAvatarProps, InitialsAvatar as default };
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // src/index.tsx
2
+ import { useMemo } from "react";
3
+ import { createAvatarDataUri, createAvatarSvg, getInitials } from "@avyn/initials-avatar";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var DEFAULT_SIZE = 96;
6
+ var InitialsAvatar = ({
7
+ name,
8
+ alt,
9
+ as = "img",
10
+ className,
11
+ style,
12
+ title,
13
+ imgProps,
14
+ svgProps,
15
+ ...avatarOptions
16
+ }) => {
17
+ const size = avatarOptions.size ?? DEFAULT_SIZE;
18
+ const memoKey = useMemo(() => JSON.stringify(avatarOptions), [avatarOptions]);
19
+ const dataUri = useMemo(() => createAvatarDataUri(name, avatarOptions), [name, memoKey]);
20
+ const svgMarkup = useMemo(() => createAvatarSvg(name, avatarOptions), [name, memoKey]);
21
+ const fallbackAlt = alt ?? `Avatar for ${name || getInitials(name)}`;
22
+ if (as === "svg") {
23
+ return /* @__PURE__ */ jsx(
24
+ "span",
25
+ {
26
+ className,
27
+ style,
28
+ dangerouslySetInnerHTML: { __html: svgMarkup },
29
+ "aria-label": fallbackAlt,
30
+ role: "img",
31
+ ...svgProps
32
+ }
33
+ );
34
+ }
35
+ return /* @__PURE__ */ jsx(
36
+ "img",
37
+ {
38
+ src: dataUri,
39
+ width: size,
40
+ height: size,
41
+ alt: fallbackAlt,
42
+ className,
43
+ style,
44
+ title,
45
+ ...imgProps
46
+ }
47
+ );
48
+ };
49
+ var index_default = InitialsAvatar;
50
+ export {
51
+ InitialsAvatar,
52
+ index_default as default
53
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@avyn/initials-avatar-react",
3
+ "version": "1.0.0",
4
+ "description": "React component wrapper for @avyn/initials-avatar",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.tsx --format esm,cjs --dts --clean"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "^18.0.0 || ^19.0.0"
25
+ },
26
+ "dependencies": {
27
+ "@avyn/initials-avatar": "1.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "tsup": "^8.2.4",
31
+ "typescript": "^5.6.3"
32
+ },
33
+ "sideEffects": false,
34
+ "author": "@avyn",
35
+ "license": "MIT"
36
+ }