@digigov/form 0.4.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -1
- package/Field/index.js +9 -2
- package/Questions/Step/index.js +1 -0
- package/es/Field/index.js +8 -2
- package/es/Questions/Step/index.js +2 -0
- package/es/index.js +2 -0
- package/es/index.mdx +0 -3
- package/es/inputs/Checkboxes/index.js +7 -1
- package/es/inputs/DateInput/index.js +149 -0
- package/es/inputs/FileInput/index.js +1 -0
- package/es/inputs/Input/index.js +5 -2
- package/es/utils.js +1 -0
- package/es/validators.js +83 -4
- package/esm/Field/index.js +8 -2
- package/esm/Questions/Step/index.js +2 -0
- package/esm/index.js +3 -1
- package/esm/index.mdx +0 -3
- package/esm/inputs/Checkboxes/index.js +7 -1
- package/esm/inputs/DateInput/index.js +149 -0
- package/esm/inputs/FileInput/index.js +1 -0
- package/esm/inputs/Input/index.js +5 -2
- package/esm/utils.js +1 -0
- package/esm/validators.js +83 -4
- package/index.js +1 -0
- package/index.mdx +0 -3
- package/inputs/Checkboxes/index.js +7 -1
- package/inputs/DateInput/index.js +173 -0
- package/inputs/FileInput/index.js +1 -0
- package/inputs/Input/index.js +5 -2
- package/libs/form/src/Field/index.d.ts +7 -6
- package/libs/form/src/Fieldset/index.d.ts +9 -3
- package/libs/form/src/inputs/Checkboxes/index.d.ts +2 -1
- package/libs/form/src/inputs/DateInput/index.d.ts +14 -0
- package/libs/form/src/validators.d.ts +4 -2
- package/libs/ui/src/core/Accordion/index.d.ts +3 -3
- 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 +2 -1
- package/libs/ui/src/core/Link/index.d.ts +3 -8
- package/libs/ui/src/core/NavList/NavList.d.ts +1 -1
- package/libs/ui/src/core/NavList/NavListItemBase.d.ts +1 -1
- package/libs/ui/src/core/NotificationBanner/index.d.ts +9 -8
- package/libs/ui/src/core/ServiceBadge/index.d.ts +1 -0
- package/libs/ui/src/locales/el.d.ts +10 -0
- package/libs/ui/src/typography/Caption.d.ts +1 -1
- package/libs-ui/react-core/src/Accordion/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionControls/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSection/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSectionContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSectionHeader/index.d.ts +1 -1
- package/libs-ui/react-core/src/ArrowIcon/index.d.ts +15 -0
- package/libs-ui/react-core/src/BackLink/index.d.ts +1 -1
- package/libs-ui/react-core/src/Blockquote/index.d.ts +1 -1
- package/libs-ui/react-core/src/Button/index.d.ts +1 -1
- package/libs-ui/react-core/src/ButtonGroup/index.d.ts +9 -0
- package/libs-ui/react-core/src/ButtonLink/index.d.ts +1 -1
- package/libs-ui/react-core/src/CallToAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/CaretIcon/index.d.ts +15 -0
- package/libs-ui/react-core/src/Checkbox/index.d.ts +1 -1
- package/libs-ui/react-core/src/CheckboxItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/DateInput/index.d.ts +12 -0
- package/libs-ui/react-core/src/DateInputItem/index.d.ts +25 -0
- package/libs-ui/react-core/src/Details/index.d.ts +1 -1
- package/libs-ui/react-core/src/DetailsContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/DetailsSummary/index.d.ts +1 -1
- package/libs-ui/react-core/src/ErrorMessage/index.d.ts +1 -1
- package/libs-ui/react-core/src/ErrorSummary/index.d.ts +1 -1
- package/libs-ui/react-core/src/Field/index.d.ts +1 -1
- package/libs-ui/react-core/src/Fieldset/index.d.ts +1 -1
- package/libs-ui/react-core/src/FieldsetLegend/index.d.ts +1 -1
- package/libs-ui/react-core/src/FileUpload/index.d.ts +1 -1
- package/libs-ui/react-core/src/Heading/index.d.ts +1 -1
- package/libs-ui/react-core/src/HeadingCaption/index.d.ts +1 -1
- package/libs-ui/react-core/src/Hint/index.d.ts +1 -1
- package/libs-ui/react-core/src/Label/index.d.ts +1 -1
- package/libs-ui/react-core/src/LabelTitle/index.d.ts +1 -1
- package/libs-ui/react-core/src/Link/index.d.ts +14 -0
- package/libs-ui/react-core/src/List/index.d.ts +1 -1
- package/libs-ui/react-core/src/ListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/NormalText/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBanner/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerHeader/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerHeading/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerLink/index.d.ts +15 -0
- package/libs-ui/react-core/src/Paragraph/index.d.ts +1 -1
- package/libs-ui/react-core/src/PhaseBanner/index.d.ts +1 -1
- package/libs-ui/react-core/src/PhaseBannerTag/index.d.ts +1 -1
- package/libs-ui/react-core/src/PhaseBannerText/index.d.ts +11 -0
- package/libs-ui/react-core/src/Radio/index.d.ts +1 -1
- package/libs-ui/react-core/src/RadioItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/SectionBreak/index.d.ts +1 -1
- package/libs-ui/react-core/src/Select/index.d.ts +1 -1
- package/libs-ui/react-core/src/SelectOption/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryList/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemKey/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemValue/index.d.ts +1 -1
- package/libs-ui/react-core/src/Tabs/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsHeading/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsList/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsPanel/index.d.ts +1 -1
- package/libs-ui/react-core/src/TextArea/index.d.ts +1 -1
- package/libs-ui/react-core/src/TextInput/index.d.ts +1 -1
- package/libs-ui/react-core/src/WarningText/index.d.ts +1 -1
- package/package.json +4 -3
- package/utils.js +1 -0
- package/validators.js +86 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
# Change Log - @digigov/form
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 16 Feb 2022 12:49:28 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.5.0
|
|
6
|
+
Wed, 16 Feb 2022 12:49:28 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Add new `date` field type that renders a three-block date input
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- Pin dayjs dependency
|
|
15
|
+
|
|
16
|
+
## 0.4.11
|
|
17
|
+
Mon, 14 Feb 2022 09:56:29 GMT
|
|
18
|
+
|
|
19
|
+
_Version update only_
|
|
20
|
+
|
|
21
|
+
## 0.4.10
|
|
22
|
+
Thu, 10 Feb 2022 13:45:56 GMT
|
|
23
|
+
|
|
24
|
+
### Patches
|
|
25
|
+
|
|
26
|
+
- pin down dependency versions
|
|
27
|
+
|
|
28
|
+
## 0.4.9
|
|
29
|
+
Tue, 08 Feb 2022 15:21:11 GMT
|
|
30
|
+
|
|
31
|
+
### Patches
|
|
32
|
+
|
|
33
|
+
- fix linting errors in @digigov/form
|
|
4
34
|
|
|
5
35
|
## 0.4.8
|
|
6
36
|
Thu, 03 Feb 2022 15:47:05 GMT
|
package/Field/index.js
CHANGED
|
@@ -43,6 +43,8 @@ var _Select = _interopRequireDefault(require("@digigov/form/inputs/Select"));
|
|
|
43
43
|
|
|
44
44
|
var _FileInput = _interopRequireDefault(require("@digigov/form/inputs/FileInput"));
|
|
45
45
|
|
|
46
|
+
var _DateInput = _interopRequireDefault(require("@digigov/form/inputs/DateInput"));
|
|
47
|
+
|
|
46
48
|
var _Label2 = _interopRequireDefault(require("@digigov/form/inputs/Label"));
|
|
47
49
|
|
|
48
50
|
var _i18n = require("@digigov/ui/app/i18n");
|
|
@@ -63,13 +65,18 @@ var FIELD_COMPONENTS = {
|
|
|
63
65
|
file: {
|
|
64
66
|
component: _FileInput["default"]
|
|
65
67
|
},
|
|
68
|
+
date: {
|
|
69
|
+
wrapper: 'fieldset',
|
|
70
|
+
controlled: true,
|
|
71
|
+
component: _DateInput["default"]
|
|
72
|
+
},
|
|
66
73
|
'choice:multiple': {
|
|
67
|
-
wrapper:
|
|
74
|
+
wrapper: 'fieldset',
|
|
68
75
|
controlled: true,
|
|
69
76
|
component: _Checkboxes["default"]
|
|
70
77
|
},
|
|
71
78
|
'choice:single': {
|
|
72
|
-
wrapper:
|
|
79
|
+
wrapper: 'fieldset',
|
|
73
80
|
controlled: false,
|
|
74
81
|
component: _Radio["default"]
|
|
75
82
|
}
|
package/Questions/Step/index.js
CHANGED
|
@@ -111,6 +111,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
111
111
|
|
|
112
112
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
113
113
|
|
|
114
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
114
115
|
var StepContext = /*#__PURE__*/(0, _react.createContext)({
|
|
115
116
|
name: '',
|
|
116
117
|
fields: [],
|
package/es/Field/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import Checkboxes from '@digigov/form/inputs/Checkboxes';
|
|
|
16
16
|
import Radio from '@digigov/form/inputs/Radio';
|
|
17
17
|
import Select from '@digigov/form/inputs/Select';
|
|
18
18
|
import FileInput from '@digigov/form/inputs/FileInput';
|
|
19
|
+
import DateInput from '@digigov/form/inputs/DateInput';
|
|
19
20
|
import Label from '@digigov/form/inputs/Label';
|
|
20
21
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
21
22
|
var FIELD_COMPONENTS = {
|
|
@@ -28,13 +29,18 @@ var FIELD_COMPONENTS = {
|
|
|
28
29
|
file: {
|
|
29
30
|
component: FileInput
|
|
30
31
|
},
|
|
32
|
+
date: {
|
|
33
|
+
wrapper: 'fieldset',
|
|
34
|
+
controlled: true,
|
|
35
|
+
component: DateInput
|
|
36
|
+
},
|
|
31
37
|
'choice:multiple': {
|
|
32
|
-
wrapper:
|
|
38
|
+
wrapper: 'fieldset',
|
|
33
39
|
controlled: true,
|
|
34
40
|
component: Checkboxes
|
|
35
41
|
},
|
|
36
42
|
'choice:single': {
|
|
37
|
-
wrapper:
|
|
43
|
+
wrapper: 'fieldset',
|
|
38
44
|
controlled: false,
|
|
39
45
|
component: Radio
|
|
40
46
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
6
|
import React, { createContext, useContext, useState } from 'react';
|
|
5
7
|
import { QuestionsContext } from '@digigov/form/Questions/';
|
|
6
8
|
import PageTitle, { PageTitleHeading } from '@digigov/ui/app/PageTitle';
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
6
|
import React, { createContext, useCallback, useRef } from 'react';
|
|
5
7
|
import { useForm } from 'react-hook-form';
|
|
6
8
|
import { yupResolver } from '@digigov/form/utils';
|
package/es/index.mdx
CHANGED
|
@@ -3,10 +3,7 @@ title: Form
|
|
|
3
3
|
parent: docs/ui/components
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { useState, useEffect } from 'react';
|
|
7
6
|
import FormBuilder from '@digigov/form/';
|
|
8
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
9
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
10
7
|
|
|
11
8
|
export const fields = [
|
|
12
9
|
{
|
|
@@ -20,8 +20,12 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
20
20
|
var newValue;
|
|
21
21
|
|
|
22
22
|
if (evt.currentTarget.checked) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore
|
|
23
25
|
newValue = value.concat([optionValue]);
|
|
24
26
|
} else {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore
|
|
25
29
|
newValue = value.filter(function (val) {
|
|
26
30
|
return val !== optionValue;
|
|
27
31
|
});
|
|
@@ -40,7 +44,9 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
40
44
|
return /*#__PURE__*/React.createElement(CheckboxItem, _extends({
|
|
41
45
|
name: name,
|
|
42
46
|
disabled: disabled,
|
|
43
|
-
key: key
|
|
47
|
+
key: key // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
,
|
|
44
50
|
checked: value.includes(option.value),
|
|
45
51
|
onChange: handleChange(option.value)
|
|
46
52
|
}, option), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(option.label.secondary)));
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
var _excluded = ["label"],
|
|
4
|
+
_excluded2 = ["name", "type"];
|
|
5
|
+
import React, { useMemo, useState } from 'react';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
8
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
9
|
+
import CoreDateInput from '@digigov/react-core/DateInput';
|
|
10
|
+
import CoreDateInputItem from '@digigov/react-core/DateInputItem';
|
|
11
|
+
dayjs.extend(customParseFormat);
|
|
12
|
+
|
|
13
|
+
function useDate(value, onChange) {
|
|
14
|
+
var _useMemo = useMemo(function () {
|
|
15
|
+
if (!value || value.length === '') {
|
|
16
|
+
return ['', '', ''];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var _value$split = value.split('/'),
|
|
20
|
+
_value$split2 = _slicedToArray(_value$split, 3),
|
|
21
|
+
day = _value$split2[0],
|
|
22
|
+
month = _value$split2[1],
|
|
23
|
+
year = _value$split2[2];
|
|
24
|
+
|
|
25
|
+
return [year, month, day];
|
|
26
|
+
}, [value]),
|
|
27
|
+
_useMemo2 = _slicedToArray(_useMemo, 3),
|
|
28
|
+
year = _useMemo2[0],
|
|
29
|
+
month = _useMemo2[1],
|
|
30
|
+
day = _useMemo2[2];
|
|
31
|
+
|
|
32
|
+
function set(year, month, day) {
|
|
33
|
+
var value = "".concat(day || '', "/").concat(month || '', "/").concat(year || '');
|
|
34
|
+
|
|
35
|
+
if (!year && !month && !day) {
|
|
36
|
+
onChange(null);
|
|
37
|
+
} else {
|
|
38
|
+
onChange(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function setYear(evt) {
|
|
43
|
+
var val = evt.target.value;
|
|
44
|
+
set(val, month, day);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function setMonth(evt, cast) {
|
|
48
|
+
var val = evt.target.value;
|
|
49
|
+
|
|
50
|
+
if (cast && val && val.length === 1) {
|
|
51
|
+
val = '0' + val;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set(year, val, day);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function setDay(evt, cast) {
|
|
58
|
+
var val = evt.target.value;
|
|
59
|
+
|
|
60
|
+
if (cast && val && val.length === 1) {
|
|
61
|
+
val = '0' + val;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
set(year, month, val);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
day: day,
|
|
69
|
+
month: month,
|
|
70
|
+
year: year,
|
|
71
|
+
setYear: setYear,
|
|
72
|
+
setMonth: setMonth,
|
|
73
|
+
setDay: setDay
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var VALID_FORMATS = ['DD/MM/YYYY'];
|
|
78
|
+
|
|
79
|
+
var makeDate = function makeDate(val) {
|
|
80
|
+
var date = dayjs(val, VALID_FORMATS, true);
|
|
81
|
+
|
|
82
|
+
if (date.isValid()) {
|
|
83
|
+
return date.format('DD/MM/YYYY');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return '';
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var DatePart = function DatePart(_ref) {
|
|
90
|
+
var label = _ref.label,
|
|
91
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
92
|
+
|
|
93
|
+
return /*#__PURE__*/React.createElement(CoreDateInputItem, props, label);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var DateInput = function DateInput(_ref2) {
|
|
97
|
+
var name = _ref2.name,
|
|
98
|
+
type = _ref2.type,
|
|
99
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
100
|
+
|
|
101
|
+
var _useTranslation = useTranslation(),
|
|
102
|
+
t = _useTranslation.t;
|
|
103
|
+
|
|
104
|
+
var _useState = useState(props.value),
|
|
105
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
106
|
+
initial = _useState2[0];
|
|
107
|
+
|
|
108
|
+
var value = useMemo(function () {
|
|
109
|
+
if (initial === props.value) {
|
|
110
|
+
return makeDate(props.value);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return props.value;
|
|
114
|
+
}, [props.value, initial]);
|
|
115
|
+
var date = useDate(value || makeDate(props.defaultValue), props.onChange);
|
|
116
|
+
return /*#__PURE__*/React.createElement(CoreDateInput, null, /*#__PURE__*/React.createElement(DatePart, {
|
|
117
|
+
label: t('form.label.day'),
|
|
118
|
+
onChange: date.setDay,
|
|
119
|
+
onBlur: function onBlur(e) {
|
|
120
|
+
return date.setDay(e, true);
|
|
121
|
+
},
|
|
122
|
+
value: date.day,
|
|
123
|
+
width: 2,
|
|
124
|
+
name: "".concat(name, "-day"),
|
|
125
|
+
maxlength: "2",
|
|
126
|
+
disabled: props.disabled
|
|
127
|
+
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
128
|
+
label: t('form.label.month'),
|
|
129
|
+
onChange: date.setMonth,
|
|
130
|
+
onBlur: function onBlur(e) {
|
|
131
|
+
return date.setMonth(e, true);
|
|
132
|
+
},
|
|
133
|
+
value: date.month,
|
|
134
|
+
width: 2,
|
|
135
|
+
name: "".concat(props.name, "-month"),
|
|
136
|
+
maxlength: "2",
|
|
137
|
+
disabled: props.disabled
|
|
138
|
+
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
139
|
+
label: t('form.label.year'),
|
|
140
|
+
onChange: date.setYear,
|
|
141
|
+
value: date.year,
|
|
142
|
+
width: 4,
|
|
143
|
+
name: "".concat(props.name, "-year"),
|
|
144
|
+
maxlength: "4",
|
|
145
|
+
disabled: props.disabled
|
|
146
|
+
}));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default DateInput;
|
|
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
3
|
import NormalText from '@digigov/react-core/NormalText';
|
|
4
4
|
import FileUpload from '@digigov/react-core/FileUpload';
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
6
|
var FileInput = /*#__PURE__*/React.forwardRef(function FileInput(_ref, ref) {
|
|
6
7
|
var name = _ref.name,
|
|
7
8
|
_ref$extra = _ref.extra,
|
package/es/inputs/Input/index.js
CHANGED
|
@@ -19,8 +19,10 @@ var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
|
|
|
19
19
|
var _ref2 = extra || {},
|
|
20
20
|
_ref2$multiline = _ref2.multiline,
|
|
21
21
|
multiline = _ref2$multiline === void 0 ? false : _ref2$multiline,
|
|
22
|
-
rows = _ref2.rows
|
|
23
|
-
|
|
22
|
+
rows = _ref2.rows;
|
|
23
|
+
|
|
24
|
+
var _ref3 = extra || {},
|
|
25
|
+
className = _ref3.className; // if enforced to multiline use true. Derive from type otherwise.
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
multiline = multiline === true || type === 'text'; // use explicit rows value if set. Derive from multiline otherwise.
|
|
@@ -40,6 +42,7 @@ var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
|
|
|
40
42
|
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
|
41
43
|
name: name,
|
|
42
44
|
type: fieldType,
|
|
45
|
+
className: className,
|
|
43
46
|
ref: ref
|
|
44
47
|
}, props));
|
|
45
48
|
}
|
package/es/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
4
4
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
5
5
|
import _extends from "@babel/runtime/helpers/extends";
|
|
6
6
|
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
8
|
var parseErrorSchema = function parseErrorSchema(error, validateAllFieldCriteria) {
|
|
8
9
|
return Array.isArray(error.inner) && error.inner.length ? error.inner.reduce(function (previous, _ref) {
|
|
9
10
|
var path = _ref.path,
|
package/es/validators.js
CHANGED
|
@@ -10,6 +10,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
10
10
|
import * as yup from 'yup';
|
|
11
11
|
import * as gPhoneNumber from 'google-libphonenumber';
|
|
12
12
|
import { useMemo } from 'react';
|
|
13
|
+
import dayjs from 'dayjs';
|
|
14
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
15
|
+
dayjs.extend(customParseFormat);
|
|
13
16
|
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
14
17
|
export function validateAFM(afm) {
|
|
15
18
|
if (afm.length !== 9) {
|
|
@@ -280,6 +283,13 @@ var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
|
280
283
|
};
|
|
281
284
|
};
|
|
282
285
|
|
|
286
|
+
var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
287
|
+
var DATE_CACHE = {};
|
|
288
|
+
|
|
289
|
+
var getDate = function getDate(v) {
|
|
290
|
+
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
291
|
+
};
|
|
292
|
+
|
|
283
293
|
function getYupField(field, yupTypeMap) {
|
|
284
294
|
var yupField = yupTypeMap[field.type] || yupTypeMap.string;
|
|
285
295
|
return yupField(field);
|
|
@@ -366,7 +376,8 @@ function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
366
376
|
return fieldSchemas;
|
|
367
377
|
}
|
|
368
378
|
|
|
369
|
-
function getYupObjectShape(
|
|
379
|
+
function getYupObjectShape( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
380
|
+
fields, yupTypeMap, validatorRegistry) {
|
|
370
381
|
if (!fields.current) {
|
|
371
382
|
var fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);
|
|
372
383
|
return yup.object().shape(fieldSchemas);
|
|
@@ -407,7 +418,6 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
407
418
|
iban: function iban(field) {
|
|
408
419
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
409
420
|
},
|
|
410
|
-
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
411
421
|
mobile_phone: function mobile_phone() {
|
|
412
422
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
413
423
|
},
|
|
@@ -416,12 +426,81 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
416
426
|
},
|
|
417
427
|
'choice:single': function choiceSingle() {
|
|
418
428
|
return yup.string().nullable();
|
|
429
|
+
},
|
|
430
|
+
date: function date(field) {
|
|
431
|
+
var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
|
|
432
|
+
if (!value) return true;
|
|
433
|
+
value = getDate(value);
|
|
434
|
+
return value.isValid();
|
|
435
|
+
});
|
|
436
|
+
var params = field.extra || {};
|
|
437
|
+
|
|
438
|
+
if (params.max) {
|
|
439
|
+
var maxDate;
|
|
440
|
+
|
|
441
|
+
if (params.max === 'now') {
|
|
442
|
+
var today = new Date();
|
|
443
|
+
maxDate = new Date(today);
|
|
444
|
+
} else {
|
|
445
|
+
maxDate = getDate(params.max).toDate();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
var maxNextDate = new Date(maxDate);
|
|
449
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
450
|
+
simpleDate = simpleDate.test({
|
|
451
|
+
name: 'earlier-than',
|
|
452
|
+
message: {
|
|
453
|
+
key: 'form.error.date.earlier_than',
|
|
454
|
+
context: {
|
|
455
|
+
maxDate: maxNextDate.toLocaleDateString()
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
test: function test(value) {
|
|
459
|
+
if (!value) return true;
|
|
460
|
+
value = getDate(value);
|
|
461
|
+
var isValid = +value.toDate() < +maxDate;
|
|
462
|
+
return isValid;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (params.min) {
|
|
468
|
+
var minDate;
|
|
469
|
+
|
|
470
|
+
if (params.min === 'now') {
|
|
471
|
+
var _today = new Date();
|
|
472
|
+
|
|
473
|
+
minDate = new Date(_today);
|
|
474
|
+
} else {
|
|
475
|
+
minDate = getDate(params.min).toDate();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
var minPreviousDate = new Date(minDate);
|
|
479
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
480
|
+
simpleDate = simpleDate.test({
|
|
481
|
+
name: 'later-than',
|
|
482
|
+
message: {
|
|
483
|
+
key: 'form.error.date.later_than',
|
|
484
|
+
context: {
|
|
485
|
+
minDate: minPreviousDate.toLocaleDateString()
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
test: function test(value) {
|
|
489
|
+
if (!value) return true;
|
|
490
|
+
value = getDate(value);
|
|
491
|
+
var isValid = +value.toDate() > +minDate;
|
|
492
|
+
return isValid;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return simpleDate;
|
|
419
498
|
}
|
|
420
499
|
};
|
|
421
500
|
return yupTypeMap;
|
|
422
|
-
};
|
|
423
|
-
|
|
501
|
+
};
|
|
424
502
|
|
|
503
|
+
// Create a yup validation schema from given fields input
|
|
425
504
|
export function useValidationSchema(fields, validatorRegistry) {
|
|
426
505
|
return useMemo(function () {
|
|
427
506
|
var yupTypeMap = getYUPTypeMap();
|
package/esm/Field/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import Checkboxes from '@digigov/form/inputs/Checkboxes';
|
|
|
16
16
|
import Radio from '@digigov/form/inputs/Radio';
|
|
17
17
|
import Select from '@digigov/form/inputs/Select';
|
|
18
18
|
import FileInput from '@digigov/form/inputs/FileInput';
|
|
19
|
+
import DateInput from '@digigov/form/inputs/DateInput';
|
|
19
20
|
import Label from '@digigov/form/inputs/Label';
|
|
20
21
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
21
22
|
var FIELD_COMPONENTS = {
|
|
@@ -28,13 +29,18 @@ var FIELD_COMPONENTS = {
|
|
|
28
29
|
file: {
|
|
29
30
|
component: FileInput
|
|
30
31
|
},
|
|
32
|
+
date: {
|
|
33
|
+
wrapper: 'fieldset',
|
|
34
|
+
controlled: true,
|
|
35
|
+
component: DateInput
|
|
36
|
+
},
|
|
31
37
|
'choice:multiple': {
|
|
32
|
-
wrapper:
|
|
38
|
+
wrapper: 'fieldset',
|
|
33
39
|
controlled: true,
|
|
34
40
|
component: Checkboxes
|
|
35
41
|
},
|
|
36
42
|
'choice:single': {
|
|
37
|
-
wrapper:
|
|
43
|
+
wrapper: 'fieldset',
|
|
38
44
|
controlled: false,
|
|
39
45
|
component: Radio
|
|
40
46
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
6
|
import React, { createContext, useContext, useState } from 'react';
|
|
5
7
|
import { QuestionsContext } from '@digigov/form/Questions/';
|
|
6
8
|
import PageTitle, { PageTitleHeading } from '@digigov/ui/app/PageTitle';
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Digigov v0.
|
|
1
|
+
/** @license Digigov v0.5.0
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
7
|
import _extends from "@babel/runtime/helpers/extends";
|
|
8
8
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
11
|
import React, { createContext, useCallback, useRef } from 'react';
|
|
10
12
|
import { useForm } from 'react-hook-form';
|
|
11
13
|
import { yupResolver } from '@digigov/form/utils';
|
package/esm/index.mdx
CHANGED
|
@@ -3,10 +3,7 @@ title: Form
|
|
|
3
3
|
parent: docs/ui/components
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { useState, useEffect } from 'react';
|
|
7
6
|
import FormBuilder from '@digigov/form/';
|
|
8
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
9
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
10
7
|
|
|
11
8
|
export const fields = [
|
|
12
9
|
{
|
|
@@ -20,8 +20,12 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
20
20
|
var newValue;
|
|
21
21
|
|
|
22
22
|
if (evt.currentTarget.checked) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore
|
|
23
25
|
newValue = value.concat([optionValue]);
|
|
24
26
|
} else {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore
|
|
25
29
|
newValue = value.filter(function (val) {
|
|
26
30
|
return val !== optionValue;
|
|
27
31
|
});
|
|
@@ -40,7 +44,9 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
40
44
|
return /*#__PURE__*/React.createElement(CheckboxItem, _extends({
|
|
41
45
|
name: name,
|
|
42
46
|
disabled: disabled,
|
|
43
|
-
key: key
|
|
47
|
+
key: key // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
,
|
|
44
50
|
checked: value.includes(option.value),
|
|
45
51
|
onChange: handleChange(option.value)
|
|
46
52
|
}, option), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(option.label.secondary)));
|