@xsolla/xui-avatar 0.99.0 → 0.100.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.
Files changed (2) hide show
  1. package/README.md +257 -32
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,57 +1,282 @@
1
- # @xsolla/xui-avatar
1
+ ---
2
+ title: Avatar
3
+ subtitle: An avatar for user images or initials.
4
+ description: A cross-platform React avatar component displaying user images, icons, or initials with optional badge support.
5
+ ---
2
6
 
3
- Avatar and avatar group components supporting images, initials, icons, and notification badges.
7
+ # Avatar
8
+
9
+ A cross-platform React avatar component that displays user images, icons, or text initials. Supports badges for notifications and can be grouped together.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-avatar
15
+ # or
8
16
  yarn add @xsolla/xui-avatar
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic Avatar
22
+
23
+ ```tsx
24
+ import * as React from 'react';
25
+ import { Avatar } from '@xsolla/xui-avatar';
26
+
27
+ export default function BasicAvatar() {
28
+ return (
29
+ <div style={{ display: 'flex', gap: 16 }}>
30
+ <Avatar src="https://example.com/user.jpg" />
31
+ <Avatar text="JD" />
32
+ <Avatar /> {/* Default user icon */}
33
+ </div>
34
+ );
35
+ }
36
+ ```
37
+
38
+ ### Avatar Sizes
39
+
40
+ ```tsx
41
+ import * as React from 'react';
42
+ import { Avatar } from '@xsolla/xui-avatar';
43
+
44
+ export default function AvatarSizes() {
45
+ return (
46
+ <div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
47
+ <Avatar size="xs" text="XS" />
48
+ <Avatar size="sm" text="S" />
49
+ <Avatar size="md" text="M" />
50
+ <Avatar size="lg" text="L" />
51
+ <Avatar size="xl" text="XL" />
52
+ </div>
53
+ );
54
+ }
55
+ ```
56
+
57
+ ### Avatar with Badge
58
+
59
+ ```tsx
60
+ import * as React from 'react';
61
+ import { Avatar } from '@xsolla/xui-avatar';
62
+
63
+ export default function AvatarWithBadge() {
64
+ return (
65
+ <div style={{ display: 'flex', gap: 24 }}>
66
+ <Avatar src="https://example.com/user.jpg" badge />
67
+ <Avatar src="https://example.com/user.jpg" badge badgeCount={5} />
68
+ <Avatar src="https://example.com/user.jpg" badge badgeCount={99} badgeTone="alert" />
69
+ </div>
70
+ );
71
+ }
72
+ ```
73
+
74
+ ### Square Avatar
12
75
 
13
76
  ```tsx
14
- import { Avatar, AvatarGroup } from '@xsolla/xui-avatar';
77
+ import * as React from 'react';
78
+ import { Avatar } from '@xsolla/xui-avatar';
79
+
80
+ export default function SquareAvatar() {
81
+ return (
82
+ <div style={{ display: 'flex', gap: 16 }}>
83
+ <Avatar src="https://example.com/user.jpg" />
84
+ <Avatar src="https://example.com/user.jpg" square />
85
+ </div>
86
+ );
87
+ }
88
+ ```
15
89
 
16
- <Avatar src="https://example.com/user.jpg" size="md" />
90
+ ## Anatomy
17
91
 
18
- <AvatarGroup
19
- list={[
20
- { src: 'https://example.com/a.jpg', tooltip: 'Alice' },
21
- { initials: 'BJ', tooltip: 'Bob Jones' },
22
- ]}
23
- maxVisible={5}
92
+ Import the component and use it directly:
93
+
94
+ ```jsx
95
+ import { Avatar } from '@xsolla/xui-avatar';
96
+
97
+ <Avatar
98
+ src="image-url" // Image source URL
99
+ text="AB" // Text/initials when no image
100
+ icon={<CustomIcon />} // Custom icon when no image
101
+ size="md" // Size variant
102
+ square={false} // Square vs circular
103
+ badge={false} // Show notification badge
104
+ badgeCount={5} // Badge count
105
+ badgeTone="brand" // Badge color tone
106
+ stroke={false} // Show border
107
+ backgroundColor="#color" // Custom background
108
+ onClick={handleClick} // Click handler
24
109
  />
25
110
  ```
26
111
 
