@digigov/form 0.6.9 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/Field/FieldBase.js +110 -0
- package/Field/{ConditionalField.js → FieldConditional.js} +9 -29
- package/Field/FieldContainer.js +62 -0
- package/Field/index.js +11 -251
- package/Field/types.js +5 -0
- package/Field/utils.js +146 -0
- package/Fieldset/FieldsetWithContext.js +63 -0
- package/Fieldset/index.js +4 -63
- package/Fieldset/types.js +5 -0
- package/FormBuilder.js +178 -0
- package/FormContext.js +14 -0
- package/Questions/Questions.js +105 -0
- package/Questions/QuestionsContext.js +20 -0
- package/Questions/Step/ReviewStep.js +11 -7
- package/Questions/Step/Step.js +93 -0
- package/Questions/Step/StepArrayReview.js +79 -0
- package/Questions/Step/StepContext.js +37 -0
- package/Questions/Step/StepDescription.js +2 -2
- package/Questions/Step/StepForm.js +10 -6
- package/Questions/Step/StepTitle.js +2 -2
- package/Questions/Step/getAddMoreFields.js +31 -0
- package/Questions/Step/index.js +81 -200
- package/Questions/Step/types.js +5 -0
- package/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/Questions/getNextStep.js +30 -0
- package/Questions/index.js +4 -150
- package/Questions/types.js +5 -0
- package/es/Field/FieldBase.js +93 -0
- package/es/Field/{ConditionalField.js → FieldConditional.js} +5 -28
- package/es/Field/FieldContainer.js +40 -0
- package/es/Field/index.js +8 -233
- package/es/Field/types.js +1 -0
- package/es/Field/utils.js +122 -0
- package/es/Fieldset/FieldsetWithContext.js +41 -0
- package/es/Fieldset/index.js +3 -51
- package/es/Fieldset/types.js +1 -0
- package/es/FormBuilder.js +148 -0
- package/es/FormContext.js +5 -0
- package/es/Questions/Questions.js +84 -0
- package/es/Questions/QuestionsContext.js +11 -0
- package/es/Questions/Step/ReviewStep.js +5 -3
- package/es/Questions/Step/Step.js +69 -0
- package/es/Questions/Step/StepArrayReview.js +50 -0
- package/es/Questions/Step/StepContext.js +27 -0
- package/es/Questions/Step/StepDescription.js +1 -1
- package/es/Questions/Step/StepForm.js +4 -2
- package/es/Questions/Step/StepTitle.js +1 -1
- package/es/Questions/Step/getAddMoreFields.js +22 -0
- package/es/Questions/Step/index.js +13 -165
- package/es/Questions/Step/types.js +1 -0
- package/es/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/es/Questions/getNextStep.js +23 -0
- package/es/Questions/index.js +2 -119
- package/es/Questions/index.spec.js +2 -1
- package/es/Questions/types.js +1 -0
- package/es/index.js +2 -153
- package/es/inputs/index.js +5 -4
- package/es/internal.js +31 -0
- package/es/types.js +1 -0
- package/es/utils.js +5 -3
- package/es/validators/index.js +155 -0
- package/es/validators/types.js +1 -0
- package/es/validators/utils/afm.js +35 -0
- package/es/validators/utils/file.js +52 -0
- package/es/validators/utils/iban.js +123 -0
- package/es/validators/utils/index.js +105 -0
- package/es/validators/utils/phone.js +122 -0
- package/es/validators/utils/postal_code.js +29 -0
- package/es/validators/utils/uuid4.js +20 -0
- package/{esm → es/validators}/validators.spec.js +1 -1
- package/esm/Field/FieldBase.js +93 -0
- package/esm/Field/{ConditionalField.js → FieldConditional.js} +5 -28
- package/esm/Field/FieldContainer.js +40 -0
- package/esm/Field/index.js +8 -233
- package/esm/Field/types.js +1 -0
- package/esm/Field/utils.js +122 -0
- package/esm/Fieldset/FieldsetWithContext.js +41 -0
- package/esm/Fieldset/index.js +3 -51
- package/esm/Fieldset/types.js +1 -0
- package/esm/FormBuilder.js +148 -0
- package/esm/FormContext.js +5 -0
- package/esm/Questions/Questions.js +84 -0
- package/esm/Questions/QuestionsContext.js +11 -0
- package/esm/Questions/Step/ReviewStep.js +5 -3
- package/esm/Questions/Step/Step.js +69 -0
- package/esm/Questions/Step/StepArrayReview.js +50 -0
- package/esm/Questions/Step/StepContext.js +27 -0
- package/esm/Questions/Step/StepDescription.js +1 -1
- package/esm/Questions/Step/StepForm.js +4 -2
- package/esm/Questions/Step/StepTitle.js +1 -1
- package/esm/Questions/Step/getAddMoreFields.js +22 -0
- package/esm/Questions/Step/index.js +13 -165
- package/esm/Questions/Step/types.js +1 -0
- package/esm/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/esm/Questions/getNextStep.js +23 -0
- package/esm/Questions/index.js +2 -119
- package/esm/Questions/index.spec.js +2 -1
- package/esm/Questions/types.js +1 -0
- package/esm/index.js +3 -154
- package/esm/inputs/index.js +5 -4
- package/esm/internal.js +31 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +5 -3
- package/esm/validators/index.js +155 -0
- package/esm/validators/types.js +1 -0
- package/esm/validators/utils/afm.js +35 -0
- package/esm/validators/utils/file.js +52 -0
- package/esm/validators/utils/iban.js +123 -0
- package/esm/validators/utils/index.js +105 -0
- package/esm/validators/utils/phone.js +122 -0
- package/esm/validators/utils/postal_code.js +29 -0
- package/esm/validators/utils/uuid4.js +20 -0
- package/{es → esm/validators}/validators.spec.js +1 -1
- package/index.js +8 -191
- package/inputs/index.js +13 -5
- package/internal.js +356 -0
- package/libs/form/src/Field/FieldBase.d.ts +3 -0
- package/libs/form/src/Field/FieldConditional.d.ts +4 -0
- package/libs/form/src/Field/FieldContainer.d.ts +4 -0
- package/libs/form/src/Field/index.d.ts +1 -62
- package/libs/form/src/Field/types.d.ts +75 -0
- package/libs/form/src/Field/utils.d.ts +5 -0
- package/libs/form/src/Fieldset/FieldsetWithContext.d.ts +4 -0
- package/libs/form/src/Fieldset/index.d.ts +2 -12
- package/libs/form/src/Fieldset/types.d.ts +6 -0
- package/libs/form/src/FormBuilder.d.ts +5 -0
- package/libs/form/src/FormContext.d.ts +3 -0
- package/libs/form/src/Questions/Questions.d.ts +8 -0
- package/libs/form/src/Questions/QuestionsContext.d.ts +3 -0
- package/libs/form/src/Questions/Step/ReviewStep.d.ts +1 -0
- package/libs/form/src/Questions/Step/Step.d.ts +9 -0
- package/libs/form/src/Questions/Step/StepArrayReview.d.ts +4 -0
- package/libs/form/src/Questions/Step/StepContext.d.ts +4 -0
- package/libs/form/src/Questions/Step/StepForm.d.ts +2 -1
- package/libs/form/src/Questions/Step/getAddMoreFields.d.ts +3 -0
- package/libs/form/src/Questions/Step/index.d.ts +12 -47
- package/libs/form/src/Questions/Step/types.d.ts +31 -0
- package/libs/form/src/Questions/getNextStep.d.ts +2 -0
- package/libs/form/src/Questions/index.d.ts +1 -28
- package/libs/form/src/Questions/types.d.ts +19 -0
- package/libs/form/src/index.d.ts +2 -73
- package/libs/form/src/inputs/Checkboxes/index.d.ts +1 -1
- package/libs/form/src/inputs/DateInput/index.d.ts +1 -2
- package/libs/form/src/inputs/FileInput/index.d.ts +1 -1
- package/libs/form/src/inputs/Input/index.d.ts +1 -1
- package/libs/form/src/inputs/Label/index.d.ts +2 -1
- package/libs/form/src/inputs/Radio/index.d.ts +1 -1
- package/libs/form/src/inputs/Select/index.d.ts +1 -1
- package/libs/form/src/inputs/index.d.ts +4 -3
- package/libs/form/src/internal.d.ts +31 -0
- package/libs/form/src/types.d.ts +70 -0
- package/libs/form/src/validators/index.d.ts +8 -0
- package/libs/form/src/validators/types.d.ts +2 -0
- package/libs/form/src/validators/utils/afm.d.ts +6 -0
- package/libs/form/src/validators/utils/file.d.ts +1 -0
- package/libs/form/src/validators/utils/iban.d.ts +2 -0
- package/libs/form/src/validators/utils/index.d.ts +12 -0
- package/libs/form/src/validators/utils/phone.d.ts +9 -0
- package/libs/form/src/validators/utils/postal_code.d.ts +2 -0
- package/libs/form/src/validators/utils/uuid4.d.ts +6 -0
- package/libs/form/src/{validators.spec.d.ts → validators/validators.spec.d.ts} +0 -0
- package/libs/ui/src/core/Accordion/index.d.ts +3 -3
- package/libs/ui/src/core/Base/index.d.ts +3 -0
- package/libs/ui/src/core/Blockquote/index.d.ts +1 -1
- package/libs/ui/src/core/Button/BackButton.d.ts +1 -1
- package/libs/ui/src/core/Button/ButtonLink.d.ts +1 -1
- package/libs/ui/src/core/Button/index.d.ts +1 -1
- package/libs/ui/src/core/Divider/index.d.ts +1 -1
- package/libs/ui/src/core/Form/index.d.ts +3 -0
- package/libs/ui/src/core/Label/index.d.ts +4 -0
- package/libs/ui/src/core/Link/index.d.ts +1 -0
- package/libs/ui/src/core/NavList/NavHorizontal.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavHorizontalList.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavHorizontalListItem.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavList.d.ts +1 -14
- package/libs/ui/src/core/NavList/NavListBase.d.ts +4 -0
- package/libs/ui/src/core/NavList/NavListItem.d.ts +1 -0
- package/libs/ui/src/core/NavList/NavListItemBase.d.ts +2 -1
- package/libs/ui/src/core/NavList/NavListSubMenu.d.ts +1 -1
- package/libs/ui/src/core/NavList/NavVertical.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavVerticalItem.d.ts +3 -0
- package/libs/ui/src/core/NavList/index.d.ts +5 -0
- package/libs/ui/src/core/NavList/types.d.ts +14 -0
- package/libs/ui/src/core/SkipLink/index.d.ts +3 -0
- package/libs/ui/src/core/SvgIcon/index.d.ts +1 -0
- package/libs/ui/src/core/Table/TableFloatingScroll.d.ts +2 -0
- package/libs/ui/src/core/Table/index.d.ts +1 -0
- package/libs/ui/src/core/index.d.ts +4 -0
- package/libs/ui/src/layouts/Grid/index.d.ts +1 -0
- package/libs/ui/src/typography/Caption/index.d.ts +3 -2
- package/libs/ui/src/typography/Title/index.d.ts +2 -1
- package/libs-ui/react-core/src/Accordion/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionControls/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSection/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionHeader/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionSummary/index.d.ts +4 -3
- package/libs-ui/react-core/src/AccordionSectionSummaryHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/BackLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/Base/index.d.ts +43 -0
- package/libs-ui/react-core/src/Blockquote/index.d.ts +3 -3
- package/libs-ui/react-core/src/Breadcrumbs/index.d.ts +3 -3
- package/libs-ui/react-core/src/BreadcrumbsList/index.d.ts +3 -3
- package/libs-ui/react-core/src/BreadcrumbsListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Button/index.d.ts +3 -3
- package/libs-ui/react-core/src/ButtonGroup/index.d.ts +3 -3
- package/libs-ui/react-core/src/ButtonLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/CallToAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/Card/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardAction/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardText/index.d.ts +3 -3
- package/libs-ui/react-core/src/CheckIcon/index.d.ts +15 -0
- package/libs-ui/react-core/src/Checkbox/index.d.ts +3 -3
- package/libs-ui/react-core/src/CheckboxItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Confirmation/index.d.ts +3 -3
- package/libs-ui/react-core/src/ConfirmationBody/index.d.ts +3 -3
- package/libs-ui/react-core/src/ConfirmationTitle/index.d.ts +3 -3
- package/libs-ui/react-core/src/DateInput/index.d.ts +3 -3
- package/libs-ui/react-core/src/DateInputItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Details/index.d.ts +3 -3
- package/libs-ui/react-core/src/DetailsContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/DetailsSummary/index.d.ts +3 -3
- package/libs-ui/react-core/src/ErrorMessage/index.d.ts +3 -3
- package/libs-ui/react-core/src/ErrorSummary/index.d.ts +3 -3
- package/libs-ui/react-core/src/Field/index.d.ts +3 -3
- package/libs-ui/react-core/src/Fieldset/index.d.ts +3 -3
- package/libs-ui/react-core/src/FieldsetLegend/index.d.ts +3 -3
- package/libs-ui/react-core/src/FileUpload/index.d.ts +3 -3
- package/libs-ui/react-core/src/Form/index.d.ts +11 -0
- package/libs-ui/react-core/src/Grid/index.d.ts +3 -3
- package/libs-ui/react-core/src/Heading/index.d.ts +3 -3
- package/libs-ui/react-core/src/HeadingCaption/index.d.ts +3 -3
- package/libs-ui/react-core/src/Hidden/index.d.ts +3 -3
- package/libs-ui/react-core/src/Hint/index.d.ts +3 -3
- package/libs-ui/react-core/src/Label/index.d.ts +3 -3
- package/libs-ui/react-core/src/LabelTitle/index.d.ts +7 -7
- package/libs-ui/react-core/src/Link/index.d.ts +3 -3
- package/libs-ui/react-core/src/List/index.d.ts +3 -3
- package/libs-ui/react-core/src/ListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/NavHorizontal/index.d.ts +16 -0
- package/libs-ui/react-core/src/NavHorizontalList/index.d.ts +10 -0
- package/libs-ui/react-core/src/NavHorizontalListItem/index.d.ts +18 -0
- package/libs-ui/react-core/src/NavVertical/index.d.ts +11 -0
- package/libs-ui/react-core/src/NavVerticalItem/index.d.ts +14 -0
- package/libs-ui/react-core/src/NormalText/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBanner/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerHeader/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/Paragraph/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBanner/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerHeaderContainer/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerTag/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerText/index.d.ts +3 -3
- package/libs-ui/react-core/src/Radio/index.d.ts +3 -3
- package/libs-ui/react-core/src/RadioItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/SectionBreak/index.d.ts +3 -3
- package/libs-ui/react-core/src/Select/index.d.ts +3 -3
- package/libs-ui/react-core/src/SelectOption/index.d.ts +3 -3
- package/libs-ui/react-core/src/SkipLink/index.d.ts +10 -0
- package/libs-ui/react-core/src/SummaryList/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemAction/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemKey/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemValue/index.d.ts +3 -3
- package/libs-ui/react-core/src/SvgIcon/index.d.ts +3 -3
- package/libs-ui/react-core/src/Table/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableBody/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableCaption/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableContainer/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableDataCell/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableHead/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableHeadCell/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableNoDataRow/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableRow/index.d.ts +3 -3
- package/libs-ui/react-core/src/Tabs/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsList/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsPanel/index.d.ts +3 -3
- package/libs-ui/react-core/src/TextArea/index.d.ts +3 -3
- package/libs-ui/react-core/src/TextInput/index.d.ts +3 -3
- package/libs-ui/react-core/src/UncheckIcon/index.d.ts +4 -4
- package/libs-ui/react-core/src/VisuallyHidden/index.d.ts +3 -3
- package/libs-ui/react-core/src/WarningText/index.d.ts +3 -3
- package/package.json +3 -2
- package/types.js +5 -0
- package/utils.js +6 -4
- package/validators/index.js +181 -0
- package/validators/types.js +5 -0
- package/validators/utils/afm.js +45 -0
- package/validators/utils/file.js +62 -0
- package/validators/utils/iban.js +134 -0
- package/validators/utils/index.js +210 -0
- package/validators/utils/phone.js +144 -0
- package/validators/utils/postal_code.js +40 -0
- package/validators/utils/uuid4.js +30 -0
- package/validators/validators.spec.js +88 -0
- package/es/validators.js +0 -626
- package/esm/validators.js +0 -626
- package/libs/form/src/Field/ConditionalField.d.ts +0 -17
- package/libs/form/src/validators.d.ts +0 -14
- package/validators.js +0 -662
- package/validators.spec.js +0 -88
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export function validateIban(value, countryCode) {
|
|
2
|
+
value = value.replace(/\s/g, '').replace(/-/g, '');
|
|
3
|
+
|
|
4
|
+
if (value.match(/^[0-9]*$/i)) {
|
|
5
|
+
// this is for greek iban without the country code
|
|
6
|
+
if (value.length !== 25) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
} else {
|
|
10
|
+
value = value.toUpperCase();
|
|
11
|
+
|
|
12
|
+
if (countryCode) {
|
|
13
|
+
if (!value.startsWith(countryCode.toUpperCase())) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (value.length !== 27) {
|
|
23
|
+
// this is for greek iban
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
export var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
31
|
+
var _field$extra;
|
|
32
|
+
|
|
33
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.country;
|
|
34
|
+
return {
|
|
35
|
+
name: 'iban-validator',
|
|
36
|
+
message: 'form.error.iban',
|
|
37
|
+
test: function test(value) {
|
|
38
|
+
if (!value) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return validateIban(value, countryCode);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var ibanCountryCodesLengths = {
|
|
47
|
+
AD: 24,
|
|
48
|
+
AT: 20,
|
|
49
|
+
AZ: 28,
|
|
50
|
+
BH: 22,
|
|
51
|
+
BY: 28,
|
|
52
|
+
BE: 16,
|
|
53
|
+
BA: 20,
|
|
54
|
+
BR: 29,
|
|
55
|
+
BG: 22,
|
|
56
|
+
CR: 22,
|
|
57
|
+
HR: 21,
|
|
58
|
+
CY: 28,
|
|
59
|
+
CZ: 24,
|
|
60
|
+
DK: 18,
|
|
61
|
+
DO: 28,
|
|
62
|
+
EG: 29,
|
|
63
|
+
SV: 28,
|
|
64
|
+
EE: 20,
|
|
65
|
+
FO: 18,
|
|
66
|
+
FI: 18,
|
|
67
|
+
FR: 27,
|
|
68
|
+
GE: 22,
|
|
69
|
+
DE: 22,
|
|
70
|
+
GI: 23,
|
|
71
|
+
GR: 27,
|
|
72
|
+
GL: 18,
|
|
73
|
+
GT: 28,
|
|
74
|
+
VA: 22,
|
|
75
|
+
HU: 28,
|
|
76
|
+
IS: 26,
|
|
77
|
+
IQ: 23,
|
|
78
|
+
IE: 22,
|
|
79
|
+
IL: 23,
|
|
80
|
+
IT: 27,
|
|
81
|
+
JO: 30,
|
|
82
|
+
KZ: 20,
|
|
83
|
+
XK: 20,
|
|
84
|
+
KW: 30,
|
|
85
|
+
LV: 21,
|
|
86
|
+
LB: 28,
|
|
87
|
+
LI: 21,
|
|
88
|
+
LT: 20,
|
|
89
|
+
LU: 20,
|
|
90
|
+
MT: 31,
|
|
91
|
+
MR: 27,
|
|
92
|
+
MU: 30,
|
|
93
|
+
MD: 24,
|
|
94
|
+
MC: 27,
|
|
95
|
+
ME: 22,
|
|
96
|
+
NL: 18,
|
|
97
|
+
MK: 19,
|
|
98
|
+
NO: 15,
|
|
99
|
+
PK: 24,
|
|
100
|
+
PS: 29,
|
|
101
|
+
PL: 28,
|
|
102
|
+
PT: 25,
|
|
103
|
+
QA: 29,
|
|
104
|
+
RO: 24,
|
|
105
|
+
LC: 32,
|
|
106
|
+
SM: 27,
|
|
107
|
+
ST: 25,
|
|
108
|
+
SA: 24,
|
|
109
|
+
RS: 22,
|
|
110
|
+
SC: 31,
|
|
111
|
+
SK: 24,
|
|
112
|
+
SI: 19,
|
|
113
|
+
ES: 24,
|
|
114
|
+
SE: 24,
|
|
115
|
+
CH: 21,
|
|
116
|
+
TL: 23,
|
|
117
|
+
TN: 24,
|
|
118
|
+
TR: 26,
|
|
119
|
+
UA: 29,
|
|
120
|
+
AE: 23,
|
|
121
|
+
GB: 22,
|
|
122
|
+
VG: 24
|
|
123
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import * as yup from 'yup';
|
|
4
|
+
export * from '@digigov/form/validators/utils/afm';
|
|
5
|
+
export * from '@digigov/form/validators/utils/file';
|
|
6
|
+
export * from '@digigov/form/validators/utils/iban';
|
|
7
|
+
export * from '@digigov/form/validators/utils/phone';
|
|
8
|
+
export * from '@digigov/form/validators/utils/postal_code';
|
|
9
|
+
export * from '@digigov/form/validators/utils/uuid4';
|
|
10
|
+
export function getYupField(field, yupTypeMap) {
|
|
11
|
+
var yupField = yupTypeMap[field.type] || yupTypeMap.string;
|
|
12
|
+
return yupField(field);
|
|
13
|
+
}
|
|
14
|
+
export function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
15
|
+
var fieldSchemas = {};
|
|
16
|
+
var objectFields = {};
|
|
17
|
+
fields.forEach(function (field) {
|
|
18
|
+
if (field.key.includes('.')) {
|
|
19
|
+
var _field$key$split = field.key.split(/\.(.+)/),
|
|
20
|
+
_field$key$split2 = _slicedToArray(_field$key$split, 2),
|
|
21
|
+
objectKey = _field$key$split2[0],
|
|
22
|
+
fieldKey = _field$key$split2[1];
|
|
23
|
+
|
|
24
|
+
if (!objectFields[objectKey]) {
|
|
25
|
+
objectFields[objectKey] = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
objectFields[objectKey].push(_extends({}, field, {
|
|
29
|
+
key: fieldKey
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var yupField = getYupField(field, yupTypeMap);
|
|
35
|
+
|
|
36
|
+
if (field.condition) {
|
|
37
|
+
for (var key in field.condition) {
|
|
38
|
+
var then = void 0,
|
|
39
|
+
otherwise = void 0;
|
|
40
|
+
|
|
41
|
+
if (field.condition[key].then) {
|
|
42
|
+
var _field$condition$key$, _field$condition$key$2;
|
|
43
|
+
|
|
44
|
+
if (((_field$condition$key$ = field.condition[key].then) === null || _field$condition$key$ === void 0 ? void 0 : _field$condition$key$.required) === false) {
|
|
45
|
+
then = yupField;
|
|
46
|
+
} else if (((_field$condition$key$2 = field.condition[key].then) === null || _field$condition$key$2 === void 0 ? void 0 : _field$condition$key$2.required) === true) {
|
|
47
|
+
then = yupField.required('form.error.required');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (field.condition[key]["else"]) {
|
|
52
|
+
var _field$condition$key$3, _field$condition$key$4;
|
|
53
|
+
|
|
54
|
+
if (((_field$condition$key$3 = field.condition[key]["else"]) === null || _field$condition$key$3 === void 0 ? void 0 : _field$condition$key$3.required) === false) {
|
|
55
|
+
otherwise = yupField;
|
|
56
|
+
} else if (((_field$condition$key$4 = field.condition[key]["else"]) === null || _field$condition$key$4 === void 0 ? void 0 : _field$condition$key$4.required) === true) {
|
|
57
|
+
otherwise = yupField.required('form.error.required');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (then || otherwise) {
|
|
62
|
+
yupField = yupField.when(key, {
|
|
63
|
+
is: field.condition[key].is,
|
|
64
|
+
then: then,
|
|
65
|
+
otherwise: otherwise
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} else if (field.required) {
|
|
70
|
+
yupField = yupField.required('form.error.required');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (validatorRegistry && field.type && validatorRegistry[field.type]) {
|
|
74
|
+
validatorRegistry[field.type].forEach(function (validator) {
|
|
75
|
+
yupField = yupField.test(validator);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (field.validators) {
|
|
80
|
+
field.validators.forEach(function (validator) {
|
|
81
|
+
yupField = yupField.test(validator);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fieldSchemas[field.key] = yupField;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
for (var objectKey in objectFields) {
|
|
89
|
+
fieldSchemas[objectKey] = getYupObjectShape(objectFields[objectKey], yupTypeMap, validatorRegistry);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return fieldSchemas;
|
|
93
|
+
}
|
|
94
|
+
export function getYupObjectShape( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
fields, yupTypeMap, validatorRegistry) {
|
|
96
|
+
if (!fields.current) {
|
|
97
|
+
var fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);
|
|
98
|
+
return yup.object().shape(fieldSchemas);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return yup.lazy(function () {
|
|
102
|
+
var fieldSchemas = computeShape(Object.values(fields.current), yupTypeMap, validatorRegistry);
|
|
103
|
+
return yup.object().shape(fieldSchemas);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as gPhoneNumber from 'google-libphonenumber';
|
|
2
|
+
export function validatePhoneNumber(phoneNumber) {
|
|
3
|
+
var countries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['gr'];
|
|
4
|
+
var typeOfPhoneNumber = arguments.length > 2 ? arguments[2] : undefined;
|
|
5
|
+
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
6
|
+
|
|
7
|
+
if (!countries || countries.length === 0) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return countries.some(function (country) {
|
|
12
|
+
try {
|
|
13
|
+
var phone = phoneUtil.parse(phoneNumber, country.toUpperCase());
|
|
14
|
+
|
|
15
|
+
if (phoneUtil.isValidNumber(phone)) {
|
|
16
|
+
if (typeOfPhoneNumber) {
|
|
17
|
+
if (matchTypeOfPhoneNumber(phone, typeOfPhoneNumber, phoneUtil)) {
|
|
18
|
+
return true;
|
|
19
|
+
} else {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
var phoneNumberTypes = {
|
|
35
|
+
0: 'landline',
|
|
36
|
+
1: 'mobile',
|
|
37
|
+
2: 'landline_or_mobile'
|
|
38
|
+
};
|
|
39
|
+
export function matchTypeOfPhoneNumber(phone, type, phoneUtil) {
|
|
40
|
+
try {
|
|
41
|
+
var phoneNumberType = phoneUtil.getNumberType(phone);
|
|
42
|
+
var numberType = phoneNumberTypes[phoneNumberType];
|
|
43
|
+
|
|
44
|
+
if (numberType === 'landline_or_mobile' || numberType === type) {
|
|
45
|
+
return true;
|
|
46
|
+
} else {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function validateMobile(value) {
|
|
56
|
+
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
57
|
+
var origValue = value; // probably catch all the cases with a regex instead of gphonenumber
|
|
58
|
+
|
|
59
|
+
if (!value.match(/^((\+|00){0,1}\d{1,3}[- ]?)?\d{10}$/)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
var phone;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
phone = phoneUtil.parse(value);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
try {
|
|
70
|
+
value = '+' + value;
|
|
71
|
+
phone = phoneUtil.parse(value);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
value = '+30' + origValue;
|
|
74
|
+
phone = phoneUtil.parse(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return phoneUtil.isValidNumber(phone);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error(err);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export var MOBILE_PHONE_VALIDATOR = {
|
|
86
|
+
name: 'mobile-phone-validator',
|
|
87
|
+
message: 'form.error.mobile_phone',
|
|
88
|
+
test: function test(value) {
|
|
89
|
+
if (value) {
|
|
90
|
+
return validateMobile(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
export var PHONE_NUMBER_VALIDATOR = function PHONE_NUMBER_VALIDATOR(field) {
|
|
97
|
+
var _field$extra, _field$extra2;
|
|
98
|
+
|
|
99
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
100
|
+
var typeOfPhone = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.phoneType;
|
|
101
|
+
return {
|
|
102
|
+
name: 'phone-number-validator',
|
|
103
|
+
message: function message() {
|
|
104
|
+
if (typeOfPhone === 'mobile') {
|
|
105
|
+
return 'form.error.mobile_phone';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeOfPhone === 'landline') {
|
|
109
|
+
return 'form.error.landline';
|
|
110
|
+
} else {
|
|
111
|
+
return 'form.error.phone_number';
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
test: function test(value) {
|
|
115
|
+
if (!value) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return validatePhoneNumber(value, countryCode, typeOfPhone);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
2
|
+
export function validatePostalCode(number, countries) {
|
|
3
|
+
if (!countries) {
|
|
4
|
+
return false;
|
|
5
|
+
} else {
|
|
6
|
+
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
7
|
+
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
8
|
+
return CODE_REGEX.test(number);
|
|
9
|
+
} else {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
15
|
+
var _field$extra;
|
|
16
|
+
|
|
17
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
18
|
+
return {
|
|
19
|
+
name: 'postal-code-validator',
|
|
20
|
+
message: 'form.error.postalCode',
|
|
21
|
+
test: function test(value) {
|
|
22
|
+
if (!value) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return validatePostalCode(value, countryCode);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var UUID4_PATTERN = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
|
2
|
+
export function validateUUID4(uuid4) {
|
|
3
|
+
if (uuid4.length !== 36) {
|
|
4
|
+
// This uuid4 should be 36 characters long
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return UUID4_PATTERN.test(uuid4);
|
|
9
|
+
}
|
|
10
|
+
export var UUID4_VALIDATOR = {
|
|
11
|
+
name: 'uuid4-validator',
|
|
12
|
+
message: 'form.error.uuid4',
|
|
13
|
+
test: function test(value) {
|
|
14
|
+
if (value) {
|
|
15
|
+
return validateUUID4(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateUUID4, validateIban, validatePostalCode, validatePhoneNumber } from '@digigov/form/validators';
|
|
1
|
+
import { validateUUID4, validateIban, validatePostalCode, validatePhoneNumber } from '@digigov/form/validators/utils';
|
|
2
2
|
it('validates wrong uuid4 for empty value', function () {
|
|
3
3
|
expect(validateUUID4('')).toBe(false);
|
|
4
4
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["required", "name", "component", "wrapper", "control", "type", "controlled", "enabled", "editable", "defaultValue", "label", "extra", "layout", "error", "register"];
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import FieldContainer from '@digigov/form/Field/FieldContainer';
|
|
6
|
+
import { Controller } from 'react-hook-form';
|
|
7
|
+
export var FieldBase = function FieldBase(props) {
|
|
8
|
+
var required = props.required,
|
|
9
|
+
name = props.name,
|
|
10
|
+
Component = props.component,
|
|
11
|
+
wrapper = props.wrapper,
|
|
12
|
+
control = props.control,
|
|
13
|
+
type = props.type,
|
|
14
|
+
_props$controlled = props.controlled,
|
|
15
|
+
controlled = _props$controlled === void 0 ? false : _props$controlled,
|
|
16
|
+
_props$enabled = props.enabled,
|
|
17
|
+
enabled = _props$enabled === void 0 ? true : _props$enabled,
|
|
18
|
+
editable = props.editable,
|
|
19
|
+
defaultValue = props.defaultValue,
|
|
20
|
+
label = props.label,
|
|
21
|
+
_props$extra = props.extra,
|
|
22
|
+
extra = _props$extra === void 0 ? {} : _props$extra,
|
|
23
|
+
layout = props.layout,
|
|
24
|
+
error = props.error,
|
|
25
|
+
register = props.register,
|
|
26
|
+
componentProps = _objectWithoutProperties(props, _excluded);
|
|
27
|
+
|
|
28
|
+
if (!enabled) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (controlled) {
|
|
33
|
+
return /*#__PURE__*/React.createElement(FieldContainer, {
|
|
34
|
+
label: label,
|
|
35
|
+
layout: layout,
|
|
36
|
+
error: error,
|
|
37
|
+
wrapper: wrapper,
|
|
38
|
+
name: name
|
|
39
|
+
}, /*#__PURE__*/React.createElement(Controller, {
|
|
40
|
+
control: control,
|
|
41
|
+
name: name,
|
|
42
|
+
render: function render(_ref) {
|
|
43
|
+
var onChange = _ref.onChange,
|
|
44
|
+
onBlur = _ref.onBlur,
|
|
45
|
+
value = _ref.value;
|
|
46
|
+
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
47
|
+
name: name,
|
|
48
|
+
onChange: onChange,
|
|
49
|
+
onBlur: onBlur,
|
|
50
|
+
value: value,
|
|
51
|
+
defaultValue: defaultValue,
|
|
52
|
+
extra: extra,
|
|
53
|
+
error: !!error,
|
|
54
|
+
type: type,
|
|
55
|
+
"aria-required": !!required,
|
|
56
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
57
|
+
required: required,
|
|
58
|
+
disabled: editable === false
|
|
59
|
+
}, componentProps));
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return /*#__PURE__*/React.createElement(FieldContainer, {
|
|
65
|
+
label: label,
|
|
66
|
+
layout: layout,
|
|
67
|
+
error: error,
|
|
68
|
+
wrapper: wrapper,
|
|
69
|
+
name: name
|
|
70
|
+
}, Component !== null && Component !== void 0 && Component.render ? /*#__PURE__*/React.createElement(Component, _extends({
|
|
71
|
+
name: name,
|
|
72
|
+
ref: register,
|
|
73
|
+
control: control,
|
|
74
|
+
error: !!error,
|
|
75
|
+
extra: extra,
|
|
76
|
+
type: type,
|
|
77
|
+
"aria-required": !!required,
|
|
78
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
79
|
+
required: required,
|
|
80
|
+
disabled: editable === false
|
|
81
|
+
}, componentProps)) : /*#__PURE__*/React.createElement(Component, _extends({
|
|
82
|
+
name: name,
|
|
83
|
+
register: register,
|
|
84
|
+
control: control,
|
|
85
|
+
error: !!error,
|
|
86
|
+
extra: extra,
|
|
87
|
+
type: type,
|
|
88
|
+
"aria-required": !!required,
|
|
89
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
90
|
+
required: required,
|
|
91
|
+
disabled: editable === false
|
|
92
|
+
}, componentProps)));
|
|
93
|
+
};
|
|
@@ -1,32 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useWatch } from 'react-hook-form';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function evaluateFieldWithConditions(field, variables) {
|
|
7
|
-
var newField = _extends({}, field);
|
|
8
|
-
|
|
9
|
-
if (variables) {
|
|
10
|
-
for (var key in variables) {
|
|
11
|
-
if (field.condition[key] && field.condition[key].is === variables[key]) {
|
|
12
|
-
var then = field.condition[key].then || {};
|
|
13
|
-
|
|
14
|
-
for (var attr in then) {
|
|
15
|
-
newField[attr] = then[attr];
|
|
16
|
-
}
|
|
17
|
-
} else if (field.condition[key]) {
|
|
18
|
-
var otherwise = field.condition[key]["else"] || {};
|
|
19
|
-
|
|
20
|
-
for (var _attr in otherwise) {
|
|
21
|
-
newField[_attr] = otherwise[_attr];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return newField;
|
|
28
|
-
}
|
|
29
|
-
|
|
4
|
+
import { evaluateFieldWithConditions } from '@digigov/form/Field/utils';
|
|
5
|
+
import { FieldBase } from '@digigov/form/Field/FieldBase';
|
|
30
6
|
var ChildFieldMemo = /*#__PURE__*/React.memo(function ChildField(_ref) {
|
|
31
7
|
var dependencies = _ref.dependencies,
|
|
32
8
|
field = _ref.field,
|
|
@@ -57,7 +33,7 @@ var ChildFieldMemo = /*#__PURE__*/React.memo(function ChildField(_ref) {
|
|
|
57
33
|
|
|
58
34
|
return true;
|
|
59
35
|
});
|
|
60
|
-
export var
|
|
36
|
+
export var FieldConditional = function FieldConditional(_ref2) {
|
|
61
37
|
var control = _ref2.control,
|
|
62
38
|
field = _ref2.field,
|
|
63
39
|
register = _ref2.register,
|
|
@@ -74,4 +50,5 @@ export var ConditionalField = function ConditionalField(_ref2) {
|
|
|
74
50
|
register: register,
|
|
75
51
|
error: error
|
|
76
52
|
});
|
|
77
|
-
};
|
|
53
|
+
};
|
|
54
|
+
export default FieldConditional;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import CoreField from '@digigov/react-core/Field';
|
|
4
|
+
import CoreLabel from '@digigov/react-core/Label';
|
|
5
|
+
import CoreFieldset from '@digigov/react-core/Fieldset';
|
|
6
|
+
import Hint from '@digigov/react-core/Hint';
|
|
7
|
+
import FieldsetLegend from '@digigov/react-core/FieldsetLegend';
|
|
8
|
+
import ErrorMessage from '@digigov/react-core/ErrorMessage';
|
|
9
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
10
|
+
import Label from '@digigov/form/inputs/Label';
|
|
11
|
+
export var FieldContainer = function FieldContainer(_ref) {
|
|
12
|
+
var name = _ref.name,
|
|
13
|
+
wrapper = _ref.wrapper,
|
|
14
|
+
label = _ref.label,
|
|
15
|
+
children = _ref.children,
|
|
16
|
+
error = _ref.error,
|
|
17
|
+
layout = _ref.layout;
|
|
18
|
+
|
|
19
|
+
var _useTranslation = useTranslation(),
|
|
20
|
+
t = _useTranslation.t;
|
|
21
|
+
|
|
22
|
+
if (wrapper === 'fieldset') {
|
|
23
|
+
return /*#__PURE__*/React.createElement(CoreField, _extends({
|
|
24
|
+
error: !!error
|
|
25
|
+
}, layout), /*#__PURE__*/React.createElement(CoreFieldset, null, /*#__PURE__*/React.createElement(FieldsetLegend, {
|
|
26
|
+
size: "s"
|
|
27
|
+
}, label && label.primary, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)), error && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
28
|
+
id: "".concat(name, "-error")
|
|
29
|
+
}, t((error === null || error === void 0 ? void 0 : error.message) || ''))), children));
|
|
30
|
+
} else {
|
|
31
|
+
return /*#__PURE__*/React.createElement(CoreField, _extends({
|
|
32
|
+
error: !!error
|
|
33
|
+
}, layout), /*#__PURE__*/React.createElement(CoreLabel, null, label && /*#__PURE__*/React.createElement(Label, {
|
|
34
|
+
label: label
|
|
35
|
+
}), error && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
36
|
+
id: "".concat(name, "-error")
|
|
37
|
+
}, t((error === null || error === void 0 ? void 0 : error.message) || '')), children));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export default FieldContainer;
|