@pablo-v/avatar 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pablo Viniegra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @pablo-v/avatar
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ User avatar image with initials or identicon fallback
4
+
5
+ ```bash
6
+ pnpm add @pablo-v/avatar @pablo-v/tokens
7
+ ```
8
+
9
+ ```tsx
10
+ import '@pablo-v/tokens/styles.css';
11
+ import '@pablo-v/avatar/style.css';
12
+ import { Avatar } from '@pablo-v/avatar';
13
+ ```
@@ -0,0 +1,27 @@
1
+ import { type ComponentPropsWithRef, type ReactNode } from 'react';
2
+ export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg';
3
+ export type AvatarStatus = 'online' | 'away' | 'busy' | 'offline';
4
+ export interface AvatarProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {
5
+ /** Person or entity shown; names the avatar and feeds the initials fallback. */
6
+ name: string;
7
+ src?: string;
8
+ /** Replaces the initials when there is no image or it fails to load. */
9
+ fallback?: ReactNode;
10
+ /** @default 'md' */
11
+ size?: AvatarSize;
12
+ /** @default 'circle' */
13
+ shape?: 'circle' | 'square';
14
+ /** Presence cell in the corner, announced with the name. */
15
+ status?: AvatarStatus;
16
+ }
17
+ /** Profile picture with an initials fallback while loading or on error. */
18
+ export declare function Avatar({ name, src, fallback, size, shape, status, className, ...rest }: AvatarProps): import("react").JSX.Element;
19
+ export interface AvatarGroupProps extends ComponentPropsWithRef<'div'> {
20
+ /** Avatars beyond this count collapse into a "+N" chip. */
21
+ max?: number;
22
+ /** Size of the overflow chip; match the avatars. @default 'md' */
23
+ size?: AvatarSize;
24
+ }
25
+ /** Overlapping row of avatars. */
26
+ export declare function AvatarGroup({ max, size, className, children, ...rest }: AvatarGroupProps): import("react").JSX.Element;
27
+ //# sourceMappingURL=Avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAY,KAAK,qBAAqB,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AAEvF,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAClF,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oBAAoB;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,wBAAwB;IACxB,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAQD,2EAA2E;AAC3E,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,IAAW,EACX,KAAgB,EAChB,MAAM,EACN,SAAS,EACT,GAAG,IAAI,EACR,EAAE,WAAW,+BAsCb;AAED,MAAM,WAAW,gBAAiB,SAAQ,qBAAqB,CAAC,KAAK,CAAC;IACpE,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,kCAAkC;AAClC,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,IAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,gBAAgB,+BAsB/F"}
package/dist/Avatar.js ADDED
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { cx } from '@pablo-v/core';
4
+ import { Children, useState } from 'react';
5
+ function initials(name) {
6
+ const words = name.trim().split(/\s+/).filter(Boolean);
7
+ const letters = words.length > 1 ? [words[0], words[words.length - 1]] : words;
8
+ return letters.map((w) => Array.from(w ?? '')[0]?.toUpperCase()).join('');
9
+ }
10
+ /** Profile picture with an initials fallback while loading or on error. */
11
+ export function Avatar({ name, src, fallback, size = 'md', shape = 'circle', status, className, ...rest }) {
12
+ const [failed, setFailed] = useState();
13
+ const [loaded, setLoaded] = useState();
14
+ const showImage = src != null && failed !== src;
15
+ return (_jsxs("span", { role: "img", "aria-label": status ? `${name} (${status})` : name, className: cx('pxl-avatar', className), "data-size": size, "data-shape": shape, ...rest, children: [(!showImage || loaded !== src) && (_jsx("span", { className: "pxl-avatar__fallback", "aria-hidden": "true", children: fallback ?? initials(name) })), showImage && (_jsx("img", { className: "pxl-avatar__image", src: src, alt: "", "data-loaded": loaded === src || undefined, ref: (img) => {
16
+ // Cached images can finish before hydration attaches onLoad.
17
+ if (img?.complete)
18
+ img.naturalWidth ? setLoaded(src) : setFailed(src);
19
+ }, onLoad: () => setLoaded(src), onError: () => setFailed(src) })), status && (_jsx("span", { className: "pxl-avatar__status", "data-status": status, "aria-hidden": "true" }, status))] }));
20
+ }
21
+ /** Overlapping row of avatars. */
22
+ export function AvatarGroup({ max, size = 'md', className, children, ...rest }) {
23
+ const items = Children.toArray(children);
24
+ const visible = max != null && items.length > max ? items.slice(0, max) : items;
25
+ const hidden = items.length - visible.length;
26
+ return (_jsxs("div", { role: "group", className: cx('pxl-avatar-group', className), ...rest, children: [visible, hidden > 0 && (_jsx("span", { role: "img", "aria-label": `${hidden} more`, className: "pxl-avatar pxl-avatar__more", "data-size": size, "data-shape": "circle", children: _jsxs("span", { className: "pxl-avatar__fallback", "aria-hidden": "true", children: ["+", hidden] }) }))] }));
27
+ }
28
+ //# sourceMappingURL=Avatar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,QAAQ,EAA8C,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmBvF,SAAS,QAAQ,CAAC,IAAY;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CA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ACR,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,184 @@
1
+ .pxl-avatar {
2
+ --_size: var(--pxl-size-md);
3
+ --_text: var(--pxl-text-md);
4
+ --_radius: var(--pxl-radius-full);
5
+
6
+ position: relative;
7
+ display: inline-grid;
8
+ flex: none;
9
+ place-items: center;
10
+ width: var(--_size);
11
+ height: var(--_size);
12
+ border-radius: var(--_radius);
13
+ background: var(--pxl-gray-200);
14
+ color: var(--pxl-fg);
15
+ font-family: var(--pxl-font-sans);
16
+ font-size: var(--_text);
17
+ font-weight: 600;
18
+ line-height: 1;
19
+ user-select: none;
20
+ vertical-align: middle;
21
+ }
22
+
23
+ .pxl-avatar[data-size="xs"] {
24
+ --_size: var(--pxl-size-xs);
25
+ --_text: 10px;
26
+ }
27
+
28
+ .pxl-avatar[data-size="sm"] {
29
+ --_size: var(--pxl-size-sm);
30
+ --_text: var(--pxl-text-xs);
31
+ }
32
+
33
+ .pxl-avatar[data-size="lg"] {
34
+ --_size: var(--pxl-size-lg);
35
+ --_text: var(--pxl-text-lg);
36
+ }
37
+
38
+ .pxl-avatar[data-shape="square"] {
39
+ --_radius: var(--pxl-radius-md);
40
+ }
41
+
42
+ .pxl-avatar__fallback,
43
+ .pxl-avatar__image {
44
+ grid-area: 1 / 1;
45
+ }
46
+
47
+ .pxl-avatar__fallback {
48
+ display: grid;
49
+ place-items: center;
50
+ width: 100%;
51
+ height: 100%;
52
+ min-width: 0;
53
+ letter-spacing: -0.02em;
54
+ }
55
+
56
+ .pxl-avatar__fallback > svg {
57
+ width: 60%;
58
+ height: 60%;
59
+ }
60
+
61
+ .pxl-avatar__image {
62
+ min-width: 0;
63
+ width: 100%;
64
+ height: 100%;
65
+ border-radius: inherit;
66
+ object-fit: cover;
67
+ opacity: 0;
68
+ transition: opacity var(--pxl-dur-base) var(--pxl-ease-out);
69
+ }
70
+
71
+ .pxl-avatar__image[data-loaded] {
72
+ opacity: 1;
73
+ }
74
+
75
+ /* Hairline inside the edge so photos with a white or black rim keep their shape. */
76
+ .pxl-avatar::after {
77
+ position: absolute;
78
+ inset: 0;
79
+ border-radius: inherit;
80
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pxl-fg) 16%, transparent);
81
+ content: "";
82
+ pointer-events: none;
83
+ }
84
+
85
+ /* The presence marker is a single pixel cell, ringed by the page colour. */
86
+ .pxl-avatar__status {
87
+ position: absolute;
88
+ inset-inline-end: 0;
89
+ bottom: 0;
90
+ z-index: 1;
91
+ display: grid;
92
+ place-items: center;
93
+ width: max(8px, calc(var(--_size) / 5));
94
+ height: max(8px, calc(var(--_size) / 5));
95
+ border-radius: var(--pxl-radius-xs);
96
+ background: var(--pxl-gray-600);
97
+ box-shadow: 0 0 0 2px var(--pxl-bg);
98
+ animation: pxl-pop-in var(--pxl-dur-base) var(--pxl-ease-out) both;
99
+ }
100
+
101
+ .pxl-avatar[data-shape="square"] .pxl-avatar__status {
102
+ inset-inline-end: -2px;
103
+ bottom: -2px;
104
+ }
105
+
106
+ .pxl-avatar__status[data-status="online"] {
107
+ background: var(--pxl-success);
108
+ }
109
+
110
+ .pxl-avatar__status[data-status="away"] {
111
+ background: var(--pxl-warning);
112
+ }
113
+
114
+ .pxl-avatar__status[data-status="busy"] {
115
+ background: var(--pxl-danger);
116
+ }
117
+
118
+ .pxl-avatar__status[data-status="busy"]::after {
119
+ width: 4px;
120
+ height: 2px;
121
+ background: var(--pxl-bg);
122
+ content: "";
123
+ }
124
+
125
+ .pxl-avatar__status[data-status="away"]::after {
126
+ width: 3px;
127
+ height: 3px;
128
+ border-inline-start: 1px solid var(--pxl-bg);
129
+ border-bottom: 1px solid var(--pxl-bg);
130
+ content: "";
131
+ }
132
+
133
+ .pxl-avatar__status[data-status="offline"] {
134
+ box-sizing: border-box;
135
+ border: 2px solid var(--pxl-gray-600);
136
+ background: var(--pxl-bg);
137
+ }
138
+
139
+ .pxl-avatar-group {
140
+ display: inline-flex;
141
+ }
142
+
143
+ .pxl-avatar-group > .pxl-avatar {
144
+ box-shadow: 0 0 0 2px var(--pxl-bg);
145
+ }
146
+
147
+ .pxl-avatar-group > .pxl-avatar + .pxl-avatar {
148
+ margin-inline-start: calc(var(--_size) / -4);
149
+ }
150
+
151
+ .pxl-avatar__more {
152
+ background: var(--pxl-fg);
153
+ color: var(--pxl-bg);
154
+ font-family: var(--pxl-font-mono);
155
+ font-size: var(--pxl-text-xs);
156
+ font-weight: 500;
157
+ font-variant-numeric: tabular-nums;
158
+ }
159
+
160
+ @media (forced-colors: active) {
161
+ .pxl-avatar::after {
162
+ border: 1px solid CanvasText;
163
+ }
164
+
165
+ .pxl-avatar__status[data-status] {
166
+ background: CanvasText;
167
+ outline: 2px solid Canvas;
168
+ forced-color-adjust: none;
169
+ }
170
+
171
+ .pxl-avatar__status[data-status="offline"] {
172
+ border-color: CanvasText;
173
+ background: Canvas;
174
+ }
175
+
176
+ .pxl-avatar__status[data-status]::after {
177
+ border-color: Canvas;
178
+ background: Canvas;
179
+ }
180
+
181
+ .pxl-avatar__status[data-status="away"]::after {
182
+ background: transparent;
183
+ }
184
+ }
@@ -0,0 +1,2 @@
1
+ export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, type AvatarSize, type AvatarStatus, } from './Avatar.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Avatar, AvatarGroup, } from './Avatar.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,GAKZ,MAAM,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@pablo-v/avatar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Photo avatar with initials fallback, presence status and groups",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/PabloViniegra/pixel-ui.git",
9
+ "directory": "packages/avatar"
10
+ },
11
+ "type": "module",
12
+ "sideEffects": [
13
+ "*.css"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "source": "./src/index.ts",
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./style.css": {
22
+ "source": "./src/avatar.css",
23
+ "default": "./dist/avatar.css"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@pablo-v/core": "^0.2.2"
32
+ },
33
+ "peerDependencies": {
34
+ "react": "^19.0.0",
35
+ "@pablo-v/tokens": "^0.2.5"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -b && node ../../scripts/copy-assets.mjs",
42
+ "clean": "rm -rf dist *.tsbuildinfo"
43
+ }
6
44
  }