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