@digigov/form 2.0.0-4be8f7cc → 2.0.0-555d1027
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/Field/ErrorGroup/index.js +48 -0
- package/{Questions/index.spec → Field/ErrorGroup}/package.json +1 -1
- package/Field/ErrorGroup.d.ts +15 -0
- package/Field/ErrorGroup.js.map +7 -0
- package/Field/FieldBase/index.js +116 -77
- package/Field/FieldBase.js.map +7 -0
- package/Field/FieldBaseContainer/index.js +47 -37
- package/Field/FieldBaseContainer.js.map +7 -0
- package/Field/FieldConditional/index.js +83 -53
- package/Field/FieldConditional.js.map +7 -0
- package/Field/index.js +113 -63
- package/Field/index.js.map +7 -0
- package/Field/types/index.js +1 -1
- package/Field/types.d.ts +52 -5
- package/Field/types.js.map +7 -0
- package/Field/utils/calculateField/index.js +27 -0
- package/{FieldArray/FieldArray.stories → Field/utils/calculateField}/package.json +1 -1
- package/Field/utils/calculateField.d.ts +2 -0
- package/Field/utils/calculateField.js.map +7 -0
- package/Field/utils/evaluateFieldWithConditions/index.js +26 -0
- package/{inputs/DateInput/__stories__/Default → Field/utils/evaluateFieldWithConditions}/package.json +1 -1
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -0
- package/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/Field/utils/index.d.ts +4 -0
- package/Field/utils/index.js +49 -116
- package/Field/utils/index.js.map +7 -0
- package/Field/utils/useField/index.js +64 -0
- package/{FormBuilder/FormBuilder → Field/utils/useField}/package.json +1 -1
- package/Field/utils/useField.d.ts +2 -0
- package/Field/utils/useField.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +3 -2
- package/FieldArray/FormDialog/index.js +399 -0
- package/{validators/validators.spec → FieldArray/FormDialog}/package.json +1 -1
- package/FieldArray/FormDialog.d.ts +67 -0
- package/FieldArray/FormDialog.js.map +7 -0
- package/FieldArray/__stories__/Default.d.ts +2 -2
- package/FieldArray/__stories__/WithExactLength.d.ts +2 -2
- package/FieldArray/__stories__/WithModal.d.ts +2 -0
- package/FieldArray/index.d.ts +7 -0
- package/FieldArray/index.js +113 -59
- package/FieldArray/index.js.map +7 -0
- package/FieldArray/index.test.d.ts +1 -0
- package/FieldObject/index.d.ts +8 -0
- package/FieldObject/index.js +85 -52
- package/FieldObject/index.js.map +7 -0
- package/Fieldset/FieldsetWithContext/index.js +27 -31
- package/Fieldset/FieldsetWithContext.js.map +7 -0
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +27 -29
- package/Fieldset/index.js.map +7 -0
- package/Fieldset/types/index.js +1 -1
- package/Fieldset/types.d.ts +3 -2
- package/Fieldset/types.js.map +7 -0
- package/FormBuilder/FormBuilder.stories.d.ts +5 -1
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
- package/FormBuilder/__stories__/Default.d.ts +2 -2
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
- package/FormBuilder/index.d.ts +8 -1
- package/FormBuilder/index.js +241 -2
- package/FormBuilder/index.js.map +7 -0
- package/FormBuilder/index.test.d.ts +1 -0
- package/FormBuilder/interaction.test.d.ts +1 -0
- package/FormBuilder/scenarios.test.d.ts +88 -0
- package/FormContext/index.js +11 -3
- package/FormContext.d.ts +1 -0
- package/FormContext.js.map +7 -0
- package/MultiplicityField/MultiplicityField.stories.d.ts +8 -6
- package/MultiplicityField/__stories__/Default.d.ts +2 -2
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +2 -2
- package/MultiplicityField/__stories__/WithExactLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMinLength.d.ts +2 -2
- package/MultiplicityField/add-objects/index.js +139 -132
- package/MultiplicityField/add-objects.d.ts +2 -1
- package/MultiplicityField/add-objects.js.map +7 -0
- package/MultiplicityField/index.d.ts +2 -19
- package/MultiplicityField/index.js +117 -106
- package/MultiplicityField/index.js.map +7 -0
- package/MultiplicityField/index.test.d.ts +1 -0
- package/MultiplicityField/types/index.js +1 -0
- package/MultiplicityField/types/package.json +6 -0
- package/MultiplicityField/types.d.ts +19 -0
- package/MultiplicityField/types.js.map +7 -0
- package/Questions/Questions/index.js +48 -56
- package/Questions/Questions.js.map +7 -0
- package/Questions/Questions.stories.d.ts +3 -1
- package/Questions/QuestionsContext/index.js +9 -9
- package/Questions/QuestionsContext.d.ts +0 -1
- package/Questions/QuestionsContext.js.map +7 -0
- package/Questions/Step/ReviewStep/index.js +35 -47
- package/Questions/Step/ReviewStep.js.map +7 -0
- package/Questions/Step/Step/index.js +39 -47
- package/Questions/Step/Step.js.map +7 -0
- package/Questions/Step/StepArrayReview/index.js +41 -45
- package/Questions/Step/StepArrayReview.js.map +7 -0
- package/Questions/Step/StepContext/index.js +15 -19
- package/Questions/Step/StepContext.d.ts +0 -1
- package/Questions/Step/StepContext.js.map +7 -0
- package/Questions/Step/StepDescription/index.js +22 -22
- package/Questions/Step/StepDescription.js.map +7 -0
- package/Questions/Step/StepForm/index.js +33 -43
- package/Questions/Step/StepForm.js.map +7 -0
- package/Questions/Step/StepQuote/index.js +10 -9
- package/Questions/Step/StepQuote.js.map +7 -0
- package/Questions/Step/StepTitle/index.js +41 -38
- package/Questions/Step/StepTitle.d.ts +2 -1
- package/Questions/Step/StepTitle.js.map +7 -0
- package/Questions/Step/getAddMoreFields/index.js +28 -20
- package/Questions/Step/getAddMoreFields.js.map +7 -0
- package/Questions/Step/index.d.ts +0 -1
- package/Questions/Step/index.js +16 -13
- package/Questions/Step/index.js.map +7 -0
- package/Questions/Step/types/index.js +1 -1
- package/Questions/Step/types.d.ts +1 -0
- package/Questions/Step/types.js.map +7 -0
- package/Questions/__stories__/Default.d.ts +2 -2
- package/Questions/getNextStep/index.js +12 -10
- package/Questions/getNextStep.js.map +7 -0
- package/Questions/index.js +7 -3
- package/Questions/index.js.map +7 -0
- package/Questions/index.test.d.ts +1 -0
- package/Questions/types/index.js +1 -1
- package/Questions/types.d.ts +1 -0
- package/Questions/types.js.map +7 -0
- package/cjs/Field/ErrorGroup/index.js +82 -0
- package/cjs/Field/ErrorGroup.js.map +7 -0
- package/cjs/Field/FieldBase/index.js +148 -83
- package/cjs/Field/FieldBase.js.map +7 -0
- package/cjs/Field/FieldBaseContainer/index.js +79 -43
- package/cjs/Field/FieldBaseContainer.js.map +7 -0
- package/cjs/Field/FieldConditional/index.js +115 -59
- package/cjs/Field/FieldConditional.js.map +7 -0
- package/cjs/Field/index.js +142 -72
- package/cjs/Field/index.js.map +7 -0
- package/cjs/Field/types/index.js +16 -5
- package/cjs/Field/types.js.map +7 -0
- package/cjs/Field/utils/calculateField/index.js +50 -0
- package/cjs/Field/utils/calculateField.js.map +7 -0
- package/cjs/Field/utils/evaluateFieldWithConditions/index.js +49 -0
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/cjs/Field/utils/index.js +92 -133
- package/cjs/Field/utils/index.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +87 -0
- package/cjs/Field/utils/useField.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +418 -0
- package/cjs/FieldArray/FormDialog.js.map +7 -0
- package/cjs/FieldArray/index.js +145 -65
- package/cjs/FieldArray/index.js.map +7 -0
- package/cjs/FieldObject/index.js +114 -61
- package/cjs/FieldObject/index.js.map +7 -0
- package/cjs/Fieldset/FieldsetWithContext/index.js +54 -40
- package/cjs/Fieldset/FieldsetWithContext.js.map +7 -0
- package/cjs/Fieldset/index.js +61 -39
- package/cjs/Fieldset/index.js.map +7 -0
- package/cjs/Fieldset/types/index.js +16 -5
- package/cjs/Fieldset/types.js.map +7 -0
- package/cjs/FormBuilder/index.js +277 -8
- package/cjs/FormBuilder/index.js.map +7 -0
- package/cjs/FormContext/index.js +34 -8
- package/cjs/FormContext.js.map +7 -0
- package/cjs/MultiplicityField/add-objects/index.js +166 -138
- package/cjs/MultiplicityField/add-objects.js.map +7 -0
- package/cjs/MultiplicityField/index.js +145 -115
- package/cjs/MultiplicityField/index.js.map +7 -0
- package/cjs/MultiplicityField/types/index.js +16 -0
- package/cjs/MultiplicityField/types.js.map +7 -0
- package/cjs/Questions/Questions/index.js +80 -65
- package/cjs/Questions/Questions.js.map +7 -0
- package/cjs/Questions/QuestionsContext/index.js +31 -14
- package/cjs/Questions/QuestionsContext.js.map +7 -0
- package/cjs/Questions/Step/ReviewStep/index.js +61 -56
- package/cjs/Questions/Step/ReviewStep.js.map +7 -0
- package/cjs/Questions/Step/Step/index.js +71 -56
- package/cjs/Questions/Step/Step.js.map +7 -0
- package/cjs/Questions/Step/StepArrayReview/index.js +65 -54
- package/cjs/Questions/Step/StepArrayReview.js.map +7 -0
- package/cjs/Questions/Step/StepContext/index.js +37 -24
- package/cjs/Questions/Step/StepContext.js.map +7 -0
- package/cjs/Questions/Step/StepDescription/index.js +55 -31
- package/cjs/Questions/Step/StepDescription.js.map +7 -0
- package/cjs/Questions/Step/StepForm/index.js +65 -52
- package/cjs/Questions/Step/StepForm.js.map +7 -0
- package/cjs/Questions/Step/StepQuote/index.js +42 -15
- package/cjs/Questions/Step/StepQuote.js.map +7 -0
- package/cjs/Questions/Step/StepTitle/index.js +72 -47
- package/cjs/Questions/Step/StepTitle.js.map +7 -0
- package/cjs/Questions/Step/getAddMoreFields/index.js +50 -25
- package/cjs/Questions/Step/getAddMoreFields.js.map +7 -0
- package/cjs/Questions/Step/index.js +59 -143
- package/cjs/Questions/Step/index.js.map +7 -0
- package/cjs/Questions/Step/types/index.js +16 -5
- package/cjs/Questions/Step/types.js.map +7 -0
- package/cjs/Questions/getNextStep/index.js +33 -14
- package/cjs/Questions/getNextStep.js.map +7 -0
- package/cjs/Questions/index.js +29 -19
- package/cjs/Questions/index.js.map +7 -0
- package/cjs/Questions/types/index.js +16 -5
- package/cjs/Questions/types.js.map +7 -0
- package/cjs/index.js +47 -20
- package/cjs/index.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js +92 -49
- package/cjs/inputs/AutoCompleteInput/index.js.map +7 -0
- package/cjs/inputs/Checkboxes/index.js +102 -96
- package/cjs/inputs/Checkboxes/index.js.map +7 -0
- package/cjs/inputs/DateInput/index.js +157 -115
- package/cjs/inputs/DateInput/index.js.map +7 -0
- package/cjs/inputs/DateTimeInput/index.js +245 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +115 -65
- package/cjs/inputs/FileInput/index.js.map +7 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +127 -83
- package/cjs/inputs/ImageInput/index.js.map +7 -0
- package/cjs/inputs/Input/index.js +106 -71
- package/cjs/inputs/Input/index.js.map +7 -0
- package/cjs/inputs/Label/index.js +45 -24
- package/cjs/inputs/Label/index.js.map +7 -0
- package/cjs/inputs/OtpInput/index.js +143 -113
- package/cjs/inputs/OtpInput/index.js.map +7 -0
- package/cjs/inputs/Radio/index.js +131 -61
- package/cjs/inputs/Radio/index.js.map +7 -0
- package/cjs/inputs/Select/index.js +61 -36
- package/cjs/inputs/Select/index.js.map +7 -0
- package/cjs/inputs/index.js +62 -69
- package/cjs/inputs/index.js.map +7 -0
- package/cjs/inputs/inputsScenarios/index.js +533 -0
- package/cjs/inputs/inputsScenarios.js.map +7 -0
- package/cjs/internal/index.js +36 -346
- package/cjs/internal.js.map +7 -0
- package/cjs/lazy/index.js +110 -516
- package/cjs/lazy.js.map +7 -0
- package/cjs/locales/el/index.js +35 -0
- package/cjs/locales/el.js.map +7 -0
- package/cjs/registry/index.js +190 -142
- package/cjs/registry.js.map +7 -0
- package/cjs/types/index.js +22 -5
- package/cjs/types.js.map +7 -0
- package/cjs/utils/index.js +93 -83
- package/cjs/utils.js.map +7 -0
- package/cjs/validators/index.js +139 -167
- package/cjs/validators/index.js.map +7 -0
- package/cjs/validators/types/index.js +16 -5
- package/cjs/validators/types.js.map +7 -0
- package/cjs/validators/utils/afm/index.js +38 -21
- package/cjs/validators/utils/afm.js.map +7 -0
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +156 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/datetime/index.js +240 -0
- package/cjs/validators/utils/datetime.js.map +7 -0
- package/cjs/validators/utils/file/index.js +48 -30
- package/cjs/validators/utils/file.js.map +7 -0
- package/cjs/validators/utils/iban/index.js +36 -17
- package/cjs/validators/utils/iban.js.map +7 -0
- package/cjs/validators/utils/image/index.js +88 -112
- package/cjs/validators/utils/image.js.map +7 -0
- package/cjs/validators/utils/index.js +103 -159
- package/cjs/validators/utils/index.js.map +7 -0
- package/cjs/validators/utils/int/index.js +35 -13
- package/cjs/validators/utils/int.js.map +7 -0
- package/cjs/validators/utils/number/index.js +34 -12
- package/cjs/validators/utils/number.js.map +7 -0
- package/cjs/validators/utils/otp/index.js +35 -13
- package/cjs/validators/utils/otp.js.map +7 -0
- package/cjs/validators/utils/phone/index.js +113 -58
- package/cjs/validators/utils/phone.js.map +7 -0
- package/cjs/validators/utils/postal_code/index.js +36 -16
- package/cjs/validators/utils/postal_code.js.map +7 -0
- package/cjs/validators/utils/text_limit/index.js +40 -25
- package/cjs/validators/utils/text_limit.js.map +7 -0
- package/cjs/validators/utils/uuid4/index.js +34 -13
- package/cjs/validators/utils/uuid4.js.map +7 -0
- package/index.d.ts +4 -1
- package/index.js +13 -4
- package/index.js.map +7 -0
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +4 -2
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +2 -2
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +2 -2
- package/inputs/AutoCompleteInput/index.d.ts +2 -2
- package/inputs/AutoCompleteInput/index.js +62 -40
- package/inputs/AutoCompleteInput/index.js.map +7 -0
- package/inputs/AutoCompleteInput/index.test.d.ts +1 -0
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +5 -3
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +2 -2
- package/inputs/Checkboxes/__stories__/Default.d.ts +2 -2
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Checkboxes/index.d.ts +2 -1
- package/inputs/Checkboxes/index.js +74 -87
- package/inputs/Checkboxes/index.js.map +7 -0
- package/inputs/Checkboxes/index.test.d.ts +1 -0
- package/inputs/DateInput/DateInput.stories.d.ts +7 -1
- package/inputs/DateInput/__stories__/Default.d.ts +2 -2
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateInput/index.d.ts +3 -4
- package/inputs/DateInput/index.js +127 -105
- package/inputs/DateInput/index.js.map +7 -0
- package/inputs/DateInput/index.test.d.ts +1 -0
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
- package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.d.ts +13 -0
- package/inputs/DateTimeInput/index.js +215 -0
- package/inputs/DateTimeInput/index.js.map +7 -0
- package/inputs/DateTimeInput/index.test.d.ts +1 -0
- package/inputs/DateTimeInput/package.json +6 -0
- package/inputs/FileInput/FileInput.stories.d.ts +4 -1
- package/inputs/FileInput/__stories__/Default.d.ts +2 -2
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +17 -1
- package/inputs/FileInput/index.js +86 -56
- package/inputs/FileInput/index.js.map +7 -0
- package/inputs/FileInput/index.test.d.ts +1 -0
- package/inputs/ImageInput/ImageInput.stories.d.ts +6 -3
- package/inputs/ImageInput/__stories__/Default.d.ts +2 -2
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +2 -2
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/{FileInput/__stories__/Default → ImageInput/__stories__/logo.d}/package.json +1 -1
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +9 -1
- package/inputs/ImageInput/index.js +95 -75
- package/inputs/ImageInput/index.js.map +7 -0
- package/inputs/ImageInput/index.test.d.ts +1 -0
- package/inputs/Input/Input.stories.d.ts +15 -10
- package/inputs/Input/__stories__/AFM.d.ts +2 -2
- package/inputs/Input/__stories__/AMKA.d.ts +3 -0
- package/inputs/Input/__stories__/Boolean.d.ts +2 -2
- package/inputs/Input/__stories__/Email.d.ts +3 -0
- package/inputs/Input/__stories__/IBAN.d.ts +2 -2
- package/inputs/Input/__stories__/Integer.d.ts +2 -2
- package/inputs/Input/__stories__/LandlineNumber.d.ts +2 -2
- package/inputs/Input/__stories__/MobilePhone.d.ts +2 -2
- package/inputs/Input/__stories__/PhoneNumber.d.ts +2 -2
- package/inputs/Input/__stories__/PostalCode.d.ts +2 -2
- package/inputs/Input/__stories__/String.d.ts +3 -0
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +3 -0
- package/inputs/Input/index.d.ts +2 -1
- package/inputs/Input/index.js +75 -66
- package/inputs/Input/index.js.map +7 -0
- package/inputs/Input/index.test.d.ts +1 -0
- package/inputs/Label/Label.stories.d.ts +3 -1
- package/inputs/Label/__stories__/Default.d.ts +2 -2
- package/inputs/Label/index.d.ts +1 -3
- package/inputs/Label/index.js +12 -17
- package/inputs/Label/index.js.map +7 -0
- package/inputs/Label/index.test.d.ts +1 -0
- package/inputs/OtpInput/OtpInput.stories.d.ts +3 -1
- package/inputs/OtpInput/__stories__/Default.d.ts +2 -2
- package/inputs/OtpInput/index.d.ts +1 -1
- package/inputs/OtpInput/index.js +111 -104
- package/inputs/OtpInput/index.js.map +7 -0
- package/inputs/OtpInput/index.test.d.ts +1 -0
- package/inputs/Radio/Radio.stories.d.ts +5 -3
- package/inputs/Radio/__stories__/Conditional.d.ts +2 -2
- package/inputs/Radio/__stories__/Default.d.ts +2 -2
- package/inputs/Radio/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Radio/index.d.ts +6 -1
- package/inputs/Radio/index.js +102 -55
- package/inputs/Radio/index.js.map +7 -0
- package/inputs/Radio/index.test.d.ts +1 -0
- package/inputs/Select/Select.stories.d.ts +3 -1
- package/inputs/Select/__stories__/Default.d.ts +2 -2
- package/inputs/Select/index.d.ts +3 -2
- package/inputs/Select/index.js +33 -31
- package/inputs/Select/index.js.map +7 -0
- package/inputs/Select/index.test.d.ts +1 -0
- package/inputs/index.js +21 -9
- package/inputs/index.js.map +7 -0
- package/inputs/inputsScenarios/index.js +499 -0
- package/inputs/inputsScenarios/package.json +6 -0
- package/inputs/inputsScenarios.d.ts +296 -0
- package/inputs/inputsScenarios.js.map +7 -0
- package/internal/index.js +10 -34
- package/internal.d.ts +2 -31
- package/internal.js.map +7 -0
- package/lazy/index.js +76 -393
- package/locales/el/index.js +6 -0
- package/{Form.stories → locales/el}/package.json +1 -1
- package/locales/el.d.ts +2 -0
- package/locales/el.js.map +7 -0
- package/package.json +8 -9
- package/registry/index.js +125 -98
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +40 -23
- package/src/Field/FieldBaseContainer.tsx +22 -8
- package/src/Field/FieldConditional.tsx +9 -1
- package/src/Field/doc.mdx +207 -0
- package/src/Field/index.tsx +40 -6
- package/src/Field/types.tsx +82 -5
- package/src/Field/utils/calculateField.ts +49 -0
- package/src/Field/utils/evaluateFieldWithConditions.ts +30 -0
- package/src/Field/utils/index.ts +84 -0
- package/src/Field/utils/useField.ts +66 -0
- package/src/FieldArray/FieldArray.stories.js +3 -2
- package/src/FieldArray/FormDialog.tsx +568 -0
- package/src/FieldArray/__stories__/Default.tsx +2 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
- package/src/FieldArray/__stories__/WithModal.tsx +160 -0
- package/src/FieldArray/index.test.tsx +32 -0
- package/src/FieldArray/index.tsx +99 -50
- package/src/FieldObject/index.tsx +56 -22
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +5 -3
- package/src/FormBuilder/FormBuilder.stories.js +6 -1
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/{FormBuilder/FormBuilder.mdx → src/FormBuilder/doc.mdx} +27 -35
- package/src/FormBuilder/index.test.tsx +32 -0
- package/src/FormBuilder/index.tsx +268 -1
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1978 -0
- package/src/FormContext.tsx +5 -2
- package/src/MultiplicityField/MultiplicityField.stories.js +9 -6
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +3 -3
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +2 -2
- package/src/MultiplicityField/add-objects.tsx +33 -15
- package/{MultiplicityField/MultiplicityField.mdx → src/MultiplicityField/doc.mdx} +112 -98
- package/src/MultiplicityField/index.test.tsx +44 -0
- package/src/MultiplicityField/index.tsx +24 -34
- package/src/MultiplicityField/types.ts +22 -0
- package/src/Questions/Questions.stories.js +4 -1
- package/src/Questions/Questions.tsx +4 -4
- package/src/Questions/Step/StepArrayReview.tsx +1 -1
- package/src/Questions/Step/StepTitle.tsx +5 -3
- package/src/Questions/Step/index.ts +0 -1
- package/src/Questions/Step/types.tsx +1 -0
- package/src/Questions/__snapshots__/index.spec.tsx.snap +74 -587
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/Questions/{index.mdx → doc.mdx} +34 -57
- package/src/Questions/index.spec.tsx +17 -5
- package/src/Questions/index.test.tsx +24 -0
- package/src/Questions/types.tsx +1 -0
- package/src/create-simple-form.mdx +2 -6
- package/{index.mdx → src/doc.mdx} +29 -18
- package/src/index.ts +4 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +5 -2
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +3 -10
- package/{inputs/AutoCompleteInput/index.mdx → src/inputs/AutoCompleteInput/doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.test.tsx +28 -0
- package/src/inputs/AutoCompleteInput/index.tsx +47 -31
- package/src/inputs/Checkboxes/Checkboxes.stories.js +6 -3
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.test.tsx +32 -0
- package/src/inputs/Checkboxes/index.tsx +34 -31
- package/src/inputs/DateInput/DateInput.stories.js +8 -1
- package/src/inputs/DateInput/__stories__/Default.tsx +17 -16
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.test.tsx +40 -0
- package/src/inputs/DateInput/index.tsx +60 -23
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/doc.mdx +16 -0
- package/src/inputs/DateTimeInput/index.test.tsx +40 -0
- package/src/inputs/DateTimeInput/index.tsx +233 -0
- package/src/inputs/FileInput/FileInput.stories.js +5 -1
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.test.tsx +28 -0
- package/src/inputs/FileInput/index.tsx +106 -41
- package/src/inputs/ImageInput/ImageInput.stories.js +7 -3
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → MaxSize.tsx} +5 -3
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +3 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.test.tsx +36 -0
- package/src/inputs/ImageInput/index.tsx +103 -50
- package/src/inputs/Input/Input.stories.js +16 -10
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +3 -2
- package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +2 -1
- package/src/inputs/Input/__stories__/{Default.tsx → String.tsx} +2 -2
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/{TextWithCharacterLimit.tsx → TextWithLimit.tsx} +3 -2
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.test.tsx +72 -0
- package/src/inputs/Input/index.tsx +44 -31
- package/src/inputs/Label/Label.stories.js +4 -1
- package/src/inputs/Label/__stories__/Default.tsx +4 -2
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.test.tsx +24 -0
- package/src/inputs/Label/index.tsx +3 -10
- package/src/inputs/OtpInput/OtpInput.stories.js +4 -1
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/{inputs/OtpInput/index.mdx → src/inputs/OtpInput/doc.mdx} +1 -8
- package/src/inputs/OtpInput/index.test.tsx +24 -0
- package/src/inputs/OtpInput/index.tsx +3 -1
- package/src/inputs/Radio/Radio.stories.js +6 -3
- package/src/inputs/Radio/__stories__/Conditional.tsx +3 -2
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/{cjs/inputs/Radio/index.mdx → src/inputs/Radio/doc.mdx} +5 -15
- package/src/inputs/Radio/index.test.tsx +32 -0
- package/src/inputs/Radio/index.tsx +79 -9
- package/src/inputs/Select/Select.stories.js +4 -1
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/{inputs/Select/index.mdx → src/inputs/Select/doc.mdx} +1 -5
- package/src/inputs/Select/index.test.tsx +24 -0
- package/src/inputs/Select/index.tsx +18 -7
- package/src/inputs/inputsScenarios.ts +496 -0
- package/src/installation.mdx +2 -5
- package/src/internal.ts +2 -31
- package/src/lazy.js +77 -59
- package/src/locales/el.ts +3 -0
- package/src/registry.js +108 -88
- package/src/types.tsx +13 -65
- package/src/utils.ts +55 -33
- package/src/validators/index.ts +107 -90
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +126 -0
- package/src/validators/utils/datetime.ts +217 -0
- package/src/validators/utils/file.ts +33 -17
- package/src/validators/utils/index.ts +6 -1
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/phone.ts +63 -72
- package/src/validators/utils/postal_code.ts +1 -1
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +6 -40
- package/types/index.js +2 -1
- package/types.d.ts +8 -36
- package/types.js.map +7 -0
- package/utils/index.js +71 -77
- package/utils.d.ts +2 -0
- package/utils.js.map +7 -0
- package/validators/index.d.ts +1 -1
- package/validators/index.js +121 -153
- package/validators/index.js.map +7 -0
- package/validators/types/index.js +1 -1
- package/validators/types.js.map +7 -0
- package/validators/utils/afm/index.js +16 -16
- package/validators/utils/afm.js.map +7 -0
- package/validators/utils/amka/index.js +36 -0
- package/validators/utils/amka/package.json +6 -0
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +121 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/datetime/index.js +205 -0
- package/{Questions/Questions.stories → validators/utils/datetime}/package.json +1 -1
- package/validators/utils/datetime.d.ts +9 -0
- package/validators/utils/datetime.js.map +7 -0
- package/validators/utils/file/index.js +26 -25
- package/validators/utils/file.js.map +7 -0
- package/validators/utils/iban/index.js +14 -12
- package/validators/utils/iban.js.map +7 -0
- package/validators/utils/image/index.js +66 -106
- package/validators/utils/image.js.map +7 -0
- package/validators/utils/index.d.ts +3 -0
- package/validators/utils/index.js +59 -48
- package/validators/utils/index.js.map +7 -0
- package/validators/utils/int/index.js +13 -8
- package/validators/utils/int.js.map +7 -0
- package/validators/utils/number/index.js +12 -7
- package/validators/utils/number.js.map +7 -0
- package/validators/utils/otp/index.js +13 -8
- package/validators/utils/otp.js.map +7 -0
- package/validators/utils/phone/index.js +89 -51
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/phone.js.map +7 -0
- package/validators/utils/postal_code/index.js +14 -11
- package/validators/utils/postal_code.d.ts +1 -1
- package/validators/utils/postal_code.js.map +7 -0
- package/validators/utils/text_limit/index.js +18 -20
- package/validators/utils/text_limit.js.map +7 -0
- package/validators/utils/uuid4/index.js +12 -8
- package/validators/utils/uuid4.js.map +7 -0
- package/Field/index.mdx +0 -6
- package/Field/utils.d.ts +0 -5
- package/FieldArray/FieldArray.stories/index.js +0 -8
- package/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/FieldArray/__stories__/Default/index.js +0 -88
- package/FieldArray/__stories__/Default/package.json +0 -6
- package/FieldArray/__stories__/WithExactLength/index.js +0 -88
- package/FieldArray/__stories__/WithExactLength/package.json +0 -6
- package/Form.stories/index.js +0 -3
- package/FormBuilder/FormBuilder/index.js +0 -152
- package/FormBuilder/FormBuilder.d.ts +0 -5
- package/FormBuilder/FormBuilder.stories/index.js +0 -7
- package/FormBuilder/FormBuilder.stories/package.json +0 -6
- package/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/FormBuilder/__stories__/Default/index.js +0 -26
- package/FormBuilder/__stories__/Default/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories/index.js +0 -12
- package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/MultiplicityField/__stories__/Default/index.js +0 -95
- package/MultiplicityField/__stories__/Default/package.json +0 -6
- package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -72
- package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
- package/MultiplicityField/__stories__/WithExactLength/index.js +0 -90
- package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -94
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
- package/Questions/Questions.stories/index.js +0 -7
- package/Questions/__snapshots__/index.spec.tsx.snap +0 -596
- package/Questions/__stories__/Default/index.js +0 -102
- package/Questions/__stories__/Default/package.json +0 -6
- package/Questions/index.mdx +0 -415
- package/Questions/index.spec/index.js +0 -59
- package/cjs/Field/index.mdx +0 -6
- package/cjs/FieldArray/FieldArray.stories/index.js +0 -38
- package/cjs/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/cjs/FieldArray/__stories__/Default/index.js +0 -98
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -98
- package/cjs/Form.stories/index.js +0 -9
- package/cjs/FormBuilder/FormBuilder/index.js +0 -162
- package/cjs/FormBuilder/FormBuilder.mdx +0 -256
- package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -26
- package/cjs/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/cjs/FormBuilder/__stories__/Default/index.js +0 -36
- package/cjs/MultiplicityField/MultiplicityField.mdx +0 -590
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -86
- package/cjs/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -105
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -82
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -100
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -103
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -104
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -103
- package/cjs/Questions/Questions.stories/index.js +0 -26
- package/cjs/Questions/__snapshots__/index.spec.tsx.snap +0 -596
- package/cjs/Questions/__stories__/Default/index.js +0 -113
- package/cjs/Questions/index.mdx +0 -415
- package/cjs/Questions/index.spec/index.js +0 -63
- package/cjs/create-simple-form.mdx +0 -539
- package/cjs/index.mdx +0 -51
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -38
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -51
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -52
- package/cjs/inputs/AutoCompleteInput/index.mdx +0 -29
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -50
- package/cjs/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -103
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -50
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -51
- package/cjs/inputs/Checkboxes/index.mdx +0 -33
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -26
- package/cjs/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -33
- package/cjs/inputs/DateInput/index.mdx +0 -23
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -26
- package/cjs/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -30
- package/cjs/inputs/FileInput/index.mdx +0 -19
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -50
- package/cjs/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -38
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -46
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -43
- package/cjs/inputs/ImageInput/index.mdx +0 -19
- package/cjs/inputs/Input/Input.stories/index.js +0 -134
- package/cjs/inputs/Input/Input.stories.playwright.json +0 -376
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -32
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Default/index.js +0 -33
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -41
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -36
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -36
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -35
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -35
- package/cjs/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -39
- package/cjs/inputs/Input/index.mdx +0 -95
- package/cjs/inputs/Label/Label.stories/index.js +0 -26
- package/cjs/inputs/Label/Label.stories.playwright.json +0 -40
- package/cjs/inputs/Label/__stories__/Default/index.js +0 -37
- package/cjs/inputs/Label/index.mdx +0 -0
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -26
- package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -39
- package/cjs/inputs/OtpInput/index.mdx +0 -23
- package/cjs/inputs/Radio/Radio.stories/index.js +0 -50
- package/cjs/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -103
- package/cjs/inputs/Radio/__stories__/Default/index.js +0 -55
- package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -56
- package/cjs/inputs/Select/Select.stories/index.js +0 -26
- package/cjs/inputs/Select/Select.stories.playwright.json +0 -22
- package/cjs/inputs/Select/__stories__/Default/index.js +0 -61
- package/cjs/inputs/Select/index.mdx +0 -17
- package/cjs/installation.mdx +0 -68
- package/cjs/validators/validators.spec/index.js +0 -87
- package/create-simple-form.mdx +0 -539
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -8
- package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -44
- package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -45
- package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -9
- package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -93
- package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Default/index.js +0 -40
- package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -41
- package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
- package/inputs/Checkboxes/index.mdx +0 -33
- package/inputs/DateInput/DateInput.stories/index.js +0 -7
- package/inputs/DateInput/DateInput.stories/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/inputs/DateInput/__stories__/Default/index.js +0 -23
- package/inputs/DateInput/index.mdx +0 -23
- package/inputs/FileInput/FileInput.stories/index.js +0 -7
- package/inputs/FileInput/FileInput.stories/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/inputs/FileInput/__stories__/Default/index.js +0 -20
- package/inputs/FileInput/index.mdx +0 -19
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -9
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/inputs/ImageInput/__stories__/Default/index.js +0 -28
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -36
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -33
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/index.mdx +0 -19
- package/inputs/Input/Input.stories/index.js +0 -16
- package/inputs/Input/Input.stories/package.json +0 -6
- package/inputs/Input/Input.stories.playwright.json +0 -376
- package/inputs/Input/__stories__/AFM/index.js +0 -22
- package/inputs/Input/__stories__/AFM/package.json +0 -6
- package/inputs/Input/__stories__/Boolean/index.js +0 -23
- package/inputs/Input/__stories__/Boolean/package.json +0 -6
- package/inputs/Input/__stories__/Default/index.js +0 -23
- package/inputs/Input/__stories__/Default/package.json +0 -6
- package/inputs/Input/__stories__/Default.d.ts +0 -3
- package/inputs/Input/__stories__/IBAN/index.js +0 -23
- package/inputs/Input/__stories__/IBAN/package.json +0 -6
- package/inputs/Input/__stories__/Integer/index.js +0 -31
- package/inputs/Input/__stories__/Integer/package.json +0 -6
- package/inputs/Input/__stories__/LandlineNumber/index.js +0 -26
- package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
- package/inputs/Input/__stories__/MobilePhone/index.js +0 -26
- package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
- package/inputs/Input/__stories__/PhoneNumber/index.js +0 -25
- package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
- package/inputs/Input/__stories__/PostalCode/index.js +0 -25
- package/inputs/Input/__stories__/PostalCode/package.json +0 -6
- package/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -29
- package/inputs/Input/__stories__/TextWithCharacterLimit/package.json +0 -6
- package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +0 -3
- package/inputs/Input/index.mdx +0 -95
- package/inputs/Label/Label.stories/index.js +0 -7
- package/inputs/Label/Label.stories/package.json +0 -6
- package/inputs/Label/Label.stories.playwright.json +0 -40
- package/inputs/Label/__stories__/Default/index.js +0 -27
- package/inputs/Label/__stories__/Default/package.json +0 -6
- package/inputs/Label/index.mdx +0 -0
- package/inputs/OtpInput/OtpInput.stories/index.js +0 -7
- package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
- package/inputs/OtpInput/__stories__/Default/index.js +0 -29
- package/inputs/OtpInput/__stories__/Default/package.json +0 -6
- package/inputs/Radio/Radio.stories/index.js +0 -9
- package/inputs/Radio/Radio.stories/package.json +0 -6
- package/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/inputs/Radio/__stories__/Conditional/index.js +0 -93
- package/inputs/Radio/__stories__/Conditional/package.json +0 -6
- package/inputs/Radio/__stories__/Default/index.js +0 -45
- package/inputs/Radio/__stories__/Default/package.json +0 -6
- package/inputs/Radio/__stories__/WithDivider/index.js +0 -46
- package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
- package/inputs/Radio/index.mdx +0 -33
- package/inputs/Select/Select.stories/index.js +0 -7
- package/inputs/Select/Select.stories/package.json +0 -6
- package/inputs/Select/Select.stories.playwright.json +0 -22
- package/inputs/Select/__stories__/Default/index.js +0 -51
- package/inputs/Select/__stories__/Default/package.json +0 -6
- package/installation.mdx +0 -68
- package/lazy.d.ts +0 -69
- package/registry.d.ts +0 -64
- package/src/Field/index.mdx +0 -6
- package/src/Field/utils.ts +0 -191
- package/src/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/src/FormBuilder/FormBuilder.mdx +0 -256
- package/src/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/src/FormBuilder/FormBuilder.tsx +0 -166
- package/src/MultiplicityField/MultiplicityField.mdx +0 -590
- package/src/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/src/index.mdx +0 -51
- package/src/inputs/AutoCompleteInput/index.mdx +0 -29
- package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/src/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/src/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/src/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/Input.stories.playwright.json +0 -376
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Label/Label.stories.playwright.json +0 -40
- package/src/inputs/Label/index.mdx +0 -0
- package/src/inputs/OtpInput/index.mdx +0 -23
- package/src/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/src/inputs/Radio/index.mdx +0 -33
- package/src/inputs/Select/Select.stories.playwright.json +0 -22
- package/src/inputs/Select/index.mdx +0 -17
- package/validators/validators.spec/index.js +0 -85
package/src/utils.ts
CHANGED
|
@@ -13,6 +13,7 @@ const parseErrorSchema = (
|
|
|
13
13
|
return (error.inner || []).reduce<Record<string, FieldError>>(
|
|
14
14
|
(previous, error) => {
|
|
15
15
|
error.path = error.path?.replace(/\[([0-9]+)\]/g, '.$1');
|
|
16
|
+
// error.path = error.path?.replace(/\["(.*?)"\]/g, '$1');
|
|
16
17
|
if (!previous[error.path!]) {
|
|
17
18
|
previous[error.path!] = { message: error.message, type: error.type! };
|
|
18
19
|
}
|
|
@@ -37,42 +38,63 @@ const parseErrorSchema = (
|
|
|
37
38
|
{}
|
|
38
39
|
);
|
|
39
40
|
};
|
|
41
|
+
function isPlainObject(obj) {
|
|
42
|
+
return (
|
|
43
|
+
typeof obj === 'object' &&
|
|
44
|
+
obj !== null &&
|
|
45
|
+
Object.prototype.toString.call(obj) === '[object Object]'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function flattenObject(obj, prefix = '') {
|
|
49
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
50
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
) => async (values, context, options) => {
|
|
46
|
-
try {
|
|
47
|
-
if (schemaOptions.context && process.env.NODE_ENV === 'development') {
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.warn(
|
|
50
|
-
"You should not used the yup options context. Please, use the 'useForm' context object instead"
|
|
51
|
-
);
|
|
52
|
+
if (isPlainObject(obj[key])) {
|
|
53
|
+
Object.assign(acc, flattenObject(obj[key], prefixedKey));
|
|
54
|
+
} else {
|
|
55
|
+
acc[prefixedKey] = obj[key];
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
export const yupResolver =
|
|
63
|
+
(schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>
|
|
64
|
+
async (values, context, options) => {
|
|
65
|
+
try {
|
|
66
|
+
if (schemaOptions.context && process.env.NODE_ENV === 'development') {
|
|
67
|
+
console.warn(
|
|
68
|
+
"You should not used the yup options context. Please, use the 'useForm' context object instead"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
59
71
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw e;
|
|
67
|
-
}
|
|
72
|
+
const result = await schema[
|
|
73
|
+
resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'
|
|
74
|
+
](
|
|
75
|
+
flattenObject(values),
|
|
76
|
+
Object.assign({ abortEarly: false }, schemaOptions, { context })
|
|
77
|
+
);
|
|
68
78
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (options.shouldUseNativeValidation)
|
|
80
|
+
validateFieldsNatively({}, options);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
values: resolverOptions.rawValues ? values : result,
|
|
84
|
+
errors: {},
|
|
85
|
+
};
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (!e.inner) {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
values: {},
|
|
93
|
+
errors: parseErrorSchema(
|
|
94
|
+
e,
|
|
95
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all'
|
|
96
|
+
),
|
|
97
|
+
options,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
package/src/validators/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, useMemo } from 'react';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
2
|
import * as yup from 'yup';
|
|
5
3
|
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
6
4
|
import { RequiredArraySchema } from 'yup/lib/array';
|
|
@@ -13,6 +11,7 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
|
13
11
|
import {
|
|
14
12
|
getYupObjectShape,
|
|
15
13
|
AFM_VALIDATOR,
|
|
14
|
+
AMKA_VALIDATOR,
|
|
16
15
|
FILE_MAX_SIZE_VALIDATOR,
|
|
17
16
|
IBAN_VALIDATOR,
|
|
18
17
|
OTP_VALIDATOR,
|
|
@@ -22,24 +21,25 @@ import {
|
|
|
22
21
|
POSTALCODE_VALIDATOR,
|
|
23
22
|
UUID4_VALIDATOR,
|
|
24
23
|
IMAGE_DIMENSION_VALIDATOR,
|
|
24
|
+
DATE_VALIDATOR,
|
|
25
|
+
LATER_THAN_VALIDATOR,
|
|
26
|
+
EARLIER_THAN_VALIDATOR,
|
|
27
|
+
DATETIME_VALIDATOR,
|
|
28
|
+
LATER_THAN_DATETIME_VALIDATOR,
|
|
29
|
+
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
25
30
|
} from '@digigov/form/validators/utils';
|
|
26
31
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
27
32
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
28
|
-
dayjs.extend(customParseFormat);
|
|
29
33
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const getYUPTypeMap = (): Record<string, any> => {
|
|
34
|
+
export const getYUPTypeMap = (
|
|
35
|
+
validatorRegistry?: Record<string, any>
|
|
36
|
+
): Record<string, any> => {
|
|
37
37
|
const yupTypeMap = {
|
|
38
38
|
file: (field): MixedSchema => {
|
|
39
39
|
return yup
|
|
40
40
|
.mixed()
|
|
41
41
|
.transform((value) => {
|
|
42
|
-
if (!value.length) {
|
|
42
|
+
if (!value || value.length === 0) {
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
return value;
|
|
@@ -47,8 +47,28 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
47
47
|
.nullable()
|
|
48
48
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
49
49
|
},
|
|
50
|
-
string: yup.
|
|
51
|
-
|
|
50
|
+
string: (field): yup.StringSchema => {
|
|
51
|
+
if (field.trim) {
|
|
52
|
+
return yup.string().trim();
|
|
53
|
+
} else {
|
|
54
|
+
return yup.string();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
boolean: (): yup.BooleanSchema<
|
|
58
|
+
boolean | null | undefined,
|
|
59
|
+
AnyObject,
|
|
60
|
+
boolean | null | undefined
|
|
61
|
+
> => {
|
|
62
|
+
return yup
|
|
63
|
+
.boolean()
|
|
64
|
+
.nullable()
|
|
65
|
+
.transform((value) => {
|
|
66
|
+
if (value === '' || typeof value === 'string') return null;
|
|
67
|
+
if (typeof value === 'boolean') return value;
|
|
68
|
+
if (value === 0 || value === 1) return Boolean(value);
|
|
69
|
+
return value;
|
|
70
|
+
});
|
|
71
|
+
},
|
|
52
72
|
object: (
|
|
53
73
|
field
|
|
54
74
|
):
|
|
@@ -64,10 +84,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
64
84
|
if (typeof field.extra.of === 'object') {
|
|
65
85
|
// else if the field is an object then it is a scalar type
|
|
66
86
|
// eg. number, string etc.
|
|
87
|
+
if (field.required) {
|
|
88
|
+
field.extra.min = 1;
|
|
89
|
+
}
|
|
67
90
|
let arrayValidator = yup
|
|
68
91
|
.array()
|
|
69
|
-
.
|
|
70
|
-
.
|
|
92
|
+
.nullable()
|
|
93
|
+
.of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
71
94
|
if (field.extra.length)
|
|
72
95
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
73
96
|
key: 'form.error.array.length',
|
|
@@ -97,22 +120,46 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
97
120
|
return yup.array().of(yup.string());
|
|
98
121
|
}
|
|
99
122
|
},
|
|
123
|
+
number: (): MixedSchema =>
|
|
124
|
+
yup
|
|
125
|
+
.mixed()
|
|
126
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
127
|
+
.test(NUMBER_VALIDATOR()),
|
|
100
128
|
int: (): MixedSchema =>
|
|
101
129
|
yup
|
|
102
130
|
.mixed()
|
|
103
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
131
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
104
132
|
.test(NUMBER_VALIDATOR())
|
|
105
133
|
.test(INT_VALIDATOR()),
|
|
106
|
-
email: (): yup.StringSchema =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
email: (field): yup.StringSchema =>
|
|
135
|
+
field.trim
|
|
136
|
+
? yup.string().trim().email('form.error.email')
|
|
137
|
+
: yup.string().email('form.error.email'),
|
|
138
|
+
afm: (field): yup.StringSchema =>
|
|
139
|
+
field.trim
|
|
140
|
+
? yup.string().trim().test(AFM_VALIDATOR)
|
|
141
|
+
: yup.string().test(AFM_VALIDATOR),
|
|
142
|
+
amka: (field): yup.StringSchema =>
|
|
143
|
+
field.trim
|
|
144
|
+
? yup.string().trim().test(AMKA_VALIDATOR)
|
|
145
|
+
: yup.string().test(AMKA_VALIDATOR),
|
|
146
|
+
uuid4: (field): yup.StringSchema =>
|
|
147
|
+
field.trim
|
|
148
|
+
? yup.string().trim().test(UUID4_VALIDATOR)
|
|
149
|
+
: yup.string().test(UUID4_VALIDATOR),
|
|
150
|
+
iban: (field): yup.StringSchema =>
|
|
151
|
+
field.trim
|
|
152
|
+
? yup.string().trim().test(IBAN_VALIDATOR(field))
|
|
153
|
+
: yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
154
|
+
otp: (field): yup.StringSchema =>
|
|
155
|
+
yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
111
156
|
text: (field): yup.StringSchema => {
|
|
112
157
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
113
|
-
return
|
|
158
|
+
return field.trim
|
|
159
|
+
? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))
|
|
160
|
+
: yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
114
161
|
} else {
|
|
115
|
-
return yup.string();
|
|
162
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
116
163
|
}
|
|
117
164
|
},
|
|
118
165
|
image: (field): MixedSchema => {
|
|
@@ -129,11 +176,17 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
129
176
|
.test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
130
177
|
},
|
|
131
178
|
postal_code: (field): yup.StringSchema =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
179
|
+
field.trim
|
|
180
|
+
? yup.string().trim().test(POSTALCODE_VALIDATOR(field))
|
|
181
|
+
: yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
182
|
+
mobile_phone: (field): yup.StringSchema =>
|
|
183
|
+
field.trim
|
|
184
|
+
? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)
|
|
185
|
+
: yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
135
186
|
phone_number: (field): yup.StringSchema =>
|
|
136
|
-
|
|
187
|
+
field.trim
|
|
188
|
+
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
189
|
+
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
137
190
|
'choice:multiple': (): yup.ArraySchema<
|
|
138
191
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
139
192
|
AnyObject,
|
|
@@ -145,70 +198,34 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
145
198
|
AnyObject,
|
|
146
199
|
string | null | undefined
|
|
147
200
|
> => yup.string().nullable(),
|
|
148
|
-
date: (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (params.max) {
|
|
159
|
-
let maxDate;
|
|
160
|
-
if (params.max === 'now') {
|
|
161
|
-
const today = new Date();
|
|
162
|
-
maxDate = new Date(today);
|
|
163
|
-
} else {
|
|
164
|
-
maxDate = getDate(params.max).toDate();
|
|
165
|
-
}
|
|
166
|
-
const maxNextDate = new Date(maxDate);
|
|
167
|
-
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
168
|
-
simpleDate = simpleDate.test({
|
|
169
|
-
name: 'earlier-than',
|
|
170
|
-
message: {
|
|
171
|
-
key: 'form.error.date.earlier_than',
|
|
172
|
-
context: {
|
|
173
|
-
maxDate: maxNextDate.toLocaleDateString(),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
test: function (value) {
|
|
177
|
-
if (!value) return true;
|
|
178
|
-
const date = getDate(value);
|
|
179
|
-
const isValid = +date.toDate() < +maxDate;
|
|
180
|
-
return isValid;
|
|
181
|
-
},
|
|
182
|
-
});
|
|
201
|
+
date: (
|
|
202
|
+
field
|
|
203
|
+
): yup.StringSchema<
|
|
204
|
+
string | null | undefined,
|
|
205
|
+
AnyObject,
|
|
206
|
+
string | null | undefined
|
|
207
|
+
> => {
|
|
208
|
+
let schema = yup.string().nullable();
|
|
209
|
+
if (field?.extra?.min) {
|
|
210
|
+
schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
183
211
|
}
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
key: 'form.error.date.later_than',
|
|
198
|
-
context: {
|
|
199
|
-
minDate: minPreviousDate.toLocaleDateString(),
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
test: function (value) {
|
|
203
|
-
if (!value) return true;
|
|
204
|
-
const date = getDate(value);
|
|
205
|
-
const isValid = +date.toDate() > +minDate;
|
|
206
|
-
return isValid;
|
|
207
|
-
},
|
|
208
|
-
});
|
|
212
|
+
if (field?.extra?.max) {
|
|
213
|
+
schema = schema.test(EARLIER_THAN_VALIDATOR(field));
|
|
214
|
+
} else {
|
|
215
|
+
schema = schema.test(DATE_VALIDATOR);
|
|
216
|
+
}
|
|
217
|
+
return schema;
|
|
218
|
+
},
|
|
219
|
+
datetime: (field): yup.StringSchema => {
|
|
220
|
+
if (field?.extra?.min) {
|
|
221
|
+
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
222
|
+
}
|
|
223
|
+
if (field?.extra?.max) {
|
|
224
|
+
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
209
225
|
}
|
|
210
|
-
return
|
|
226
|
+
return yup.string().test(DATETIME_VALIDATOR);
|
|
211
227
|
},
|
|
228
|
+
...validatorRegistry,
|
|
212
229
|
};
|
|
213
230
|
return yupTypeMap;
|
|
214
231
|
};
|
|
@@ -220,7 +237,7 @@ export function useValidationSchema(
|
|
|
220
237
|
validatorRegistry?: Record<string, ValidatorSchema[]>
|
|
221
238
|
): Lazy<any, unknown> | AnyObjectSchema | void {
|
|
222
239
|
return useMemo(() => {
|
|
223
|
-
const yupTypeMap = getYUPTypeMap();
|
|
240
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
224
241
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
225
|
-
}, []);
|
|
242
|
+
}, [fields, validatorRegistry]);
|
|
226
243
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function digitSum(number) {
|
|
2
|
+
const sum = number > 9 ? 1 : 0;
|
|
3
|
+
return sum + (number % 10);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function validateAMKA(amka: string): boolean {
|
|
7
|
+
// Validate that the last digit is the correct check digit (created using the
|
|
8
|
+
// Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
|
|
9
|
+
amka = String(amka);
|
|
10
|
+
const checkDigitIndex = amka.length - 1;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
amka
|
|
13
|
+
.substring(0, checkDigitIndex)
|
|
14
|
+
.split('')
|
|
15
|
+
.reverse()
|
|
16
|
+
.forEach(function (value, index) {
|
|
17
|
+
const weight = ((index + 1) % 2) + 1;
|
|
18
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
19
|
+
});
|
|
20
|
+
const sumMod10 = sum % 10;
|
|
21
|
+
if (sumMod10 === 0) {
|
|
22
|
+
return amka.substring(checkDigitIndex) === '0';
|
|
23
|
+
} else {
|
|
24
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const AMKA_VALIDATOR = {
|
|
29
|
+
name: 'amka-validator',
|
|
30
|
+
message: 'form.error.amka',
|
|
31
|
+
test: (value): boolean => {
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
34
|
+
if (!AMKA_REGEX.test(value) || value === '00000000000') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return validateAMKA(value);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(customParseFormat);
|
|
7
|
+
|
|
8
|
+
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
|
+
const DATE_CACHE = {};
|
|
10
|
+
|
|
11
|
+
const getDate = (v: string) => {
|
|
12
|
+
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
16
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Function to check partial date completion
|
|
20
|
+
const checkPartialDate = (value: string) => {
|
|
21
|
+
const [day, month, year] = value.split('/');
|
|
22
|
+
if (day && !month && !year) {
|
|
23
|
+
return 'form.error.date.invalid_month_year';
|
|
24
|
+
}
|
|
25
|
+
if (!day && month && !year) {
|
|
26
|
+
return 'form.error.date.invalid_day_year';
|
|
27
|
+
}
|
|
28
|
+
if (!day && !month && year) {
|
|
29
|
+
return 'form.error.date.invalid_day_month';
|
|
30
|
+
}
|
|
31
|
+
if (day && month && !year) {
|
|
32
|
+
return 'form.error.date.invalid_year';
|
|
33
|
+
}
|
|
34
|
+
if (day && !month && year) {
|
|
35
|
+
return 'form.error.date.invalid_month';
|
|
36
|
+
}
|
|
37
|
+
if (!day && month && year) {
|
|
38
|
+
return 'form.error.date.invalid_day';
|
|
39
|
+
}
|
|
40
|
+
if (day && month) {
|
|
41
|
+
const dayNum = parseInt(day);
|
|
42
|
+
const monthNum = parseInt(month);
|
|
43
|
+
const yearNum = parseInt(year);
|
|
44
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
45
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
46
|
+
return {
|
|
47
|
+
key: 'form.error.date.invalid_day_range',
|
|
48
|
+
context: {
|
|
49
|
+
maxDay: maxDay,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
54
|
+
return 'form.error.datetime.invalid_month_range';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return 'form.error.date.invalid';
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
61
|
+
let minDate;
|
|
62
|
+
const params = field.extra || {};
|
|
63
|
+
if (params.min === 'now') {
|
|
64
|
+
const today = new Date();
|
|
65
|
+
minDate = new Date(today);
|
|
66
|
+
} else {
|
|
67
|
+
minDate = getDate(params.min).toDate();
|
|
68
|
+
}
|
|
69
|
+
const minPreviousDate = new Date(minDate);
|
|
70
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
71
|
+
return {
|
|
72
|
+
name: 'later-than',
|
|
73
|
+
message: {
|
|
74
|
+
key: 'form.error.date.later_than',
|
|
75
|
+
context: {
|
|
76
|
+
minDate: minPreviousDate.toLocaleDateString(),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
test: function (value: string) {
|
|
80
|
+
if (!value) return true;
|
|
81
|
+
const date = getDate(value);
|
|
82
|
+
const isValid = +date.toDate() > +minDate;
|
|
83
|
+
return isValid;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
89
|
+
let maxDate;
|
|
90
|
+
const params = field.extra || {};
|
|
91
|
+
if (params.max === 'now') {
|
|
92
|
+
const today = new Date();
|
|
93
|
+
maxDate = new Date(today);
|
|
94
|
+
} else {
|
|
95
|
+
maxDate = getDate(params.max).toDate();
|
|
96
|
+
}
|
|
97
|
+
const maxNextDate = new Date(maxDate);
|
|
98
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
99
|
+
return {
|
|
100
|
+
name: 'earlier-than',
|
|
101
|
+
message: {
|
|
102
|
+
key: 'form.error.date.earlier_than',
|
|
103
|
+
context: {
|
|
104
|
+
maxDate: maxNextDate.toLocaleDateString(),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
test: function (value: string) {
|
|
108
|
+
if (!value) return true;
|
|
109
|
+
const date = getDate(value);
|
|
110
|
+
const isValid = +date.toDate() < +maxDate;
|
|
111
|
+
return isValid;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const DATE_VALIDATOR = {
|
|
117
|
+
name: 'date-validator',
|
|
118
|
+
message: (v): string | object => {
|
|
119
|
+
return checkPartialDate(v.value);
|
|
120
|
+
},
|
|
121
|
+
test: function (value: string) {
|
|
122
|
+
if (!value) return true;
|
|
123
|
+
const date = getDate(value);
|
|
124
|
+
return date.isValid();
|
|
125
|
+
},
|
|
126
|
+
};
|