@xsolla/xui-uploader 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 +256 -16
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,36 +1,276 @@
1
- # @xsolla/xui-uploader
1
+ ---
2
+ title: Uploader
3
+ subtitle: File upload component.
4
+ description: A cross-platform React file uploader component with file selection, preview, and management capabilities.
5
+ ---
2
6
 
3
- File upload control with a trigger button and selected file list.
7
+ # Uploader
8
+
9
+ A cross-platform React file uploader component that provides a button to select files, displays selected files, and allows removing them.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-uploader
15
+ # or
8
16
  yarn add @xsolla/xui-uploader
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic Uploader
12
22
 
13
23
  ```tsx
24
+ import * as React from 'react';
25
+ import { Uploader } from '@xsolla/xui-uploader';
26
+
27
+ export default function BasicUploader() {
28
+ return (
29
+ <Uploader
30
+ label="Upload file"
31
+ onFilesChange={(files) => console.log('Selected:', files)}
32
+ />
33
+ );
34
+ }
35
+ ```
36
+
37
+ ### Multiple Files
38
+
39
+ ```tsx
40
+ import * as React from 'react';
41
+ import { Uploader } from '@xsolla/xui-uploader';
42
+
43
+ export default function MultipleFiles() {
44
+ return (
45
+ <Uploader
46
+ label="Upload documents"
47
+ placeholder="Select multiple files"
48
+ multiple
49
+ onFilesChange={(files) => console.log('Files:', files)}
50
+ />
51
+ );
52
+ }
53
+ ```
54
+
55
+ ### Accept Specific Types
56
+
57
+ ```tsx
58
+ import * as React from 'react';
59
+ import { Uploader } from '@xsolla/xui-uploader';
60
+
61
+ export default function ImageUploader() {
62
+ return (
63
+ <Uploader
64
+ label="Upload image"
65
+ placeholder="Select image file"
66
+ accept=".jpg,.jpeg,.png,.gif"
67
+ onFilesChange={(files) => console.log('Images:', files)}
68
+ />
69
+ );
70
+ }
71
+ ```
72
+
73
+ ## Anatomy
74
+
75
+ ```jsx
14
76
  import { Uploader } from '@xsolla/xui-uploader';
15
77
 
16
78
  <Uploader
17
- label="Attachments"
18
- accept=".jpg,.png,.pdf"
19
- multiple
20
- onFilesChange={(files) => console.log(files)}
79
+ label="Label" // Label above button
80
+ placeholder="Select files" // Button text
81
+ accept=".pdf,.doc" // Accepted file types
82
+ multiple={false} // Allow multiple selection
83
+ disabled={false} // Disabled state
84
+ size="md" // Button size
85
+ onFilesChange={handleFiles} // File change callback
21
86
  />
22
87
  ```
23
88
 
