@elmqeddem/react-avatar 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.
@@ -0,0 +1,11 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface AvatarProps {
5
+ name?: string;
6
+ size?: number;
7
+ content?: string | ReactNode;
8
+ }
9
+ declare const Avatar: ({ name, size, content, }: AvatarProps) => react_jsx_runtime.JSX.Element;
10
+
11
+ export { Avatar };
@@ -0,0 +1,11 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface AvatarProps {
5
+ name?: string;
6
+ size?: number;
7
+ content?: string | ReactNode;
8
+ }
9
+ declare const Avatar: ({ name, size, content, }: AvatarProps) => react_jsx_runtime.JSX.Element;
10
+
11
+ export { Avatar };
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
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.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Avatar: () => Avatar
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/Avatar.tsx
28
+ var import_react = require("react");
29
+ var import_string_to_color = require("@marko19907/string-to-color");
30
+ var import_jsx_runtime = require("react/jsx-runtime");
31
+ var Avatar = ({
32
+ name = "",
33
+ size = 40,
34
+ content
35
+ }) => {
36
+ const bgColor = (0, import_string_to_color.generateColor)(name || "default", {
37
+ saturation: 70,
38
+ lightness: 94
39
+ });
40
+ const textColor = (0, import_string_to_color.generateColor)(name || "default", {
41
+ saturation: 70,
42
+ lightness: 60
43
+ });
44
+ const initials = name ? name.split(" ").map((w) => {
45
+ var _a;
46
+ return (_a = w[0]) == null ? void 0 : _a.toUpperCase();
47
+ }).slice(0, 2).join("") : "";
48
+ const renderContent = content ? typeof content === "string" ? content : (0, import_react.isValidElement)(content) ? (0, import_react.cloneElement)(content, {
49
+ size: size * 0.5,
50
+ // auto scale icon
51
+ strokeWidth: 2
52
+ // Lucide icons look better
53
+ }) : null : initials;
54
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
55
+ "div",
56
+ {
57
+ style: {
58
+ width: size,
59
+ height: size,
60
+ backgroundColor: bgColor,
61
+ color: textColor,
62
+ display: "flex",
63
+ alignItems: "center",
64
+ justifyContent: "center",
65
+ borderRadius: "50%",
66
+ fontWeight: "400",
67
+ fontSize: size * 0.45,
68
+ userSelect: "none"
69
+ },
70
+ children: renderContent
71
+ }
72
+ );
73
+ };
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ Avatar
77
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,50 @@
1
+ // src/Avatar.tsx
2
+ import { isValidElement, cloneElement } from "react";
3
+ import { generateColor } from "@marko19907/string-to-color";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var Avatar = ({
6
+ name = "",
7
+ size = 40,
8
+ content
9
+ }) => {
10
+ const bgColor = generateColor(name || "default", {
11
+ saturation: 70,
12
+ lightness: 94
13
+ });
14
+ const textColor = generateColor(name || "default", {
15
+ saturation: 70,
16
+ lightness: 60
17
+ });
18
+ const initials = name ? name.split(" ").map((w) => {
19
+ var _a;
20
+ return (_a = w[0]) == null ? void 0 : _a.toUpperCase();
21
+ }).slice(0, 2).join("") : "";
22
+ const renderContent = content ? typeof content === "string" ? content : isValidElement(content) ? cloneElement(content, {
23
+ size: size * 0.5,
24
+ // auto scale icon
25
+ strokeWidth: 2
26
+ // Lucide icons look better
27
+ }) : null : initials;
28
+ return /* @__PURE__ */ jsx(
29
+ "div",
30
+ {
31
+ style: {
32
+ width: size,
33
+ height: size,
34
+ backgroundColor: bgColor,
35
+ color: textColor,
36
+ display: "flex",
37
+ alignItems: "center",
38
+ justifyContent: "center",
39
+ borderRadius: "50%",
40
+ fontWeight: "400",
41
+ fontSize: size * 0.45,
42
+ userSelect: "none"
43
+ },
44
+ children: renderContent
45
+ }
46
+ );
47
+ };
48
+ export {
49
+ Avatar
50
+ };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@elmqeddem/react-avatar",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "build": "tsup src/index.ts --dts --format esm,cjs"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": "",
12
+ "dependencies": {
13
+ "@marko19907/string-to-color": "^1.0.1",
14
+ "lucide-react": "^0.562.0",
15
+ "react": "^18.3.1",
16
+ "react-dom": "^18.3.1"
17
+ },
18
+ "devDependencies": {
19
+ "@types/react": "^18.3.27",
20
+ "@types/react-dom": "^18.3.7",
21
+ "tsup": "^8.5.1",
22
+ "typescript": "^5.9.3"
23
+ }
24
+ }
package/src/Avatar.tsx ADDED
@@ -0,0 +1,63 @@
1
+ import React, { ReactNode, isValidElement, cloneElement, ReactElement } from "react";
2
+ import { generateColor } from "@marko19907/string-to-color";
3
+
4
+ interface AvatarProps {
5
+ name?: string;
6
+ size?: number;
7
+ content?: string | ReactNode ;
8
+ }
9
+
10
+ export const Avatar = ({
11
+ name = "",
12
+ size = 40,
13
+ content,
14
+ }: AvatarProps) => {
15
+ const bgColor = generateColor(name || "default", {
16
+ saturation: 70,
17
+ lightness: 94,
18
+ });
19
+
20
+ const textColor = generateColor(name || "default", {
21
+ saturation: 70,
22
+ lightness: 60,
23
+ });
24
+
25
+ const initials = name
26
+ ? name
27
+ .split(" ")
28
+ .map(w => w[0]?.toUpperCase())
29
+ .slice(0, 2)
30
+ .join("")
31
+ : "";
32
+
33
+ const renderContent = content
34
+ ? typeof content === "string"
35
+ ? content
36
+ : isValidElement(content)
37
+ ? cloneElement(content as ReactElement<any>, {
38
+ size: size * 0.5, // auto scale icon
39
+ strokeWidth: 2, // Lucide icons look better
40
+ })
41
+ : null
42
+ : initials;
43
+
44
+ return (
45
+ <div
46
+ style={{
47
+ width: size,
48
+ height: size,
49
+ backgroundColor: bgColor,
50
+ color: textColor,
51
+ display: "flex",
52
+ alignItems: "center",
53
+ justifyContent: "center",
54
+ borderRadius: "50%",
55
+ fontWeight: "400",
56
+ fontSize: size * 0.45,
57
+ userSelect: "none",
58
+ }}
59
+ >
60
+ {renderContent}
61
+ </div>
62
+ );
63
+ };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { Avatar } from "./Avatar";
@@ -0,0 +1,9 @@
1
+ declare module "@marko19907/string-to-color" {
2
+ interface GenerateColorOptions {
3
+ saturation?: number;
4
+ lightness?: number;
5
+ }
6
+
7
+ export function generateColor(str: string, options?: GenerateColorOptions): string;
8
+ }
9
+
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2018",
4
+ "module": "ESNext",
5
+ "jsx": "react-jsx",
6
+ "moduleResolution": "bundler",
7
+ "declaration": true,
8
+ "outDir": "dist",
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "esModuleInterop": true
13
+ },
14
+ "include": ["src"]
15
+ }
16
+