@flipdish/ui-library 0.51.0 → 0.53.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 +17 -16
- package/dist/components/atoms/Checkbox/index.cjs +4 -2
- package/dist/components/atoms/Checkbox/index.cjs.map +1 -1
- package/dist/components/atoms/Checkbox/index.d.ts.map +1 -1
- package/dist/components/atoms/Checkbox/index.js +4 -2
- package/dist/components/atoms/Checkbox/index.js.map +1 -1
- package/dist/components/atoms/Slider/index.cjs +2 -2
- package/dist/components/atoms/Slider/index.cjs.map +1 -1
- package/dist/components/atoms/Slider/index.d.ts +3 -1
- package/dist/components/atoms/Slider/index.d.ts.map +1 -1
- package/dist/components/atoms/Slider/index.js +2 -2
- package/dist/components/atoms/Slider/index.js.map +1 -1
- package/dist/components/forms/Form/hooks/useForm.cjs +26 -0
- package/dist/components/forms/Form/hooks/useForm.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useForm.d.ts +13 -0
- package/dist/components/forms/Form/hooks/useForm.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useForm.js +24 -0
- package/dist/components/forms/Form/hooks/useForm.js.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs +93 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts +54 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js +91 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs +28 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts +10 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js +26 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js.map +1 -0
- package/dist/components/forms/Form/index.cjs +63 -0
- package/dist/components/forms/Form/index.cjs.map +1 -0
- package/dist/components/forms/Form/index.d.ts +37 -0
- package/dist/components/forms/Form/index.d.ts.map +1 -0
- package/dist/components/forms/Form/index.js +59 -0
- package/dist/components/forms/Form/index.js.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.cjs +23 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.cjs.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts +14 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.js +21 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.js.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs +39 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts +17 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js +37 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs +26 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts +9 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.js +24 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.js.map +1 -0
- package/dist/components/forms/FormFooter/index.cjs +41 -0
- package/dist/components/forms/FormFooter/index.cjs.map +1 -0
- package/dist/components/forms/FormFooter/index.d.ts +56 -0
- package/dist/components/forms/FormFooter/index.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/index.js +39 -0
- package/dist/components/forms/FormFooter/index.js.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs +21 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts +12 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.js +19 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.js.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.cjs +28 -0
- package/dist/components/forms/FormSaveErrorAlert/index.cjs.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.d.ts +18 -0
- package/dist/components/forms/FormSaveErrorAlert/index.d.ts.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.js +26 -0
- package/dist/components/forms/FormSaveErrorAlert/index.js.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.cjs +15 -0
- package/dist/components/forms/FormSection/FormSection.styles.cjs.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.d.ts +9 -0
- package/dist/components/forms/FormSection/FormSection.styles.d.ts.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.js +13 -0
- package/dist/components/forms/FormSection/FormSection.styles.js.map +1 -0
- package/dist/components/forms/FormSection/index.cjs +43 -0
- package/dist/components/forms/FormSection/index.cjs.map +1 -0
- package/dist/components/forms/FormSection/index.d.ts +41 -0
- package/dist/components/forms/FormSection/index.d.ts.map +1 -0
- package/dist/components/forms/FormSection/index.js +41 -0
- package/dist/components/forms/FormSection/index.js.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.cjs +24 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.cjs.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.d.ts +14 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.d.ts.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.js +22 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs +28 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts +12 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js +26 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +68 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts +26 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +66 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs +147 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +35 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js +145 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs +12 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts +7 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js +10 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs +47 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts +26 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js +43 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs +39 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts +21 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js +37 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs +40 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts +18 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js +37 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs +21 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts +11 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js +19 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs +128 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts +72 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js +121 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs +12 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts +6 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js +10 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.cjs +34 -0
- package/dist/components/forms/fields/FormCheckbox/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.d.ts +19 -0
- package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.js +32 -0
- package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.cjs +33 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +19 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.js +31 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs +26 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts +11 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js +24 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.cjs +33 -0
- package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.d.ts +24 -0
- package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.js +31 -0
- package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs +20 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts +17 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js +18 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.cjs +35 -0
- package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.d.ts +20 -0
- package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.js +33 -0
- package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs +23 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts +9 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js +21 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js.map +1 -0
- package/dist/components/forms/fields/FormInput/index.cjs +27 -0
- package/dist/components/forms/fields/FormInput/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormInput/index.d.ts +19 -0
- package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormInput/index.js +25 -0
- package/dist/components/forms/fields/FormInput/index.js.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.cjs +44 -0
- package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts +20 -0
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.js +42 -0
- package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.cjs +36 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +32 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.js +34 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.cjs +31 -0
- package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts +20 -0
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.js +29 -0
- package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.cjs +30 -0
- package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.d.ts +19 -0
- package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.js +28 -0
- package/dist/components/forms/fields/FormSelect/index.js.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.cjs +43 -0
- package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.d.ts +20 -0
- package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.js +41 -0
- package/dist/components/forms/fields/FormSlider/index.js.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.cjs +27 -0
- package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.d.ts +19 -0
- package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.js +25 -0
- package/dist/components/forms/fields/FormTextArea/index.js.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.cjs +32 -0
- package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.d.ts +19 -0
- package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.js +30 -0
- package/dist/components/forms/fields/FormToggle/index.js.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +44 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +16 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.js +42 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -0
- package/dist/components/forms/validation/index.cjs +413 -0
- package/dist/components/forms/validation/index.cjs.map +1 -0
- package/dist/components/forms/validation/index.d.ts +278 -0
- package/dist/components/forms/validation/index.d.ts.map +1 -0
- package/dist/components/forms/validation/index.js +394 -0
- package/dist/components/forms/validation/index.js.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs +72 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.d.ts +38 -0
- package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.js +67 -0
- package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -0
- package/dist/components/forms/validation/validation.types.d.ts +8 -0
- package/dist/components/forms/validation/validation.types.d.ts.map +1 -0
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs +13 -3
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs.map +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.js +13 -3
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.js.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs +2 -2
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts +1 -0
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js +2 -2
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useCssColorField.cjs +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useCssColorField.js +1 -1
- package/dist/components/organisms/ColorPicker/index.cjs +1 -1
- package/dist/components/organisms/ColorPicker/index.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/index.js +1 -1
- package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts +1 -1
- package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.cjs.map +1 -0
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.d.ts.map +1 -0
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.js.map +1 -0
- package/dist/components/organisms/GradientPicker/components/GradientStopRow.cjs +1 -1
- package/dist/components/organisms/GradientPicker/components/GradientStopRow.js +1 -1
- package/dist/hooks/useFocusAfterRetry/index.cjs +7 -3
- package/dist/hooks/useFocusAfterRetry/index.cjs.map +1 -1
- package/dist/hooks/useFocusAfterRetry/index.d.ts +8 -2
- package/dist/hooks/useFocusAfterRetry/index.d.ts.map +1 -1
- package/dist/hooks/useFocusAfterRetry/index.js +7 -3
- package/dist/hooks/useFocusAfterRetry/index.js.map +1 -1
- package/dist/localization/en.json.cjs +117 -0
- package/dist/localization/en.json.cjs.map +1 -0
- package/dist/localization/en.json.js +98 -0
- package/dist/localization/en.json.js.map +1 -0
- package/dist/native/components/forms/Form/index.d.ts +12 -0
- package/dist/native/components/forms/FormFooter/index.d.ts +12 -0
- package/dist/native/components/forms/FormSaveErrorAlert/index.d.ts +12 -0
- package/dist/native/components/forms/FormSection/index.d.ts +12 -0
- package/dist/native/components/forms/FormUnsavedChangesModal/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormCheckbox/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormCheckboxGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormColorPicker/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormDatePicker/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormInput/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormMultiSelect/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormRadioCardGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormRadioGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormSelect/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormSlider/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormTextArea/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormToggle/index.d.ts +12 -0
- package/dist/native/components/forms/validation/index.d.ts +12 -0
- package/dist/native/utilities/colorUtils/index.d.ts +12 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.cjs +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/index.js +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.d.ts → utilities/unsavedChangesGuard.utils.d.ts} +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs +74 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +51 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js +68 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js.map +1 -0
- package/dist/utilities/colorUtils/index.cjs +24 -0
- package/dist/utilities/colorUtils/index.cjs.map +1 -0
- package/dist/utilities/colorUtils/index.d.ts +8 -0
- package/dist/utilities/colorUtils/index.d.ts.map +1 -0
- package/dist/utilities/colorUtils/index.js +22 -0
- package/dist/utilities/colorUtils/index.js.map +1 -0
- package/package.json +41 -6
- package/dist/components/organisms/ColorPicker/colorPicker.utils.cjs.map +0 -1
- package/dist/components/organisms/ColorPicker/colorPicker.utils.d.ts.map +0 -1
- package/dist/components/organisms/ColorPicker/colorPicker.utils.js.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js.map +0 -1
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.cjs → utilities/colorPicker.utils.cjs} +0 -0
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.d.ts → utilities/colorPicker.utils.d.ts} +0 -0
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.js → utilities/colorPicker.utils.js} +0 -0
- /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.cjs → utilities/unsavedChangesGuard.utils.cjs} +0 -0
- /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.js → utilities/unsavedChangesGuard.utils.js} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { UnsavedChangesModal } from '@flipdish/ui-library/components/molecules/Modals';
|
|
3
|
+
import { useFormContext, useFormState } from 'react-hook-form';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Asks before a form's unsaved edits are lost to navigation, reading the dirty flag from the form itself and standing
|
|
7
|
+
* down while a save is sending them. Render one inside each `Form` that waits on Save.
|
|
8
|
+
*
|
|
9
|
+
* @summary unsaved-changes modal driven by its form's own state
|
|
10
|
+
*/
|
|
11
|
+
const FormUnsavedChangesModal = ({ isDisabled = false, 'data-testid': dataTestId }) => {
|
|
12
|
+
const form = useFormContext();
|
|
13
|
+
if (!form)
|
|
14
|
+
throw new Error("FormUnsavedChangesModal needs Form above it: it guards that form's unsaved edits.");
|
|
15
|
+
const { isDirty, isSubmitting } = useFormState({ control: form.control });
|
|
16
|
+
// Edits a save is sending can no longer be discarded by leaving, so only a draft at rest is guarded.
|
|
17
|
+
const hasUnsavedChanges = isDirty && !isSubmitting && !isDisabled;
|
|
18
|
+
return jsx(UnsavedChangesModal, { hasUnsavedChanges: hasUnsavedChanges, "data-testid": dataTestId });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { FormUnsavedChangesModal };
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/forms/FormUnsavedChangesModal/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;AAYA;;;;;AAKG;AACI,MAAM,uBAAuB,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,EAAE,aAAa,EAAE,UAAU,EAAgC,KAAI;AACzH,IAAA,MAAM,IAAI,GAAG,cAAc,EAAE;AAC7B,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC;AAC/G,IAAA,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;;IAEzE,MAAM,iBAAiB,GAAG,OAAO,IAAI,CAAC,YAAY,IAAI,CAAC,UAAU;IAEjE,OAAOA,GAAA,CAAC,mBAAmB,EAAA,EAAC,iBAAiB,EAAE,iBAAiB,EAAA,aAAA,EAAe,UAAU,EAAA,CAAI;AAC/F;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
|
|
7
|
+
* focusable element inside the wrapper, so a failed submit can still land on the field.
|
|
8
|
+
*
|
|
9
|
+
* @param ref The field's ref from `useFormField`.
|
|
10
|
+
* @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
|
|
11
|
+
* @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
|
|
12
|
+
* @returns A ref for the wrapper element.
|
|
13
|
+
*/
|
|
14
|
+
const useFocusTarget = (ref, selector, fallbackSelector) => React.useCallback((wrapper) => {
|
|
15
|
+
// Passed on, so the form lets go of a wrapper that has left the page.
|
|
16
|
+
if (!wrapper)
|
|
17
|
+
return ref(null);
|
|
18
|
+
const find = () => wrapper.querySelector(selector) ?? (fallbackSelector ? wrapper.querySelector(fallbackSelector) : null);
|
|
19
|
+
ref({
|
|
20
|
+
focus: () => find()?.focus(),
|
|
21
|
+
contains: (node) => wrapper.contains(node),
|
|
22
|
+
ownerDocument: wrapper.ownerDocument,
|
|
23
|
+
element: wrapper,
|
|
24
|
+
});
|
|
25
|
+
}, [ref, selector, fallbackSelector]);
|
|
26
|
+
|
|
27
|
+
exports.useFocusTarget = useFocusTarget;
|
|
28
|
+
//# sourceMappingURL=useFocusTarget.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTarget.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"sourcesContent":[null],"names":["useCallback"],"mappings":";;;;AAGA;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,GAAgB,EAAE,QAAgB,EAAE,gBAAyB,KAC1FA,iBAAW,CACT,CAAC,OAA2B,KAAI;;AAE9B,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,GAAG,CAAC,IAAI,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,MACX,OAAO,CAAC,aAAa,CAAc,QAAQ,CAAC,KAAK,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAc,gBAAgB,CAAC,GAAG,IAAI,CAAC;AAClI,IAAA,GAAG,CAAC;QACF,KAAK,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE;QAC5B,QAAQ,EAAE,CAAC,IAAiB,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,OAAO,CAAC,aAAa;AACpC,QAAA,OAAO,EAAE,OAAO;AACjB,KAAA,CAAC;AACJ,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RefCallBack } from 'react-hook-form';
|
|
2
|
+
/**
|
|
3
|
+
* Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
|
|
4
|
+
* focusable element inside the wrapper, so a failed submit can still land on the field.
|
|
5
|
+
*
|
|
6
|
+
* @param ref The field's ref from `useFormField`.
|
|
7
|
+
* @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
|
|
8
|
+
* @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
|
|
9
|
+
* @returns A ref for the wrapper element.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useFocusTarget: (ref: RefCallBack, selector: string, fallbackSelector?: string) => (wrapper: HTMLElement | null) => void;
|
|
12
|
+
//# sourceMappingURL=useFocusTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTarget.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,EAAE,UAAU,MAAM,EAAE,mBAAmB,MAAM,eAE9E,WAAW,GAAG,IAAI,SAa7B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
|
|
5
|
+
* focusable element inside the wrapper, so a failed submit can still land on the field.
|
|
6
|
+
*
|
|
7
|
+
* @param ref The field's ref from `useFormField`.
|
|
8
|
+
* @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
|
|
9
|
+
* @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
|
|
10
|
+
* @returns A ref for the wrapper element.
|
|
11
|
+
*/
|
|
12
|
+
const useFocusTarget = (ref, selector, fallbackSelector) => useCallback((wrapper) => {
|
|
13
|
+
// Passed on, so the form lets go of a wrapper that has left the page.
|
|
14
|
+
if (!wrapper)
|
|
15
|
+
return ref(null);
|
|
16
|
+
const find = () => wrapper.querySelector(selector) ?? (fallbackSelector ? wrapper.querySelector(fallbackSelector) : null);
|
|
17
|
+
ref({
|
|
18
|
+
focus: () => find()?.focus(),
|
|
19
|
+
contains: (node) => wrapper.contains(node),
|
|
20
|
+
ownerDocument: wrapper.ownerDocument,
|
|
21
|
+
element: wrapper,
|
|
22
|
+
});
|
|
23
|
+
}, [ref, selector, fallbackSelector]);
|
|
24
|
+
|
|
25
|
+
export { useFocusTarget };
|
|
26
|
+
//# sourceMappingURL=useFocusTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTarget.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,GAAgB,EAAE,QAAgB,EAAE,gBAAyB,KAC1F,WAAW,CACT,CAAC,OAA2B,KAAI;;AAE9B,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,GAAG,CAAC,IAAI,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,MACX,OAAO,CAAC,aAAa,CAAc,QAAQ,CAAC,KAAK,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAc,gBAAgB,CAAC,GAAG,IAAI,CAAC;AAClI,IAAA,GAAG,CAAC;QACF,KAAK,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE;QAC5B,QAAQ,EAAE,CAAC,IAAiB,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,OAAO,CAAC,aAAa;AACpC,QAAA,OAAO,EAAE,OAAO;AACjB,KAAA,CAAC;AACJ,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
|
|
7
|
+
* read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
|
|
8
|
+
* such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
|
|
9
|
+
*
|
|
10
|
+
* @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
|
|
11
|
+
* @param isSubmitting Whether the form is submitting.
|
|
12
|
+
* @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
|
|
13
|
+
*/
|
|
14
|
+
const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
|
|
15
|
+
const target = React.useRef(null);
|
|
16
|
+
const focus = React.useRef({ heldBy: null, wasLost: false, isOwed: false });
|
|
17
|
+
// The lock follows the submit by one render, so focus can be read first: a browser drops it the moment a control is disabled.
|
|
18
|
+
const [hasReadFocus, setHasReadFocus] = React.useState(false);
|
|
19
|
+
const isLocked = isSubmitting && hasReadFocus;
|
|
20
|
+
const ref = React.useCallback((instance) => {
|
|
21
|
+
target.current = instance;
|
|
22
|
+
if (!instance)
|
|
23
|
+
return fieldRef(null);
|
|
24
|
+
fieldRef({
|
|
25
|
+
focus: () => {
|
|
26
|
+
instance.focus();
|
|
27
|
+
focus.current.isOwed = !instance.contains(instance.ownerDocument.activeElement);
|
|
28
|
+
},
|
|
29
|
+
select: () => instance.select?.(),
|
|
30
|
+
});
|
|
31
|
+
}, [fieldRef]);
|
|
32
|
+
React.useLayoutEffect(() => {
|
|
33
|
+
const state = focus.current;
|
|
34
|
+
const control = target.current;
|
|
35
|
+
if (!control)
|
|
36
|
+
return setHasReadFocus(isSubmitting);
|
|
37
|
+
const { ownerDocument } = control;
|
|
38
|
+
if (isSubmitting && !hasReadFocus) {
|
|
39
|
+
const focused = ownerDocument.activeElement;
|
|
40
|
+
state.heldBy = control.contains(focused) ? focused : null;
|
|
41
|
+
// A request the control refused before this submit is stale: only one made while it is locked is owed.
|
|
42
|
+
state.isOwed = false;
|
|
43
|
+
return setHasReadFocus(true);
|
|
44
|
+
}
|
|
45
|
+
if (isSubmitting) {
|
|
46
|
+
// Only a control the lock disabled loses focus to it; a read-only one keeps it, and must not take it back later.
|
|
47
|
+
state.wasLost = state.heldBy?.matches(':disabled') ?? false;
|
|
48
|
+
// Focus the user puts elsewhere meanwhile is theirs: it is not pulled back, even if another form's submit then drops
|
|
49
|
+
// it, and neither is focus the form had sent here before the user moved on.
|
|
50
|
+
const forget = () => {
|
|
51
|
+
state.wasLost = false;
|
|
52
|
+
state.isOwed = false;
|
|
53
|
+
};
|
|
54
|
+
ownerDocument.addEventListener('focusin', forget);
|
|
55
|
+
return () => ownerDocument.removeEventListener('focusin', forget);
|
|
56
|
+
}
|
|
57
|
+
setHasReadFocus(false);
|
|
58
|
+
// Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
|
|
59
|
+
const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
|
|
60
|
+
if (state.isOwed || isStillLost)
|
|
61
|
+
control.focus();
|
|
62
|
+
focus.current = { heldBy: null, wasLost: false, isOwed: false };
|
|
63
|
+
}, [isSubmitting, hasReadFocus]);
|
|
64
|
+
return { ref, isLocked };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.useFocusThroughSubmit = useFocusThroughSubmit;
|
|
68
|
+
//# sourceMappingURL=useFocusThroughSubmit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTh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AAI,CAAC,YAAY,EAAE;AACjC,YAAA,MAAM,OAAO,GAAG,aAAa,CAAC,aAAa;AAC3C,YAAA,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,IAAI;;AAEzD,YAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACpB,YAAA,OAAO,eAAe,CAAC,IAAI,CAAC;QAC9B;QACA,IAAI,YAAY,EAAE;;AAEhB,YAAA,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK;;;YAG3D,MAAM,MAAM,GAAG,MAAK;AAClB,gBAAA,KAAK,CAAC,OAAO,GAAG,KAAK;AACrB,gBAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACtB,YAAA,CAAC;AACD,YAAA,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC;YACjD,OAAO,MAAM,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC;QACnE;QACA,eAAe,CAAC,KAAK,CAAC;;AAEtB,QAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,IAAI,aAAa,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI;AACvF,QAAA,IAAI,KAAK,CAAC,MAAM,IAAI,WAAW;YAAE,OAAO,CAAC,KAAK,EAAE;AAChD,QAAA,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;AACjE,IAAA,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAEhC,IAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;AAC1B;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RefCallBack } from 'react-hook-form';
|
|
2
|
+
/** What a wrapper hands the form to focus: the control's own element, or `useFocusTarget`'s stand-in for one inside a wrapper. */
|
|
3
|
+
export interface FocusTarget {
|
|
4
|
+
focus: () => void;
|
|
5
|
+
/** Whether the node is the control or sits inside it, which tells the form where focus was when a submit began. */
|
|
6
|
+
contains: (node: Node | null) => boolean;
|
|
7
|
+
/** The document the control is in, which is where focus is read from. */
|
|
8
|
+
ownerDocument: Document;
|
|
9
|
+
select?: () => void;
|
|
10
|
+
/** The element the control occupies on the page, from a stand-in that is not an element itself. */
|
|
11
|
+
element?: Element;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
|
|
15
|
+
* read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
|
|
16
|
+
* such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
|
|
17
|
+
*
|
|
18
|
+
* @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
|
|
19
|
+
* @param isSubmitting Whether the form is submitting.
|
|
20
|
+
* @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
|
|
21
|
+
*/
|
|
22
|
+
export declare const useFocusThroughSubmit: (fieldRef: RefCallBack, isSubmitting: boolean) => {
|
|
23
|
+
ref: (instance: FocusTarget | null) => void;
|
|
24
|
+
isLocked: boolean;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=useFocusThroughSubmit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,kIAAkI;AAClI,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,QAAQ,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,mGAAmG;IACnG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,WAAW,EAAE,cAAc,OAAO;oBAQnE,WAAW,GAAG,IAAI;;CA8ChC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useRef, useState, useCallback, useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
|
|
5
|
+
* read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
|
|
6
|
+
* such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
|
|
7
|
+
*
|
|
8
|
+
* @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
|
|
9
|
+
* @param isSubmitting Whether the form is submitting.
|
|
10
|
+
* @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
|
|
11
|
+
*/
|
|
12
|
+
const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
|
|
13
|
+
const target = useRef(null);
|
|
14
|
+
const focus = useRef({ heldBy: null, wasLost: false, isOwed: false });
|
|
15
|
+
// The lock follows the submit by one render, so focus can be read first: a browser drops it the moment a control is disabled.
|
|
16
|
+
const [hasReadFocus, setHasReadFocus] = useState(false);
|
|
17
|
+
const isLocked = isSubmitting && hasReadFocus;
|
|
18
|
+
const ref = useCallback((instance) => {
|
|
19
|
+
target.current = instance;
|
|
20
|
+
if (!instance)
|
|
21
|
+
return fieldRef(null);
|
|
22
|
+
fieldRef({
|
|
23
|
+
focus: () => {
|
|
24
|
+
instance.focus();
|
|
25
|
+
focus.current.isOwed = !instance.contains(instance.ownerDocument.activeElement);
|
|
26
|
+
},
|
|
27
|
+
select: () => instance.select?.(),
|
|
28
|
+
});
|
|
29
|
+
}, [fieldRef]);
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
const state = focus.current;
|
|
32
|
+
const control = target.current;
|
|
33
|
+
if (!control)
|
|
34
|
+
return setHasReadFocus(isSubmitting);
|
|
35
|
+
const { ownerDocument } = control;
|
|
36
|
+
if (isSubmitting && !hasReadFocus) {
|
|
37
|
+
const focused = ownerDocument.activeElement;
|
|
38
|
+
state.heldBy = control.contains(focused) ? focused : null;
|
|
39
|
+
// A request the control refused before this submit is stale: only one made while it is locked is owed.
|
|
40
|
+
state.isOwed = false;
|
|
41
|
+
return setHasReadFocus(true);
|
|
42
|
+
}
|
|
43
|
+
if (isSubmitting) {
|
|
44
|
+
// Only a control the lock disabled loses focus to it; a read-only one keeps it, and must not take it back later.
|
|
45
|
+
state.wasLost = state.heldBy?.matches(':disabled') ?? false;
|
|
46
|
+
// Focus the user puts elsewhere meanwhile is theirs: it is not pulled back, even if another form's submit then drops
|
|
47
|
+
// it, and neither is focus the form had sent here before the user moved on.
|
|
48
|
+
const forget = () => {
|
|
49
|
+
state.wasLost = false;
|
|
50
|
+
state.isOwed = false;
|
|
51
|
+
};
|
|
52
|
+
ownerDocument.addEventListener('focusin', forget);
|
|
53
|
+
return () => ownerDocument.removeEventListener('focusin', forget);
|
|
54
|
+
}
|
|
55
|
+
setHasReadFocus(false);
|
|
56
|
+
// Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
|
|
57
|
+
const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
|
|
58
|
+
if (state.isOwed || isStillLost)
|
|
59
|
+
control.focus();
|
|
60
|
+
focus.current = { heldBy: null, wasLost: false, isOwed: false };
|
|
61
|
+
}, [isSubmitting, hasReadFocus]);
|
|
62
|
+
return { ref, isLocked };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { useFocusThroughSubmit };
|
|
66
|
+
//# sourceMappingURL=useFocusThroughSubmit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CAAC,QAAqB,EAAE,YAAqB,KAAI;AACpF,IAAA,MAAM,MAAM,GAAG,MAAM,CAAqB,IAAI,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAgE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;IAEpI,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,QAAQ,GAAG,YAAY,IAAI,YAAY;AAE7C,IAAA,MAAM,GAAG,GAAG,WAAW,CACrB,CAAC,QAA4B,KAAI;AAC/B,QAAA,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACpC,QAAA,QAAQ,CAAC;YACP,KAAK,EAAE,MAAK;gBACV,QAAQ,CAAC,KAAK,EAAE;AAChB,gBAAA,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC;YACjF,CAAC;YACD,MAAM,EAAE,MAAM,QAAQ,CAAC,MAAM,IAAI;AAClC,SAAA,CAAC;AACJ,IAAA,CAAC,EACD,CAAC,QAAQ,CAAC,CACX;IAED,eAAe,CAAC,MAAK;AACnB,QAAA,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO;AAC3B,QAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO;AAC9B,QAAA,IAAI,CAAC,OAAO;AAAE,YAAA,OAAO,eAAe,CAAC,YAAY,CAAC;AAClD,QAAA,MAA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= require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var FieldElements_context = require('../providers/FieldElements.context.cjs');
|
|
6
|
+
var fieldDependents_utils = require('../utilities/fieldDependents.utils.cjs');
|
|
7
|
+
var fieldValue_utils = require('../utilities/fieldValue.utils.cjs');
|
|
8
|
+
var validationQueue_utils = require('../utilities/validationQueue.utils.cjs');
|
|
9
|
+
var useFocusThroughSubmit = require('./useFocusThroughSubmit.cjs');
|
|
10
|
+
|
|
11
|
+
const toList = (value) => {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return [];
|
|
14
|
+
return Array.isArray(value) ? value : [value];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Binds one control to a react-hook-form field, for the `components/forms` wrappers. In a form that validates and
|
|
18
|
+
* re-validates on blur (`mode` and `reValidateMode` both `'onBlur'`) it re-validates a field on every change while that field is invalid, so an error raised by a blur,
|
|
19
|
+
* a submit, `trigger()` or the server clears as soon as the user fixes it, and a valid field stays quiet until blur.
|
|
20
|
+
* It also reports the form's lock: disabled for good, or locked while it submits.
|
|
21
|
+
*
|
|
22
|
+
* @param name The field's path in the form values.
|
|
23
|
+
* @param revalidates Other fields whose rule reads this one, added to those a `useSchemaResolver` resolver names from its schema's `crossFieldRules`. Typing here re-validates those already invalid; finishing the edit also re-validates those the user has filled in or visited.
|
|
24
|
+
* @returns The field's `value`, `onChange`, `onCommit`, `onDraft`, `onBlur`, `ref` and `name`, with `isInvalid`, its `errorMessage`, and the form's lock as `isDisabled` and `isLocked`.
|
|
25
|
+
*/
|
|
26
|
+
const useFormField = (name, revalidates) => {
|
|
27
|
+
const form = reactHookForm.useFormContext();
|
|
28
|
+
if (!form)
|
|
29
|
+
throw new Error('A components/forms field needs a react-hook-form FormProvider above it.');
|
|
30
|
+
const { control, trigger, getFieldState, getValues } = form;
|
|
31
|
+
const { field, fieldState, formState } = reactHookForm.useController({ name, control });
|
|
32
|
+
const { ref: focusRef, isLocked } = useFocusThroughSubmit.useFocusThroughSubmit(field.ref, formState.isSubmitting);
|
|
33
|
+
const fieldElements = React.useContext(FieldElements_context.FieldElementsContext);
|
|
34
|
+
// `Form` reads where each field sits, so a failed submit focuses the first invalid one in page order.
|
|
35
|
+
const ref = React.useCallback((instance) => {
|
|
36
|
+
focusRef(instance);
|
|
37
|
+
const element = instance instanceof Element ? instance : instance?.element;
|
|
38
|
+
if (element)
|
|
39
|
+
fieldElements?.set(name, element);
|
|
40
|
+
else
|
|
41
|
+
fieldElements?.delete(name);
|
|
42
|
+
}, [focusRef, fieldElements, name]);
|
|
43
|
+
const { onChange: setValue } = field;
|
|
44
|
+
const isInvalid = fieldState.invalid;
|
|
45
|
+
const { error } = fieldState;
|
|
46
|
+
const errorMessage = error?.message;
|
|
47
|
+
// `trigger` is only on the form, not on `control`, which is why the wrappers need a FormProvider.
|
|
48
|
+
const validate = React.useCallback((names) => trigger(names), [trigger]);
|
|
49
|
+
const validation = validationQueue_utils.validationQueueOf(control);
|
|
50
|
+
// Typing only ever clears an error or changes its message, so it asks only while the field is invalid.
|
|
51
|
+
const isInvalidNow = React.useCallback((field) => getFieldState(field).invalid, [getFieldState]);
|
|
52
|
+
const revalidate = React.useCallback(() => validationQueue_utils.runInTurn(validation, [name], isInvalidNow, validate), [validation, name, isInvalidNow, validate]);
|
|
53
|
+
// Whether a finished edit still stands when a check it asked for comes up: the field holds that value, and counts as
|
|
54
|
+
// visited or changed. A reset leaves it neither, even one to the value just chosen, and validating then would put an error on a form just discarded.
|
|
55
|
+
const standingEdit = React.useCallback(() => {
|
|
56
|
+
const edited = getValues(name);
|
|
57
|
+
return () => {
|
|
58
|
+
const editor = getFieldState(name);
|
|
59
|
+
// By what it holds: leaving the field copies a list or a group, so the same choice comes back as a new object.
|
|
60
|
+
return fieldValue_utils.isSameValue(getValues(name), edited) && (editor.isTouched || editor.isDirty);
|
|
61
|
+
};
|
|
62
|
+
}, [name, getFieldState, getValues]);
|
|
63
|
+
// The end of an edit: react-hook-form marks the field visited and validates it, by itself and outside the queue.
|
|
64
|
+
const { onBlur: validateOnBlur } = field;
|
|
65
|
+
const finishEdit = React.useCallback(() => {
|
|
66
|
+
const isAwaited = validationQueue_utils.isAwaitingAnswer(validation, name);
|
|
67
|
+
// Typed as returning nothing, but react-hook-form (7.92) returns the validation it started; without it no turn is held back.
|
|
68
|
+
const answer = validateOnBlur();
|
|
69
|
+
validationQueue_utils.holdTurnsUntil(validation, name, answer);
|
|
70
|
+
// An answer on its way is for an older value and may land after this one: asked again in turn, so it is not the last word.
|
|
71
|
+
if (isAwaited)
|
|
72
|
+
void validationQueue_utils.runInTurn(validation, [name], standingEdit(), validate);
|
|
73
|
+
}, [validation, name, validateOnBlur, standingEdit, validate]);
|
|
74
|
+
// A cross-field rule puts its error on another field, which the form never re-checks when this one changes. Typing
|
|
75
|
+
// only clears such an error; a finished edit may also raise one, on a dependent the user has filled in or visited.
|
|
76
|
+
const revalidateDependents = React.useCallback((isEditFinished) => {
|
|
77
|
+
// The edit that asks. If it is gone when the turn comes, only an error already on screen is worth re-checking.
|
|
78
|
+
const isEditStanding = standingEdit();
|
|
79
|
+
const isWanted = (dependent) => {
|
|
80
|
+
const { invalid, isTouched } = getFieldState(dependent);
|
|
81
|
+
if (invalid)
|
|
82
|
+
return true;
|
|
83
|
+
return isEditFinished && isEditStanding() && (isTouched || fieldValue_utils.isFilledIn(getValues(dependent)));
|
|
84
|
+
};
|
|
85
|
+
// Read when the edit happens, not when the field renders: the form may have been given another schema since.
|
|
86
|
+
// `_options` is react-hook-form's own copy of what `useForm` was given, the only place a field can reach the resolver.
|
|
87
|
+
// Private to it, so read with `?.`: a release that moves it then costs these dependents, not every edit.
|
|
88
|
+
const named = (fieldDependents_utils.dependentsOf(control._options?.resolver).get(name) ?? []);
|
|
89
|
+
const dependents = [...new Set([...named, ...toList(revalidates)])];
|
|
90
|
+
if (dependents.length > 0)
|
|
91
|
+
void validationQueue_utils.runInTurn(validation, dependents, isWanted, validate);
|
|
92
|
+
}, [revalidates, control, name, standingEdit, getFieldState, getValues, validation, validate]);
|
|
93
|
+
// Typed into since the dependents were last checked in full, which leaving the field then does.
|
|
94
|
+
const hasTyped = React.useRef(false);
|
|
95
|
+
const onChange = React.useCallback((next) => {
|
|
96
|
+
setValue(next);
|
|
97
|
+
const isAwaited = validationQueue_utils.isAwaitingAnswer(validation, name);
|
|
98
|
+
// Leaving the field checks it again, so nothing withdrawn here is lost.
|
|
99
|
+
validationQueue_utils.withdrawAsks(validation, name);
|
|
100
|
+
// Read from the form, not from the last render: an error that landed between two keystrokes is not on screen yet.
|
|
101
|
+
// Also while an answer is on its way: the error may have cleared since, and that answer is for an older value.
|
|
102
|
+
if (getFieldState(name).invalid || isAwaited)
|
|
103
|
+
void revalidate();
|
|
104
|
+
hasTyped.current = true;
|
|
105
|
+
revalidateDependents(false);
|
|
106
|
+
}, [setValue, getFieldState, validation, name, revalidate, revalidateDependents]);
|
|
107
|
+
// The value the current error was raised against. Leaving the field without changing it cannot make it valid, and
|
|
108
|
+
// re-validating would wipe an error only the server can judge, such as a name that is already taken.
|
|
109
|
+
const erroredValue = React.useRef(undefined);
|
|
110
|
+
const { value } = field;
|
|
111
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: recorded when the error appears or changes, not on every keystroke
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
erroredValue.current = error ? value : undefined;
|
|
114
|
+
}, [error]);
|
|
115
|
+
const onBlur = React.useCallback(() => {
|
|
116
|
+
const hadTyped = hasTyped.current;
|
|
117
|
+
hasTyped.current = false;
|
|
118
|
+
// First, so the field counts as visited before its dependents are asked about, which they are only while it does.
|
|
119
|
+
if (!(error && fieldValue_utils.isSameValue(value, erroredValue.current)))
|
|
120
|
+
finishEdit();
|
|
121
|
+
// Leaving a field the user only passed through must not raise an error on another one.
|
|
122
|
+
if (hadTyped)
|
|
123
|
+
revalidateDependents(true);
|
|
124
|
+
}, [error, value, finishEdit, revalidateDependents]);
|
|
125
|
+
// A choice has no typing phase to wait out, so it counts as changed and left in one step.
|
|
126
|
+
const onCommit = React.useCallback((next) => {
|
|
127
|
+
setValue(next);
|
|
128
|
+
finishEdit();
|
|
129
|
+
revalidateDependents(true);
|
|
130
|
+
}, [setValue, finishEdit, revalidateDependents]);
|
|
131
|
+
return {
|
|
132
|
+
name: field.name,
|
|
133
|
+
value: value,
|
|
134
|
+
ref,
|
|
135
|
+
onBlur,
|
|
136
|
+
onDraft: setValue,
|
|
137
|
+
onChange,
|
|
138
|
+
onCommit,
|
|
139
|
+
isInvalid,
|
|
140
|
+
errorMessage,
|
|
141
|
+
isDisabled: field.disabled ?? false,
|
|
142
|
+
isLocked,
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
exports.useFormField = useFormField;
|
|
147
|
+
//# sourceMappingURL=useFormField.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormField.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"sourcesContent":[null],"names":["useFormContext","useController","useFocusThroughSubmit","useContext","FieldElementsContext","useCallback","validationQueueOf","runInTurn","isSameValue","isAwaitingAnswer","holdTurnsUntil","isFilledIn","dependentsOf","useRef","withdrawAsks","useEffect"],"mappings":";;;;;;;;;;AA+BA,MAAM,MAAM,GAAG,CAAQ,KAAkC,KAAa;IACpE,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,EAAE;AAClC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;AAC/C,CAAC;AAED;;;;;;;;;AASG;MACU,YAAY,GAAG,CAC1B,IAAwB,EACxB,WAAuD,KAClC;AACrB,IAAA,MAAM,IAAI,GAAGA,4BAAc,EAAW;AACtC,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC;IACrG,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,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AAC,QAAQ,IAAI,KAAK;QACnC,QAAQ;KACT;AACH;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type FieldPath, type FieldValues, type RefCallBack } from 'react-hook-form';
|
|
2
|
+
/** What a `components/forms` wrapper spreads onto its control. */
|
|
3
|
+
export interface FormField<TValue> {
|
|
4
|
+
name: string;
|
|
5
|
+
/** The field's value in the form; `undefined` when the form has no default for it. */
|
|
6
|
+
value: TValue | undefined;
|
|
7
|
+
/** Lets the form focus the control, such as the first invalid field after a failed submit. */
|
|
8
|
+
ref: RefCallBack;
|
|
9
|
+
onBlur: () => void;
|
|
10
|
+
/** Sets the value with no validation of its own, for a value still in motion such as a slider mid-drag. */
|
|
11
|
+
onDraft: (value: TValue) => void;
|
|
12
|
+
/** For a control the user types into: sets the value, and re-validates while the field is invalid. */
|
|
13
|
+
onChange: (value: TValue) => void;
|
|
14
|
+
/** For a control where one action is the whole edit (a choice, a toggle, a picked date): sets the value and validates it. */
|
|
15
|
+
onCommit: (value: TValue) => void;
|
|
16
|
+
isInvalid: boolean;
|
|
17
|
+
/** The message validation gave the field's error. */
|
|
18
|
+
errorMessage: string | undefined;
|
|
19
|
+
/** The whole form is disabled, through `useForm({ disabled })`. */
|
|
20
|
+
isDisabled: boolean;
|
|
21
|
+
/** The form is submitting: the control is read-only meanwhile, or disabled where it has no read-only mode. */
|
|
22
|
+
isLocked: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Binds one control to a react-hook-form field, for the `components/forms` wrappers. In a form that validates and
|
|
26
|
+
* re-validates on blur (`mode` and `reValidateMode` both `'onBlur'`) it re-validates a field on every change while that field is invalid, so an error raised by a blur,
|
|
27
|
+
* a submit, `trigger()` or the server clears as soon as the user fixes it, and a valid field stays quiet until blur.
|
|
28
|
+
* It also reports the form's lock: disabled for good, or locked while it submits.
|
|
29
|
+
*
|
|
30
|
+
* @param name The field's path in the form values.
|
|
31
|
+
* @param revalidates Other fields whose rule reads this one, added to those a `useSchemaResolver` resolver names from its schema's `crossFieldRules`. Typing here re-validates those already invalid; finishing the edit also re-validates those the user has filled in or visited.
|
|
32
|
+
* @returns The field's `value`, `onChange`, `onCommit`, `onDraft`, `onBlur`, `ref` and `name`, with `isInvalid`, its `errorMessage`, and the form's lock as `isDisabled` and `isLocked`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const useFormField: <TValues extends FieldValues, TValue = unknown>(name: FieldPath<TValues>, revalidates?: FieldPath<TValues> | FieldPath<TValues>[]) => FormField<TValue>;
|
|
35
|
+
//# sourceMappingURL=useFormField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAiC,MAAM,iBAAiB,CAAC;AAOpH,kEAAkE;AAClE,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,8FAA8F;IAC9F,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,2GAA2G;IAC3G,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,sGAAsG;IACtG,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,6HAA6H;IAC7H,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAC;IACpB,8GAA8G;IAC9G,QAAQ,EAAE,OAAO,CAAC;CACnB;AAOD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,WAAW,EAAE,MAAM,GAAG,OAAO,EACxE,MAAM,SAAS,CAAC,OAAO,CAAC,EACxB,cAAc,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,KACtD,SAAS,CAAC,MAAM,CAkIlB,CAAC"}
|