27
- ## Components
112
+ ## Examples
113
+
114
+ ### Avatar with Custom Icon
115
+
116
+ ```tsx
117
+ import * as React from 'react';
118
+ import { Avatar } from '@xsolla/xui-avatar';
119
+ import { Building2, Briefcase, Star } from '@xsolla/xui-icons-base';
120
+
121
+ export default function AvatarWithIcon() {
122
+ return (
123
+ <div style={{ display: 'flex', gap: 16 }}>
124
+ <Avatar icon={<Building2 />} backgroundColor="#4A90D9" />
125
+ <Avatar icon={<Briefcase />} backgroundColor="#9B59B6" />
126
+ <Avatar icon={<Star />} backgroundColor="#F39C12" />
127
+ </div>
128
+ );
129
+ }
130
+ ```
131
+
132
+ ### Avatar with Stroke
133
+
134
+ ```tsx
135
+ import * as React from 'react';
136
+ import { Avatar } from '@xsolla/xui-avatar';
137
+
138
+ export default function AvatarWithStroke() {
139
+ return (
140
+ <Avatar
141
+ src="https://example.com/user.jpg"
142
+ stroke
143
+ size="lg"
144
+ />
145
+ );
146
+ }
147
+ ```
148
+
149
+ ### Clickable Avatar
150
+
151
+ ```tsx
152
+ import * as React from 'react';
153
+ import { Avatar } from '@xsolla/xui-avatar';
154
+
155
+ export default function ClickableAvatar() {
156
+ return (
157
+ <Avatar
158
+ text="JD"
159
+ size="lg"
160
+ onClick={() => alert('Avatar clicked!')}
161
+ aria-label="View John Doe's profile"
162
+ />
163
+ );
164
+ }
165
+ ```
166
+
167
+ ### Avatar Group
168
+
169
+ ```tsx
170
+ import * as React from 'react';
171
+ import { AvatarGroup } from '@xsolla/xui-avatar';
172
+
173
+ export default function AvatarGroupExample() {
174
+ const users = [
175
+ { src: 'https://example.com/user1.jpg' },
176
+ { src: 'https://example.com/user2.jpg' },
177
+ { initials: 'JD' },
178
+ { initials: 'AB' },
179
+ { initials: 'CD' },
180
+ { initials: 'EF' },
181
+ { initials: 'GH' },
182
+ ];
183
+
184
+ return (
185
+ <AvatarGroup
186
+ list={users}
187
+ maxVisible={5}
188
+ size="md"
189
+ />
190
+ );
191
+ }
192
+ ```
193
+
194
+ ### Badge Tones
195
+
196
+ ```tsx
197
+ import * as React from 'react';
198
+ import { Avatar } from '@xsolla/xui-avatar';
28
199
 
29
- - **Avatar** Single avatar displaying an image, initials, icon, or default user icon.
30
- - **AvatarGroup** — Row of overlapping avatars with a "+N" overflow counter.
200
+ export default function BadgeTones() {
201
+ return (
202
+ <div style={{ display: 'flex', gap: 24 }}>
203
+ <Avatar text="A" badge badgeCount={3} badgeTone="brand" />
204
+ <Avatar text="B" badge badgeCount={3} badgeTone="success" />
205
+ <Avatar text="C" badge badgeCount={3} badgeTone="warning" />
206
+ <Avatar text="D" badge badgeCount={3} badgeTone="alert" />
207
+ </div>
208
+ );
209
+ }
210
+ ```
31
211
 
32
- ## Props
212
+ ## API Reference
33
213
 
34
214
  ### Avatar
35
215
 
216
+ An avatar component for displaying user representation.
217
+
218
+ **Avatar Props:**
219
+
36
220
  | Prop | Type | Default | Description |