24
- ## Props
89
+ ## Examples
90
+
91
+ ### Document Upload
92
+
93
+ ```tsx
94
+ import * as React from 'react';
95
+ import { Uploader } from '@xsolla/xui-uploader';
96
+
97
+ export default function DocumentUpload() {
98
+ const [files, setFiles] = React.useState<File[]>([]);
99
+
100
+ return (
101
+ <div>
102
+ <Uploader
103
+ label="Legal documents"
104
+ placeholder="Upload PDF documents"
105
+ accept=".pdf"
106
+ multiple
107
+ onFilesChange={setFiles}
108
+ />
109
+ {files.length > 0 && (
110
+ <p style={{ marginTop: 8 }}>
111
+ {files.length} file(s) selected
112
+ </p>
113
+ )}
114
+ </div>
115
+ );
116
+ }
117
+ ```
118
+
119
+ ### Profile Image Upload
120
+
121
+ ```tsx
122
+ import * as React from 'react';
123
+ import { Uploader } from '@xsolla/xui-uploader';
124
+
125
+ export default function ProfileImageUpload() {
126
+ const handleImageUpload = (files: File[]) => {
127
+ if (files.length > 0) {
128
+ const file = files[0];
129
+ // Create preview URL
130
+ const previewUrl = URL.createObjectURL(file);
131
+ console.log('Preview:', previewUrl);
132
+ }
133
+ };
134
+
135
+ return (
136
+ <div style={{ maxWidth: 300 }}>
137
+ <Uploader
138
+ label="Profile picture"
139
+ placeholder="Choose image"
140
+ accept="image/*"
141
+ onFilesChange={handleImageUpload}
142
+ size="sm"
143
+ />
144
+ <p style={{ fontSize: 12, color: '#666', marginTop: 4 }}>
145
+ Recommended: Square image, at least 200x200px
146
+ </p>
147
+ </div>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### Form with File Upload
153
+
154
+ ```tsx
155
+ import * as React from 'react';
156
+ import { Uploader } from '@xsolla/xui-uploader';
157
+ import { Input } from '@xsolla/xui-input';
158
+ import { Textarea } from '@xsolla/xui-textarea';
159
+ import { Button } from '@xsolla/xui-button';
160
+
161
+ export default function FormWithUpload() {
162
+ const [files, setFiles] = React.useState<File[]>([]);
163
+
164
+ const handleSubmit = () => {
165
+ const formData = new FormData();
166
+ files.forEach((file) => formData.append('attachments', file));
167
+ console.log('Submitting with', files.length, 'files');
168
+ };
169
+
170
+ return (
171
+ <form
172
+ style={{ display: 'flex', flexDirection: 'column', gap: 16, maxWidth: 400 }}
173
+ onSubmit={(e) => { e.preventDefault(); handleSubmit(); }}
174
+ >
175
+ <Input label="Subject" placeholder="Enter subject" />
176
+ <Textarea label="Message" placeholder="Enter your message" />
177
+ <Uploader
178
+ label="Attachments"
179
+ placeholder="Add attachments"
180
+ multiple
181
+ onFilesChange={setFiles}
182
+ />
183
+ <Button type="submit">Submit</Button>
184
+ </form>
185
+ );
186
+ }
187
+ ```
188
+
189
+ ### Different Sizes
190
+
191
+ ```tsx
192
+ import * as React from 'react';
193
+ import { Uploader } from '@xsolla/xui-uploader';
194
+
195
+ export default function UploaderSizes() {
196
+ return (
197
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
198
+ <Uploader size="xs" placeholder="Extra small" />
199
+ <Uploader size="sm" placeholder="Small" />
200
+ <Uploader size="md" placeholder="Medium" />
201
+ <Uploader size="lg" placeholder="Large" />
202
+ <Uploader size="xl" placeholder="Extra large" />
203
+ </div>
204
+ );
205
+ }
206
+ ```
207
+
208
+ ### Disabled State
209
+
210
+ ```tsx
211
+ import * as React from 'react';
212
+ import { Uploader } from '@xsolla/xui-uploader';
213
+
214
+ export default function DisabledUploader() {
215
+ return (
216
+ <Uploader
217
+ label="Upload (disabled)"
218
+ placeholder="Cannot upload files"
219
+ disabled
220
+ />
221
+ );
222
+ }
223
+ ```
224
+
225
+ ## API Reference
25
226
 
26
227
  ### Uploader
27
228
 
229
+ **UploaderProps:**
230
+
28
231
  | Prop | Type | Default | Description |
29
- |------|------|---------|-------------|
30
- | `label` | `string` | | Label rendered above the upload button |
31
- | `placeholder` | `string` | `"Select files to upload"` | Button text when no files are selected |
32
- | `accept` | `string` | | Accepted file types (e.g. `".jpg,.png"`) |
33
- | `multiple` | `boolean` | `false` | Allow selecting multiple files |
34
- | `onFilesChange` | `(files: File[]) => void` | | Callback fired when the file list changes |
35
- | `disabled` | `boolean` | `false` | Disables the control |
36
- | `size` | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Size of the upload button |
232
+ | :--- | :--- | :------ | :---------- |
233
+ | label | `string` | - | Label text above the button. |
234
+ | placeholder | `string` | `"Select files to upload"` | Button text. |
235
+ | accept | `string` | - | Accepted file types (e.g., ".jpg,.png"). |
236
+ | multiple | `boolean` | `false` | Allow multiple file selection. |
237
+ | disabled | `boolean` | `false` | Disabled state. |
238
+ | size | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Button size. |
239
+ | onFilesChange | `(files: File[]) => void` | - | Callback when files change. |
240
+
241
+ ## File List Display
242
+
243
+ When files are selected, they appear below the button with:
244
+
245
+ - File icon
246
+ - File name (truncated if too long)
247
+ - Remove button (X icon)
248
+
249
+ Removing a file updates the list and calls `onFilesChange` with the updated array.
250
+
251
+ ## Accept Patterns
252
+
253
+ | Pattern | Description |
254
+ | :------ | :---------- |
255
+ | `.pdf` | PDF files only |
256
+ | `.jpg,.jpeg,.png` | Specific image formats |
257
+ | `image/*` | All image types |
258
+ | `video/*` | All video types |
259
+ | `.doc,.docx,.pdf` | Multiple document types |
260
+
261
+ ## Behavior
262
+
263
+ - Click button to open native file picker
264
+ - Multiple selection when `multiple` is true
265
+ - Files accumulate when `multiple` is true (new selections add to existing)
266
+ - Files replace when `multiple` is false
267
+ - Each file can be removed individually
268
+ - Hidden native input, styled button
269
+
270
+ ## Accessibility
271
+
272
+ - Button is keyboard accessible
273
+ - File input is properly associated with the button
274
+ - Remove buttons have appropriate labels
275
+ - Disabled state prevents interaction
276
+ - File list is accessible to screen readers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-uploader",
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,10 +10,10 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-button": "0.99.0",
14
- "@xsolla/xui-core": "0.99.0",
15
- "@xsolla/xui-icons": "0.99.0",
16
- "@xsolla/xui-primitives-core": "0.99.0"
13
+ "@xsolla/xui-button": "0.100.0",
14
+ "@xsolla/xui-core": "0.100.0",
15
+ "@xsolla/xui-icons": "0.100.0",
16
+ "@xsolla/xui-primitives-core": "0.100.0"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": ">=16.8.0"