@undefine-ui/design-system 3.8.7 → 3.9.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 CHANGED
@@ -312,6 +312,82 @@ toast.promise(fetchData(), {
312
312
  - **Dark themed:** Consistent dark background with themed icons
313
313
  - **Positioned:** Top-right with expandable queue
314
314
 
315
+ ### File Upload (React Hook Form)
316
+
317
+ Form-ready file upload component integrated with React Hook Form. Supports single and multiple file uploads with automatic form state management, deduplication, and lifecycle callbacks.
318
+
319
+ **Usage:**
320
+
321
+ ```tsx
322
+ import { Form, Field } from '@undefine-ui/design-system';
323
+ import { useForm } from 'react-hook-form';
324
+
325
+ const MyForm = () => {
326
+ const methods = useForm({
327
+ defaultValues: {
328
+ avatar: null,
329
+ documents: []
330
+ }
331
+ });
332
+
333
+ return (
334
+ <Form methods={methods} onSubmit={(data) => console.log(data)}>
335
+ {/* Single file upload */}
336
+ <Field.Upload name="avatar" helperText="Upload your profile picture" />
337
+
338
+ {/* Multiple files upload */}
339
+ <Field.Upload name="documents" multiple helperText="Upload multiple documents" />
340
+
341
+ {/* With lifecycle callbacks */}
342
+ <Field.Upload
343
+ name="photos"
344
+ multiple
345
+ onDropComplete={(files) => toast.success(`${files.length} files added`)}
346
+ onRemoveComplete={(file) => console.log('Removed:', file)}
347
+ onRemoveAllComplete={() => toast.info('All files cleared')}
348
+ />
349
+
350
+ {/* Custom accept types */}
351
+ <Field.Upload
352
+ name="resume"
353
+ accept={{
354
+ 'application/pdf': ['.pdf'],
355
+ 'application/msword': ['.doc', '.docx']
356
+ }}
357
+ helperText="PDF or Word documents only"
358
+ />
359
+ </Form>
360
+ );
361
+ };
362
+ ```
363
+
364
+ **Props:**
365
+
366
+ - `name` - Form field name for react-hook-form (required)
367
+ - `multiple` - Enable multiple file selection (default: `false`)
368
+ - `helperText` - Helper text displayed below the upload area
369
+ - `accept` - Accepted file types object (e.g., `{ 'image/*': [] }`)
370
+ - `maxSize` - Maximum file size in bytes
371
+ - `maxFiles` - Maximum number of files (for multiple mode)
372
+ - `disabled` - Disable the upload area
373
+
374
+ **Lifecycle Callbacks:**
375
+
376
+ These callbacks are called **after** the internal form state is updated, allowing you to add side effects like notifications, analytics, or logging without breaking form integration:
377
+
378
+ - `onDropComplete` - Called after files are added to form state `(files: File[]) => void`
379
+ - `onDeleteComplete` - Called after a file is deleted from form state (single mode) `() => void`
380
+ - `onRemoveComplete` - Called after a file is removed from form state (multiple mode) `(file: File | string) => void`
381
+ - `onRemoveAllComplete` - Called after all files are removed from form state (multiple mode) `() => void`
382
+
383
+ **Features:**
384
+
385
+ - **Form integration:** Automatically syncs with react-hook-form state
386
+ - **Validation:** Displays validation errors from react-hook-form
387
+ - **Deduplication:** Prevents adding duplicate files in multiple mode
388
+ - **Safe callbacks:** Lifecycle callbacks extend (not override) internal form logic
389
+ - **Full control:** Use the base `Upload` component directly if you need to override behavior
390
+
315
391
  ### Date Pickers (React Hook Form)
316
392
 
317
393
  Form-ready date picker components integrated with React Hook Form. Includes `RHFDatePicker`, `RHFTimePicker`, and `RHFDateTimePicker` for seamless form state management.