37
- |------|------|---------|-------------|
38
- | `src` | `string` | | Image source URL |
39
- | `icon` | `ReactNode` | | Icon shown when no image is provided |
40
- | `text` | `string` | | Initials shown when no image or icon is provided |
41
- | `size` | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Avatar size |
42
- | `square` | `boolean` | `false` | Square shape with small border radius instead of circle |
43
- | `badge` | `boolean` | `false` | Show a notification badge |
44
- | `badgeCount` | `ReactNode` | | Count or label displayed in the badge |
45
- | `badgeTone` | `"primary" \| "secondary" \| "brand" \| "success" \| "warning" \| "alert" \| "neutral"` | `"alert"` | Badge colour tone |
46
- | `stroke` | `boolean` | `false` | Border to separate avatar from adjacent avatars |
47
- | `onClick` | `() => void` | | Click handler |
221
+ | :--- | :--- | :------ | :---------- |
222
+ | src | `string` | - | Image source URL. |
223
+ | icon | `ReactNode` | - | Icon to display when no image. |
224
+ | text | `string` | - | Text/initials when no image or icon. |
225
+ | size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Size of the avatar. |
226
+ | square | `boolean` | `false` | Square with border radius vs circular. |
227
+ | badge | `boolean` | `false` | Show notification badge. |
228
+ | badgeCount | `ReactNode` | - | Badge count or content. |
229
+ | badgeTone | `"primary" \| "secondary" \| "brand" \| "brandExtra" \| "success" \| "warning" \| "alert" \| "neutral"` | - | Badge color tone. |
230
+ | stroke | `boolean` | `false` | Show border around avatar. |
231
+ | backgroundColor | `string` | - | Custom background color. |
232
+ | disableHover | `boolean` | `false` | Disable hover effect. |
233
+ | aria-label | `string` | - | Accessible label. |
234
+ | alt | `string` | - | Alt text for image. |
235
+ | onClick | `() => void` | - | Click handler. |
236
+
237
+ ---
48
238
 
49
239
  ### AvatarGroup
50
240
 
241
+ A component for displaying multiple avatars with overlap.
242
+
243
+ **AvatarGroup Props:**
244
+
51
245
  | Prop | Type | Default | Description |
52
- |------|------|---------|-------------|
53
- | `list` | `AvatarGroupItem[]` | | Avatars to display (`src`, `initials`, `tooltip`, `onClick`) |
54
- | `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of all avatars in the group |
55
- | `maxVisible` | `number` | `6` | Max avatars shown before collapsing into "+N" |
56
- | `stroke` | `boolean` | `true` | Border around each avatar |
57
- | `avatarBackgroundMode` | `"mixed" \| "brand" \| "success" \| "warning" \| "alert" \| "neutral" \| ((theme) => string)` | `"mixed"` | Background colour mode for text/icon avatars |
246
+ | :--- | :--- | :------ | :---------- |
247
+ | list | `AvatarGroupItem[]` | - | **Required.** Array of avatar items. |
248
+ | size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of avatars. |
249
+ | maxVisible | `number` | `6` | Max avatars before "+N" counter. |
250
+ | stroke | `boolean` | `true` | Show borders on avatars. |
251
+ | avatarBackgroundMode | `"mixed" \| ToneString \| Function` | `"mixed"` | Background color mode. |
252
+ | aria-label | `string` | - | Accessible label for the group. |
253
+
254
+ **AvatarGroupItem:**
255
+
256
+ ```typescript
257
+ interface AvatarGroupItem {
258
+ src?: string; // Image URL
259
+ initials?: string; // Text initials
260
+ onClick?: () => void; // Click handler
261
+ tooltip?: string; // Tooltip on hover
262
+ }
263
+ ```
264
+
265
+ ## Theming
266
+
267
+ Avatar uses the design system theme for colors:
268
+
269
+ ```typescript
270
+ // Colors accessed via theme
271
+ theme.colors.background.secondary // Default avatar background
272
+ theme.colors.content.primary // Text/icon color
273
+ theme.colors.border.primary // Stroke color
274
+ ```
275
+
276
+ ## Accessibility
277
+
278
+ - Supports `aria-label` for screen readers
279
+ - `alt` attribute for images
280
+ - Keyboard accessible when clickable (Enter/Space)
281
+ - Focus indicator follows WCAG guidelines
282
+ - Badge count announced to assistive technology
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-avatar",
3
- "version": "0.99.0",
3
+ "version": "0.100.0",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -10,11 +10,11 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-badge": "0.99.0",
14
- "@xsolla/xui-core": "0.99.0",
15
- "@xsolla/xui-icons-base": "0.99.0",
16
- "@xsolla/xui-primitives-core": "0.99.0",
17
- "@xsolla/xui-tooltip": "0.99.0"
13
+ "@xsolla/xui-badge": "0.100.0",
14
+ "@xsolla/xui-core": "0.100.0",
15
+ "@xsolla/xui-icons-base": "0.100.0",
16
+ "@xsolla/xui-primitives-core": "0.100.0",
17
+ "@xsolla/xui-tooltip": "0.100.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "react": ">=16.8.0",