@mehdashti/forms 0.6.3 → 1.0.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/dist/index.d.ts +263 -6
- package/dist/index.js +329 -19
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as react_hook_form from 'react-hook-form';
|
|
2
2
|
import { FieldValues, DefaultValues, Path, UseFormReturn, Control, ArrayPath, FieldErrors } from 'react-hook-form';
|
|
3
3
|
export { FieldErrors, FieldValues, Path, PathValue } from 'react-hook-form';
|
|
4
|
-
import { ZodTypeAny, z } from 'zod';
|
|
5
|
-
export { z } from 'zod';
|
|
6
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
5
|
import { InputProps } from '@mehdashti/ui';
|
|
8
6
|
import * as React$1 from 'react';
|
|
7
|
+
import { z, ZodTypeAny } from 'zod';
|
|
8
|
+
export { z } from 'zod';
|
|
9
9
|
|
|
10
10
|
interface SmartFormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
11
|
-
schema:
|
|
11
|
+
schema: any;
|
|
12
12
|
onSubmit: (data: TFieldValues) => void | Promise<void>;
|
|
13
13
|
onError?: (errors: Record<string, unknown>) => void;
|
|
14
14
|
realtimeValidation?: boolean;
|
|
@@ -311,8 +311,172 @@ interface FormErrorSummaryProps {
|
|
|
311
311
|
* Callback when an error link is clicked
|
|
312
312
|
*/
|
|
313
313
|
onErrorClick?: (fieldName: string) => void;
|
|
314
|
+
/**
|
|
315
|
+
* Show error count badge
|
|
316
|
+
* @default true
|
|
317
|
+
*/
|
|
318
|
+
showErrorCount?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Auto-scroll to first error on mount
|
|
321
|
+
* @default false
|
|
322
|
+
*/
|
|
323
|
+
autoScrollToFirstError?: boolean;
|
|
324
|
+
}
|
|
325
|
+
declare function FormErrorSummary({ title, fieldLabels, show, className, onErrorClick, showErrorCount, autoScrollToFirstError, }: FormErrorSummaryProps): react_jsx_runtime.JSX.Element | null;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* FormFieldError Component
|
|
329
|
+
*
|
|
330
|
+
* Displays error icon and message for form fields.
|
|
331
|
+
*/
|
|
332
|
+
interface FormFieldErrorProps {
|
|
333
|
+
/**
|
|
334
|
+
* Error message to display
|
|
335
|
+
*/
|
|
336
|
+
message?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Show error icon
|
|
339
|
+
* @default true
|
|
340
|
+
*/
|
|
341
|
+
showIcon?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* Custom className
|
|
344
|
+
*/
|
|
345
|
+
className?: string;
|
|
346
|
+
/**
|
|
347
|
+
* Field ID for accessibility
|
|
348
|
+
*/
|
|
349
|
+
fieldId?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* FormFieldError - Displays error icon and message
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```tsx
|
|
356
|
+
* <FormFieldError message={errors.email?.message} fieldId="email" />
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
declare function FormFieldError({ message, showIcon, className, fieldId, }: FormFieldErrorProps): react_jsx_runtime.JSX.Element | null;
|
|
360
|
+
declare namespace FormFieldError {
|
|
361
|
+
var displayName: string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* useAutosave Hook
|
|
366
|
+
*
|
|
367
|
+
* Provides debounced autosave functionality for forms with save state indicators.
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
type SaveStatus = "idle" | "saving" | "saved" | "error";
|
|
371
|
+
interface UseAutosaveOptions<TData> {
|
|
372
|
+
/**
|
|
373
|
+
* Function to save the form data
|
|
374
|
+
*/
|
|
375
|
+
onSave: (data: TData) => Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Debounce delay in milliseconds
|
|
378
|
+
* @default 2000
|
|
379
|
+
*/
|
|
380
|
+
debounceMs?: number;
|
|
381
|
+
/**
|
|
382
|
+
* Whether autosave is enabled
|
|
383
|
+
* @default true
|
|
384
|
+
*/
|
|
385
|
+
enabled?: boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Callback when save succeeds
|
|
388
|
+
*/
|
|
389
|
+
onSaveSuccess?: (data: TData) => void;
|
|
390
|
+
/**
|
|
391
|
+
* Callback when save fails
|
|
392
|
+
*/
|
|
393
|
+
onSaveError?: (error: Error, data: TData) => void;
|
|
394
|
+
/**
|
|
395
|
+
* Fields to exclude from triggering autosave
|
|
396
|
+
*/
|
|
397
|
+
excludeFields?: string[];
|
|
398
|
+
}
|
|
399
|
+
interface UseAutosaveReturn {
|
|
400
|
+
/**
|
|
401
|
+
* Current save status
|
|
402
|
+
*/
|
|
403
|
+
status: SaveStatus;
|
|
404
|
+
/**
|
|
405
|
+
* Last save timestamp
|
|
406
|
+
*/
|
|
407
|
+
lastSaved: Date | null;
|
|
408
|
+
/**
|
|
409
|
+
* Error from last save attempt
|
|
410
|
+
*/
|
|
411
|
+
error: Error | null;
|
|
412
|
+
/**
|
|
413
|
+
* Manually trigger save
|
|
414
|
+
*/
|
|
415
|
+
save: () => Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Reset save status
|
|
418
|
+
*/
|
|
419
|
+
reset: () => void;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Hook for autosaving form data with debouncing
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```tsx
|
|
426
|
+
* const form = useSmartForm({ ... });
|
|
427
|
+
* const autosave = useAutosave({
|
|
428
|
+
* onSave: async (data) => {
|
|
429
|
+
* await api.saveDraft(data);
|
|
430
|
+
* },
|
|
431
|
+
* debounceMs: 2000,
|
|
432
|
+
* });
|
|
433
|
+
*
|
|
434
|
+
* return (
|
|
435
|
+
* <FormProvider {...form}>
|
|
436
|
+
* <AutosaveIndicator status={autosave.status} lastSaved={autosave.lastSaved} />
|
|
437
|
+
* <form>...</form>
|
|
438
|
+
* </FormProvider>
|
|
439
|
+
* );
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare function useAutosave<TData extends FieldValues = any>({ onSave, debounceMs, enabled, onSaveSuccess, onSaveError, excludeFields, }: UseAutosaveOptions<TData>): UseAutosaveReturn;
|
|
443
|
+
|
|
444
|
+
interface AutosaveIndicatorProps {
|
|
445
|
+
/**
|
|
446
|
+
* Current save status
|
|
447
|
+
*/
|
|
448
|
+
status: SaveStatus;
|
|
449
|
+
/**
|
|
450
|
+
* Last save timestamp
|
|
451
|
+
*/
|
|
452
|
+
lastSaved?: Date | null;
|
|
453
|
+
/**
|
|
454
|
+
* Custom className
|
|
455
|
+
*/
|
|
456
|
+
className?: string;
|
|
457
|
+
/**
|
|
458
|
+
* Show timestamp
|
|
459
|
+
* @default true
|
|
460
|
+
*/
|
|
461
|
+
showTimestamp?: boolean;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* AutosaveIndicator - Visual indicator for autosave status
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```tsx
|
|
468
|
+
* const autosave = useAutosave({ ... });
|
|
469
|
+
*
|
|
470
|
+
* <AutosaveIndicator
|
|
471
|
+
* status={autosave.status}
|
|
472
|
+
* lastSaved={autosave.lastSaved}
|
|
473
|
+
* />
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function AutosaveIndicator({ status, lastSaved, className, showTimestamp, }: AutosaveIndicatorProps): react_jsx_runtime.JSX.Element | null;
|
|
477
|
+
declare namespace AutosaveIndicator {
|
|
478
|
+
var displayName: string;
|
|
314
479
|
}
|
|
315
|
-
declare function FormErrorSummary({ title, fieldLabels, show, className, onErrorClick, }: FormErrorSummaryProps): react_jsx_runtime.JSX.Element | null;
|
|
316
480
|
|
|
317
481
|
/**
|
|
318
482
|
* Form field component props
|
|
@@ -587,6 +751,24 @@ interface FormSectionProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
|
587
751
|
* @default "md"
|
|
588
752
|
*/
|
|
589
753
|
spacing?: 'sm' | 'md' | 'lg';
|
|
754
|
+
/**
|
|
755
|
+
* Make the section collapsible
|
|
756
|
+
* @default false
|
|
757
|
+
*/
|
|
758
|
+
collapsible?: boolean;
|
|
759
|
+
/**
|
|
760
|
+
* Initial collapsed state (only works when collapsible is true)
|
|
761
|
+
* @default false
|
|
762
|
+
*/
|
|
763
|
+
defaultCollapsed?: boolean;
|
|
764
|
+
/**
|
|
765
|
+
* Controlled collapsed state
|
|
766
|
+
*/
|
|
767
|
+
collapsed?: boolean;
|
|
768
|
+
/**
|
|
769
|
+
* Callback when collapsed state changes
|
|
770
|
+
*/
|
|
771
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
590
772
|
}
|
|
591
773
|
/**
|
|
592
774
|
* FormSection - Section with title and grid layout
|
|
@@ -598,12 +780,87 @@ interface FormSectionProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
|
598
780
|
* <FormField name="email" label="Email" control={form.control} />
|
|
599
781
|
* </FormSection>
|
|
600
782
|
* ```
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* ```tsx
|
|
786
|
+
* <FormSection
|
|
787
|
+
* title="Advanced Settings"
|
|
788
|
+
* collapsible
|
|
789
|
+
* defaultCollapsed
|
|
790
|
+
* >
|
|
791
|
+
* <FormField name="apiKey" label="API Key" control={form.control} />
|
|
792
|
+
* </FormSection>
|
|
793
|
+
* ```
|
|
601
794
|
*/
|
|
602
|
-
declare function FormSection({ title, description, columns, spacing, className, children, ...props }: FormSectionProps): react_jsx_runtime.JSX.Element;
|
|
795
|
+
declare function FormSection({ title, description, columns, spacing, className, children, collapsible, defaultCollapsed, collapsed: controlledCollapsed, onCollapsedChange, ...props }: FormSectionProps): react_jsx_runtime.JSX.Element;
|
|
603
796
|
declare namespace FormSection {
|
|
604
797
|
var displayName: string;
|
|
605
798
|
}
|
|
606
799
|
|
|
800
|
+
interface FormFieldGroupProps extends React$1.HTMLAttributes<HTMLFieldSetElement> {
|
|
801
|
+
/**
|
|
802
|
+
* Group label (rendered as legend)
|
|
803
|
+
*/
|
|
804
|
+
label?: string;
|
|
805
|
+
/**
|
|
806
|
+
* Group description
|
|
807
|
+
*/
|
|
808
|
+
description?: string;
|
|
809
|
+
/**
|
|
810
|
+
* Number of columns for fields in this group
|
|
811
|
+
* @default 1
|
|
812
|
+
*/
|
|
813
|
+
columns?: 1 | 2 | 3 | 4;
|
|
814
|
+
/**
|
|
815
|
+
* Spacing between fields
|
|
816
|
+
* @default "md"
|
|
817
|
+
*/
|
|
818
|
+
spacing?: 'sm' | 'md' | 'lg';
|
|
819
|
+
/**
|
|
820
|
+
* Visual variant
|
|
821
|
+
* @default "default"
|
|
822
|
+
*/
|
|
823
|
+
variant?: 'default' | 'bordered' | 'outlined';
|
|
824
|
+
/**
|
|
825
|
+
* Whether the group is disabled
|
|
826
|
+
*/
|
|
827
|
+
disabled?: boolean;
|
|
828
|
+
/**
|
|
829
|
+
* Whether the group is required (shows * on label)
|
|
830
|
+
*/
|
|
831
|
+
required?: boolean;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* FormFieldGroup - Semantic grouping of related form fields
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```tsx
|
|
838
|
+
* <FormFieldGroup label="Shipping Address" columns={2}>
|
|
839
|
+
* <FormField name="street" label="Street" control={form.control} />
|
|
840
|
+
* <FormField name="city" label="City" control={form.control} />
|
|
841
|
+
* <FormField name="state" label="State" control={form.control} />
|
|
842
|
+
* <FormField name="zip" label="ZIP Code" control={form.control} />
|
|
843
|
+
* </FormFieldGroup>
|
|
844
|
+
* ```
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```tsx
|
|
848
|
+
* <FormFieldGroup
|
|
849
|
+
* label="Contact Information"
|
|
850
|
+
* description="How can we reach you?"
|
|
851
|
+
* variant="bordered"
|
|
852
|
+
* required
|
|
853
|
+
* >
|
|
854
|
+
* <FormField name="email" label="Email" control={form.control} />
|
|
855
|
+
* <FormField name="phone" label="Phone" control={form.control} />
|
|
856
|
+
* </FormFieldGroup>
|
|
857
|
+
* ```
|
|
858
|
+
*/
|
|
859
|
+
declare function FormFieldGroup({ label, description, columns, spacing, variant, disabled, required, className, children, ...props }: FormFieldGroupProps): react_jsx_runtime.JSX.Element;
|
|
860
|
+
declare namespace FormFieldGroup {
|
|
861
|
+
var displayName: string;
|
|
862
|
+
}
|
|
863
|
+
|
|
607
864
|
interface FormGridProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
608
865
|
/**
|
|
609
866
|
* Spacing between items
|
|
@@ -1066,4 +1323,4 @@ declare function validateFileExtension(filename: string, allowedExtensions: stri
|
|
|
1066
1323
|
*/
|
|
1067
1324
|
declare function formatValidationError(error: z.ZodError): Record<string, string>;
|
|
1068
1325
|
|
|
1069
|
-
export { type BlockerState, type FieldArrayOptions, FormCheckbox, type FormCheckboxProps, FormCheckbox$1 as FormCheckboxUI, type FormCheckboxProps$1 as FormCheckboxUIProps, FormDatePicker, type FormDatePickerProps, FormErrorSummary, type FormErrorSummaryProps, FormField, type FormFieldProps, FormFileUpload, type FormFileUploadProps, FormGrid, FormGridItem, type FormGridItemProps, type FormGridProps, FormInput, type FormInputProps, FormLayout, type FormLayoutProps, FormMultiSelect, type FormMultiSelectProps, FormRadioGroup, type FormRadioGroupProps, FormSection, type FormSectionProps, FormSelect, type FormSelectOption, type FormSelectProps, FormSelect$1 as FormSelectUI, type FormSelectProps$1 as FormSelectUIProps, FormSwitch, type FormSwitchProps, FormTagInput, type FormTagInputProps, FormTextarea, type FormTextareaProps, FormTextarea$1 as FormTextareaUI, type FormTextareaProps$1 as FormTextareaUIProps, FormWizard, type FormWizardProps, type FormWizardStep, type MultiSelectOption, type RadioOption, type SelectOption, type SmartFormOptions, type SmartFormReturn, type UseUnsavedChangesBlockerOptions, type UseUnsavedChangesOptions, conditionalSchema, createConfirmPasswordSchema, createFileSizeSchema, createFileTypeSchema, dateStringSchema, emailSchema, formatValidationError, futureDateSchema, getAllErrors, getErrorMessage, hasError, imageFileSchema, invalidFormatMessage, lengthMessage, optionalEmailSchema, optionalUrlSchema, passwordSchema, pastDateSchema, percentageSchema, phoneSchema, positiveIntegerSchema, positiveNumberSchema, priceSchema, requiredMessage, sanitizeString, slugSchema, strongPasswordSchema, urlSchema, useSmartFieldArray, useSmartForm, useUnsavedChanges, useUnsavedChangesBlocker, useUnsavedChangesBlockerReactRouter, useUnsavedChangesBlockerTanStack, usernameSchema, validateCreditCard, validateFileExtension, validateIBAN, validatePasswordStrength };
|
|
1326
|
+
export { AutosaveIndicator, type AutosaveIndicatorProps, type BlockerState, type FieldArrayOptions, FormCheckbox, type FormCheckboxProps, FormCheckbox$1 as FormCheckboxUI, type FormCheckboxProps$1 as FormCheckboxUIProps, FormDatePicker, type FormDatePickerProps, FormErrorSummary, type FormErrorSummaryProps, FormField, FormFieldError, type FormFieldErrorProps, FormFieldGroup, type FormFieldGroupProps, type FormFieldProps, FormFileUpload, type FormFileUploadProps, FormGrid, FormGridItem, type FormGridItemProps, type FormGridProps, FormInput, type FormInputProps, FormLayout, type FormLayoutProps, FormMultiSelect, type FormMultiSelectProps, FormRadioGroup, type FormRadioGroupProps, FormSection, type FormSectionProps, FormSelect, type FormSelectOption, type FormSelectProps, FormSelect$1 as FormSelectUI, type FormSelectProps$1 as FormSelectUIProps, FormSwitch, type FormSwitchProps, FormTagInput, type FormTagInputProps, FormTextarea, type FormTextareaProps, FormTextarea$1 as FormTextareaUI, type FormTextareaProps$1 as FormTextareaUIProps, FormWizard, type FormWizardProps, type FormWizardStep, type MultiSelectOption, type RadioOption, type SaveStatus, type SelectOption, type SmartFormOptions, type SmartFormReturn, type UseAutosaveOptions, type UseAutosaveReturn, type UseUnsavedChangesBlockerOptions, type UseUnsavedChangesOptions, conditionalSchema, createConfirmPasswordSchema, createFileSizeSchema, createFileTypeSchema, dateStringSchema, emailSchema, formatValidationError, futureDateSchema, getAllErrors, getErrorMessage, hasError, imageFileSchema, invalidFormatMessage, lengthMessage, optionalEmailSchema, optionalUrlSchema, passwordSchema, pastDateSchema, percentageSchema, phoneSchema, positiveIntegerSchema, positiveNumberSchema, priceSchema, requiredMessage, sanitizeString, slugSchema, strongPasswordSchema, urlSchema, useAutosave, useSmartFieldArray, useSmartForm, useUnsavedChanges, useUnsavedChangesBlocker, useUnsavedChangesBlockerReactRouter, useUnsavedChangesBlockerTanStack, usernameSchema, validateCreditCard, validateFileExtension, validateIBAN, validatePasswordStrength };
|