@mehdashti/forms 0.3.1 → 0.4.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/dist/index.d.ts +224 -1
- package/dist/index.js +467 -7
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
package/dist/index.d.ts
CHANGED
|
@@ -261,6 +261,158 @@ interface FormMultiSelectProps<TFieldValues extends FieldValues = FieldValues> {
|
|
|
261
261
|
*/
|
|
262
262
|
declare function FormMultiSelect<TFieldValues extends FieldValues = FieldValues>({ name, label, options, required, helpText, disabled, className, control, layout, maxSelection, }: FormMultiSelectProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
263
263
|
|
|
264
|
+
interface RadioOption {
|
|
265
|
+
value: string;
|
|
266
|
+
label: string;
|
|
267
|
+
description?: string;
|
|
268
|
+
disabled?: boolean;
|
|
269
|
+
}
|
|
270
|
+
interface FormRadioGroupProps<TFieldValues extends FieldValues> {
|
|
271
|
+
/**
|
|
272
|
+
* Field name (registered with react-hook-form)
|
|
273
|
+
*/
|
|
274
|
+
name: Path<TFieldValues>;
|
|
275
|
+
/**
|
|
276
|
+
* Radio group label
|
|
277
|
+
*/
|
|
278
|
+
label?: string;
|
|
279
|
+
/**
|
|
280
|
+
* Radio options
|
|
281
|
+
*/
|
|
282
|
+
options: RadioOption[];
|
|
283
|
+
/**
|
|
284
|
+
* Layout orientation
|
|
285
|
+
*/
|
|
286
|
+
orientation?: "vertical" | "horizontal";
|
|
287
|
+
/**
|
|
288
|
+
* Help text shown below the radio group
|
|
289
|
+
*/
|
|
290
|
+
helperText?: string;
|
|
291
|
+
/**
|
|
292
|
+
* Whether the field is required
|
|
293
|
+
*/
|
|
294
|
+
required?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Whether the field is disabled
|
|
297
|
+
*/
|
|
298
|
+
disabled?: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Custom className
|
|
301
|
+
*/
|
|
302
|
+
className?: string;
|
|
303
|
+
}
|
|
304
|
+
declare function FormRadioGroup<TFieldValues extends FieldValues>({ name, label, options, orientation, helperText, required, disabled, className, }: FormRadioGroupProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
305
|
+
|
|
306
|
+
interface FormSwitchProps<TFieldValues extends FieldValues> {
|
|
307
|
+
/**
|
|
308
|
+
* Field name (registered with react-hook-form)
|
|
309
|
+
*/
|
|
310
|
+
name: Path<TFieldValues>;
|
|
311
|
+
/**
|
|
312
|
+
* Switch label
|
|
313
|
+
*/
|
|
314
|
+
label?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Description shown below the label
|
|
317
|
+
*/
|
|
318
|
+
description?: string;
|
|
319
|
+
/**
|
|
320
|
+
* Help text shown below the switch
|
|
321
|
+
*/
|
|
322
|
+
helperText?: string;
|
|
323
|
+
/**
|
|
324
|
+
* Whether the field is required
|
|
325
|
+
*/
|
|
326
|
+
required?: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Whether the field is disabled
|
|
329
|
+
*/
|
|
330
|
+
disabled?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Custom className
|
|
333
|
+
*/
|
|
334
|
+
className?: string;
|
|
335
|
+
/**
|
|
336
|
+
* Callback when value changes
|
|
337
|
+
*/
|
|
338
|
+
onChange?: (checked: boolean) => void;
|
|
339
|
+
}
|
|
340
|
+
declare function FormSwitch<TFieldValues extends FieldValues>({ name, label, description, helperText, required, disabled, className, onChange, }: FormSwitchProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
341
|
+
|
|
342
|
+
interface FormTagInputProps<TFieldValues extends FieldValues> {
|
|
343
|
+
/**
|
|
344
|
+
* Field name (registered with react-hook-form)
|
|
345
|
+
*/
|
|
346
|
+
name: Path<TFieldValues>;
|
|
347
|
+
/**
|
|
348
|
+
* Field label
|
|
349
|
+
*/
|
|
350
|
+
label?: string;
|
|
351
|
+
/**
|
|
352
|
+
* Placeholder text
|
|
353
|
+
*/
|
|
354
|
+
placeholder?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Help text shown below the input
|
|
357
|
+
*/
|
|
358
|
+
helperText?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Whether the field is required
|
|
361
|
+
*/
|
|
362
|
+
required?: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Whether the field is disabled
|
|
365
|
+
*/
|
|
366
|
+
disabled?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Maximum number of tags allowed
|
|
369
|
+
*/
|
|
370
|
+
maxTags?: number;
|
|
371
|
+
/**
|
|
372
|
+
* Separator keys (default: Enter, comma)
|
|
373
|
+
*/
|
|
374
|
+
separators?: string[];
|
|
375
|
+
/**
|
|
376
|
+
* Validate individual tags before adding
|
|
377
|
+
*/
|
|
378
|
+
validateTag?: (tag: string) => boolean | string;
|
|
379
|
+
/**
|
|
380
|
+
* Custom className
|
|
381
|
+
*/
|
|
382
|
+
className?: string;
|
|
383
|
+
}
|
|
384
|
+
declare function FormTagInput<TFieldValues extends FieldValues>({ name, label, placeholder, helperText, required, disabled, maxTags, separators, validateTag, className, }: FormTagInputProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* FormErrorSummary Component
|
|
388
|
+
*
|
|
389
|
+
* Displays all form errors in a summary box with links to fields.
|
|
390
|
+
*/
|
|
391
|
+
interface FormErrorSummaryProps {
|
|
392
|
+
/**
|
|
393
|
+
* Title for the error summary
|
|
394
|
+
*/
|
|
395
|
+
title?: string;
|
|
396
|
+
/**
|
|
397
|
+
* Custom field labels (for better error messages)
|
|
398
|
+
*/
|
|
399
|
+
fieldLabels?: Record<string, string>;
|
|
400
|
+
/**
|
|
401
|
+
* Whether to show the error summary
|
|
402
|
+
* Defaults to showing when there are errors
|
|
403
|
+
*/
|
|
404
|
+
show?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* Custom className
|
|
407
|
+
*/
|
|
408
|
+
className?: string;
|
|
409
|
+
/**
|
|
410
|
+
* Callback when an error link is clicked
|
|
411
|
+
*/
|
|
412
|
+
onErrorClick?: (fieldName: string) => void;
|
|
413
|
+
}
|
|
414
|
+
declare function FormErrorSummary({ title, fieldLabels, show, className, onErrorClick, }: FormErrorSummaryProps): react_jsx_runtime.JSX.Element | null;
|
|
415
|
+
|
|
264
416
|
interface FormLayoutProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
265
417
|
/**
|
|
266
418
|
* Number of columns for the form layout
|
|
@@ -451,6 +603,77 @@ declare function useSmartFieldArray<TFieldValues extends FieldValues = FieldValu
|
|
|
451
603
|
fields: react_hook_form.FieldArrayWithId<TFieldValues, ArrayPath<TFieldValues>, "id">[];
|
|
452
604
|
};
|
|
453
605
|
|
|
606
|
+
/**
|
|
607
|
+
* useUnsavedChanges Hook
|
|
608
|
+
*
|
|
609
|
+
* Warns users before leaving the page if form has unsaved changes.
|
|
610
|
+
*/
|
|
611
|
+
interface UseUnsavedChangesOptions {
|
|
612
|
+
/**
|
|
613
|
+
* Custom message for the confirmation dialog
|
|
614
|
+
*/
|
|
615
|
+
message?: string;
|
|
616
|
+
/**
|
|
617
|
+
* Whether to enable the warning
|
|
618
|
+
* Defaults to true
|
|
619
|
+
*/
|
|
620
|
+
enabled?: boolean;
|
|
621
|
+
/**
|
|
622
|
+
* Callback when user tries to leave with unsaved changes
|
|
623
|
+
*/
|
|
624
|
+
onBeforeUnload?: (isDirty: boolean) => void;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Hook to warn users before leaving the page with unsaved form changes
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```tsx
|
|
631
|
+
* function MyForm() {
|
|
632
|
+
* const form = useSmartForm({ schema: mySchema });
|
|
633
|
+
*
|
|
634
|
+
* useUnsavedChanges({
|
|
635
|
+
* message: "You have unsaved changes. Are you sure you want to leave?",
|
|
636
|
+
* enabled: true
|
|
637
|
+
* });
|
|
638
|
+
*
|
|
639
|
+
* return <FormProvider {...form}>...</FormProvider>;
|
|
640
|
+
* }
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
declare function useUnsavedChanges(options?: UseUnsavedChangesOptions): {
|
|
644
|
+
hasUnsavedChanges: boolean;
|
|
645
|
+
isDirty: boolean;
|
|
646
|
+
};
|
|
647
|
+
/**
|
|
648
|
+
* Hook variant for React Router integration
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```tsx
|
|
652
|
+
* function MyForm() {
|
|
653
|
+
* const form = useSmartForm({ schema: mySchema });
|
|
654
|
+
* const blocker = useUnsavedChangesBlocker();
|
|
655
|
+
*
|
|
656
|
+
* if (blocker.state === "blocked") {
|
|
657
|
+
* return (
|
|
658
|
+
* <ConfirmDialog
|
|
659
|
+
* title="Unsaved changes"
|
|
660
|
+
* message="You have unsaved changes. Are you sure you want to leave?"
|
|
661
|
+
* onConfirm={blocker.proceed}
|
|
662
|
+
* onCancel={blocker.reset}
|
|
663
|
+
* />
|
|
664
|
+
* );
|
|
665
|
+
* }
|
|
666
|
+
*
|
|
667
|
+
* return <FormProvider {...form}>...</FormProvider>;
|
|
668
|
+
* }
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
declare function useUnsavedChangesBlocker(): {
|
|
672
|
+
hasUnsavedChanges: boolean;
|
|
673
|
+
isDirty: boolean;
|
|
674
|
+
shouldBlock: boolean;
|
|
675
|
+
};
|
|
676
|
+
|
|
454
677
|
/**
|
|
455
678
|
* Common Validation Schemas
|
|
456
679
|
*
|
|
@@ -631,4 +854,4 @@ declare function validateFileExtension(filename: string, allowedExtensions: stri
|
|
|
631
854
|
*/
|
|
632
855
|
declare function formatValidationError(error: z.ZodError): Record<string, string>;
|
|
633
856
|
|
|
634
|
-
export { type FieldArrayOptions, FormCheckbox, type FormCheckboxProps, FormDatePicker, type FormDatePickerProps, FormField, type FormFieldProps, FormFileUpload, type FormFileUploadProps, FormGrid, FormGridItem, type FormGridItemProps, type FormGridProps, FormLayout, type FormLayoutProps, FormMultiSelect, type FormMultiSelectProps, FormSection, type FormSectionProps, FormSelect, type FormSelectProps, FormTextarea, type FormTextareaProps, FormWizard, type FormWizardProps, type FormWizardStep, type MultiSelectOption, type SelectOption, type SmartFormOptions, type SmartFormReturn, 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, usernameSchema, validateCreditCard, validateFileExtension, validateIBAN, validatePasswordStrength };
|
|
857
|
+
export { type FieldArrayOptions, FormCheckbox, type FormCheckboxProps, FormDatePicker, type FormDatePickerProps, FormErrorSummary, type FormErrorSummaryProps, FormField, type FormFieldProps, FormFileUpload, type FormFileUploadProps, FormGrid, FormGridItem, type FormGridItemProps, type FormGridProps, FormLayout, type FormLayoutProps, FormMultiSelect, type FormMultiSelectProps, FormRadioGroup, type FormRadioGroupProps, FormSection, type FormSectionProps, FormSelect, type FormSelectProps, FormSwitch, type FormSwitchProps, FormTagInput, type FormTagInputProps, FormTextarea, type FormTextareaProps, FormWizard, type FormWizardProps, type FormWizardStep, type MultiSelectOption, type RadioOption, type SelectOption, type SmartFormOptions, type SmartFormReturn, 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, usernameSchema, validateCreditCard, validateFileExtension, validateIBAN, validatePasswordStrength };
|