@xsolla/xui-badge 0.99.0 → 0.101.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/README.md +239 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,31 +1,257 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Badge
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A cross-platform React badge component for displaying counts, status indicators, and small labels. Supports multiple sizes and color tones.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install @xsolla/xui-badge
|
|
9
|
+
# or
|
|
8
10
|
yarn add @xsolla/xui-badge
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Demo
|
|
14
|
+
|
|
15
|
+
### Basic Badge
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
20
|
+
|
|
21
|
+
export default function BasicBadge() {
|
|
22
|
+
return (
|
|
23
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
24
|
+
<Badge>5</Badge>
|
|
25
|
+
<Badge>99+</Badge>
|
|
26
|
+
<Badge>New</Badge>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Badge Tones
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import * as React from 'react';
|
|
36
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
37
|
+
|
|
38
|
+
export default function BadgeTones() {
|
|
39
|
+
return (
|
|
40
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
41
|
+
<Badge tone="primary">Primary</Badge>
|
|
42
|
+
<Badge tone="secondary">Secondary</Badge>
|
|
43
|
+
<Badge tone="brand">Brand</Badge>
|
|
44
|
+
<Badge tone="brandExtra">Extra</Badge>
|
|
45
|
+
<Badge tone="success">Success</Badge>
|
|
46
|
+
<Badge tone="warning">Warning</Badge>
|
|
47
|
+
<Badge tone="alert">Alert</Badge>
|
|
48
|
+
<Badge tone="neutral">Neutral</Badge>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Badge Sizes
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import * as React from 'react';
|
|
58
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
59
|
+
|
|
60
|
+
export default function BadgeSizes() {
|
|
61
|
+
return (
|
|
62
|
+
<div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
|
|
63
|
+
<Badge size="xs" tone="alert" /> {/* Dot only */}
|
|
64
|
+
<Badge size="sm" tone="alert" /> {/* Dot only */}
|
|
65
|
+
<Badge size="md" tone="alert">5</Badge>
|
|
66
|
+
<Badge size="lg" tone="alert">5</Badge>
|
|
67
|
+
<Badge size="xl" tone="alert">5</Badge>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Badge with Icon
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import * as React from 'react';
|
|
77
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
78
|
+
import { Check, AlertCircle } from '@xsolla/xui-icons';
|
|
79
|
+
import { Star } from '@xsolla/xui-icons-base';
|
|
80
|
+
|
|
81
|
+
export default function BadgeWithIcon() {
|
|
82
|
+
return (
|
|
83
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
84
|
+
<Badge icon={<Star size={12} />} tone="warning">Featured</Badge>
|
|
85
|
+
<Badge icon={<Check size={12} />} tone="success">Verified</Badge>
|
|
86
|
+
<Badge icon={<AlertCircle size={12} />} tone="alert">Error</Badge>
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Dot Badge (Status Indicator)
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import * as React from 'react';
|
|
96
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
97
|
+
|
|
98
|
+
export default function DotBadge() {
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
|
|
101
|
+
<span>Online</span>
|
|
102
|
+
<Badge size="xs" tone="success" />
|
|
103
|
+
|
|
104
|
+
<span>Away</span>
|
|
105
|
+
<Badge size="xs" tone="warning" />
|
|
106
|
+
|
|
107
|
+
<span>Busy</span>
|
|
108
|
+
<Badge size="xs" tone="alert" />
|
|
109
|
+
|
|
110
|
+
<span>Offline</span>
|
|
111
|
+
<Badge size="xs" tone="neutral" />
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Anatomy
|
|
118
|
+
|
|
119
|
+
Import the component and use it directly:
|
|
120
|
+
|
|
121
|
+
```jsx
|
|
122
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
123
|
+
|
|
124
|
+
<Badge
|
|
125
|
+
size="md" // Size variant (xs/s are dots only)
|
|
126
|
+
tone="alert" // Color tone
|
|
127
|
+
icon={<Icon />} // Optional icon
|
|
128
|
+
showStroke={false} // Show border
|
|
129
|
+
>
|
|
130
|
+
Content
|
|
131
|
+
</Badge>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Examples
|
|
135
|
+
|
|
136
|
+
### Notification Count
|
|
12
137
|
|
|
13
138
|
```tsx
|
|
14
|
-
import
|
|
139
|
+
import * as React from 'react';
|
|
140
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
141
|
+
import { Bell } from '@xsolla/xui-icons';
|
|
15
142
|
|
|
16
|
-
|
|
143
|
+
export default function NotificationBadge() {
|
|
144
|
+
const count = 12;
|
|
17
145
|
|
|
18
|
-
|
|
19
|
-
<
|
|
146
|
+
return (
|
|
147
|
+
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
148
|
+
<Bell size={24} />
|
|
149
|
+
<div style={{ position: 'absolute', top: -8, right: -8 }}>
|
|
150
|
+
<Badge tone="alert" size="md">
|
|
151
|
+
{count > 99 ? '99+' : count}
|
|
152
|
+
</Badge>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
20
157
|
```
|
|
21
158
|
|
|
22
|
-
|
|
159
|
+
### Badge with Stroke
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import * as React from 'react';
|
|
163
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
164
|
+
|
|
165
|
+
export default function BadgeWithStroke() {
|
|
166
|
+
return (
|
|
167
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
168
|
+
<Badge tone="brand" showStroke>Pro</Badge>
|
|
169
|
+
<Badge tone="success" showStroke>Active</Badge>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Status Labels
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import * as React from 'react';
|
|
179
|
+
import { Badge } from '@xsolla/xui-badge';
|
|
180
|
+
|
|
181
|
+
export default function StatusLabels() {
|
|
182
|
+
const statuses = [
|
|
183
|
+
{ label: 'Published', tone: 'success' as const },
|
|
184
|
+
{ label: 'Draft', tone: 'neutral' as const },
|
|
185
|
+
{ label: 'Pending', tone: 'warning' as const },
|
|
186
|
+
{ label: 'Rejected', tone: 'alert' as const },
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<div style={{ display: 'flex', gap: 12 }}>
|
|
191
|
+
{statuses.map((status) => (
|
|
192
|
+
<Badge key={status.label} tone={status.tone} size="md">
|
|
193
|
+
{status.label}
|
|
194
|
+
</Badge>
|
|
195
|
+
))}
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## API Reference
|
|
23
202
|
|
|
24
203
|
### Badge
|
|
25
204
|
|
|
205
|
+
A badge component for counts and status indicators.
|
|
206
|
+
|
|
207
|
+
**Badge Props:**
|
|
208
|
+
|
|
26
209
|
| Prop | Type | Default | Description |
|
|
27
|
-
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
210
|
+
| :--- | :--- | :------ | :---------- |
|
|
211
|
+
| children | `ReactNode` | - | Badge content (ignored for xs/s sizes). |
|
|
212
|
+
| icon | `ReactNode` | - | Icon to display. |
|
|
213
|
+
| size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Size of the badge. |
|
|
214
|
+
| tone | `"primary" \| "secondary" \| "brand" \| "brandExtra" \| "success" \| "warning" \| "alert" \| "neutral"` | `"alert"` | Color tone. |
|
|
215
|
+
| showStroke | `boolean` | `false` | Show border around badge. |
|
|
216
|
+
| aria-label | `string` | - | Accessible label. |
|
|
217
|
+
| aria-hidden | `boolean` | - | Hide from screen readers. |
|
|
218
|
+
|
|
219
|
+
**Size Behavior:**
|
|
220
|
+
|
|
221
|
+
| Size | Behavior |
|
|
222
|
+
| :--- | :------- |
|
|
223
|
+
| xs | Dot only (8px), no content |
|
|
224
|
+
| sm | Dot only (12px), no content |
|
|
225
|
+
| md | Supports content (20px height) |
|
|
226
|
+
| lg | Supports content (24px height) |
|
|
227
|
+
| xl | Supports content (28px height) |
|
|
228
|
+
|
|
229
|
+
**Tone Color Mapping:**
|
|
230
|
+
|
|
231
|
+
| Tone | Background | Text |
|
|
232
|
+
| :--- | :--------- | :--- |
|
|
233
|
+
| primary | Background primary | Content primary |
|
|
234
|
+
| secondary | Background secondary | Content primary |
|
|
235
|
+
| brand | Brand primary | On brand |
|
|
236
|
+
| brandExtra | BrandExtra primary | On brandExtra |
|
|
237
|
+
| success | Success primary | On success |
|
|
238
|
+
| warning | Warning primary | On warning |
|
|
239
|
+
| alert | Alert primary | On alert |
|
|
240
|
+
| neutral | Neutral primary | On neutral |
|
|
241
|
+
|
|
242
|
+
## Theming
|
|
243
|
+
|
|
244
|
+
Badge uses the design system theme for colors:
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// Colors accessed via theme (example for "alert" tone)
|
|
248
|
+
theme.colors.background.alert.primary // Background
|
|
249
|
+
theme.colors.content.onAlert // Text color
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Accessibility
|
|
253
|
+
|
|
254
|
+
- Uses `role="status"` for proper semantics
|
|
255
|
+
- Dot badges without labels use `aria-hidden` by default
|
|
256
|
+
- Supports custom `aria-label` for screen readers
|
|
257
|
+
- Text content is automatically announced
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-badge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"test:coverage": "vitest run --coverage"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@xsolla/xui-core": "0.
|
|
18
|
-
"@xsolla/xui-primitives-core": "0.
|
|
17
|
+
"@xsolla/xui-core": "0.101.0",
|
|
18
|
+
"@xsolla/xui-primitives-core": "0.101.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=16.8.0",
|