@digigov/form 0.10.16 → 0.11.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 +19 -1
- package/Field/utils.js +7 -0
- package/Form.stories.d.ts +0 -2
- package/Form.stories.js +0 -29
- package/FormBuilder/FormBuilder.js +2 -1
- package/es/Field/utils.js +6 -0
- package/es/Form.stories.js +1 -3
- package/es/FormBuilder/FormBuilder.js +2 -1
- package/es/inputs/AutoComplete/AutoComplete.stories.js +7 -0
- package/{esm/__stories__/AutoCompleteField.js → es/inputs/AutoComplete/__stories__/Default.js} +1 -1
- package/es/inputs/DateInput/index.js +9 -6
- package/es/inputs/Input/__stories__/Integer.js +8 -0
- package/es/inputs/OtpInput/OtpInput.stories.js +7 -0
- package/es/inputs/OtpInput/__stories__/Default.js +31 -0
- package/es/inputs/OtpInput/index.js +168 -0
- package/es/inputs/index.js +1 -0
- package/es/registry.js +4 -0
- package/es/validators/index.js +4 -1
- package/es/validators/utils/index.js +1 -0
- package/es/validators/utils/otp.js +26 -0
- package/esm/Field/utils.js +6 -0
- package/esm/Form.stories.js +1 -3
- package/esm/FormBuilder/FormBuilder.js +2 -1
- package/esm/index.js +1 -1
- package/esm/inputs/AutoComplete/AutoComplete.stories.js +7 -0
- package/{es/__stories__/AutoCompleteField.js → esm/inputs/AutoComplete/__stories__/Default.js} +1 -1
- package/esm/inputs/DateInput/index.js +9 -6
- package/esm/inputs/Input/__stories__/Integer.js +8 -0
- package/esm/inputs/OtpInput/OtpInput.stories.js +7 -0
- package/esm/inputs/OtpInput/__stories__/Default.js +31 -0
- package/esm/inputs/OtpInput/index.js +168 -0
- package/esm/inputs/index.js +1 -0
- package/esm/registry.js +4 -0
- package/esm/validators/index.js +4 -1
- package/esm/validators/utils/index.js +1 -0
- package/esm/validators/utils/otp.js +26 -0
- package/inputs/AutoComplete/AutoComplete.stories.d.ts +8 -0
- package/inputs/AutoComplete/AutoComplete.stories.js +31 -0
- package/inputs/AutoComplete/__stories__/Default.d.ts +1 -0
- package/{__stories__/AutoCompleteField.js → inputs/AutoComplete/__stories__/Default.js} +3 -3
- package/inputs/DateInput/index.js +9 -6
- package/inputs/Input/__stories__/Integer.js +8 -0
- package/inputs/OtpInput/OtpInput.stories.d.ts +8 -0
- package/inputs/OtpInput/OtpInput.stories.js +31 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.js +52 -0
- package/inputs/OtpInput/index.d.ts +8 -0
- package/inputs/OtpInput/index.js +193 -0
- package/inputs/index.d.ts +1 -0
- package/inputs/index.js +8 -0
- package/package.json +4 -4
- package/registry.d.ts +2 -0
- package/registry.js +6 -0
- package/src/Field/utils.ts +6 -0
- package/src/Form.stories.js +0 -2
- package/src/FormBuilder/FormBuilder.tsx +1 -0
- package/src/inputs/AutoComplete/AutoComplete.stories.js +7 -0
- package/src/{__stories__/AutoCompleteField.tsx → inputs/AutoComplete/__stories__/Default.tsx} +1 -1
- package/src/inputs/DateInput/index.tsx +6 -3
- package/src/inputs/Input/__stories__/Integer.tsx +30 -18
- package/src/inputs/OtpInput/OtpInput.stories.js +7 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +32 -0
- package/src/inputs/OtpInput/index.tsx +164 -0
- package/src/inputs/index.ts +1 -0
- package/src/registry.js +4 -0
- package/src/types.tsx +2 -0
- package/src/validators/index.ts +2 -0
- package/src/validators/utils/index.ts +1 -0
- package/src/validators/utils/otp.ts +28 -0
- package/types.d.ts +2 -1
- package/validators/index.js +3 -0
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +14 -0
- package/validators/utils/otp.d.ts +4 -0
- package/validators/utils/otp.js +37 -0
- package/Form.stories.playwright.json +0 -71
- package/__stories__/AutoCompleteField.d.ts +0 -1
- package/__stories__/IntField.d.ts +0 -1
- package/__stories__/IntField.js +0 -56
- package/es/Form.stories.playwright.json +0 -71
- package/es/__stories__/IntField.js +0 -41
- package/esm/Form.stories.playwright.json +0 -71
- package/esm/__stories__/IntField.js +0 -41
- package/src/Form.stories.playwright.json +0 -71
- package/src/__stories__/IntField.tsx +0 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
# Change Log - @digigov/form
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 11 May 2023 10:48:56 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.11.1
|
|
6
|
+
Thu, 11 May 2023 10:48:56 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Fix input error validations for OtpInput and DateInput
|
|
11
|
+
|
|
12
|
+
## 0.11.0
|
|
13
|
+
Tue, 02 May 2023 09:16:06 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Create OtpInput component, add validators and types
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Update form stories
|
|
4
22
|
|
|
5
23
|
## 0.10.16
|
|
6
24
|
Mon, 03 Apr 2023 11:13:15 GMT
|
package/Field/utils.js
CHANGED
|
@@ -27,6 +27,8 @@ var _FileInput = _interopRequireDefault(require("@digigov/form/inputs/FileInput"
|
|
|
27
27
|
|
|
28
28
|
var _DateInput = _interopRequireDefault(require("@digigov/form/inputs/DateInput"));
|
|
29
29
|
|
|
30
|
+
var _OtpInput = _interopRequireDefault(require("@digigov/form/inputs/OtpInput"));
|
|
31
|
+
|
|
30
32
|
var _FormContext = require("@digigov/form/FormContext");
|
|
31
33
|
|
|
32
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -54,6 +56,11 @@ var FIELD_COMPONENTS = {
|
|
|
54
56
|
controlled: true,
|
|
55
57
|
component: _DateInput["default"]
|
|
56
58
|
},
|
|
59
|
+
otp: {
|
|
60
|
+
wrapper: 'fieldset',
|
|
61
|
+
controlled: true,
|
|
62
|
+
component: _OtpInput["default"]
|
|
63
|
+
},
|
|
57
64
|
'choice:multiple': {
|
|
58
65
|
wrapper: 'fieldset',
|
|
59
66
|
controlled: true,
|
package/Form.stories.d.ts
CHANGED
package/Form.stories.js
CHANGED
|
@@ -3,36 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {};
|
|
7
6
|
exports["default"] = void 0;
|
|
8
|
-
|
|
9
|
-
var _IntField = require("@digigov/form/__stories__/IntField");
|
|
10
|
-
|
|
11
|
-
Object.keys(_IntField).forEach(function (key) {
|
|
12
|
-
if (key === "default" || key === "__esModule") return;
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
14
|
-
if (key in exports && exports[key] === _IntField[key]) return;
|
|
15
|
-
Object.defineProperty(exports, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function get() {
|
|
18
|
-
return _IntField[key];
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
var _AutoCompleteField = require("@digigov/form/__stories__/AutoCompleteField");
|
|
24
|
-
|
|
25
|
-
Object.keys(_AutoCompleteField).forEach(function (key) {
|
|
26
|
-
if (key === "default" || key === "__esModule") return;
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
-
if (key in exports && exports[key] === _AutoCompleteField[key]) return;
|
|
29
|
-
Object.defineProperty(exports, key, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function get() {
|
|
32
|
-
return _AutoCompleteField[key];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
7
|
var _default = {
|
|
37
8
|
title: 'Digigov Form'
|
|
38
9
|
};
|
|
@@ -80,7 +80,8 @@ var FormBase = /*#__PURE__*/_react["default"].forwardRef(function FormBase(_ref,
|
|
|
80
80
|
clearErrors: form.clearErrors,
|
|
81
81
|
getValues: form.getValues,
|
|
82
82
|
unregister: form.unregister,
|
|
83
|
-
componentRegistry: componentRegistry
|
|
83
|
+
componentRegistry: componentRegistry,
|
|
84
|
+
setError: form.setError
|
|
84
85
|
};
|
|
85
86
|
return /*#__PURE__*/_react["default"].createElement(_FormContext.FormContext.Provider, {
|
|
86
87
|
value: ctx
|
package/es/Field/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ import Radio from '@digigov/form/inputs/Radio';
|
|
|
6
6
|
import Select from '@digigov/form/inputs/Select';
|
|
7
7
|
import FileInput from '@digigov/form/inputs/FileInput';
|
|
8
8
|
import DateInput from '@digigov/form/inputs/DateInput';
|
|
9
|
+
import OtpInput from '@digigov/form/inputs/OtpInput';
|
|
9
10
|
import { FormContext } from '@digigov/form/FormContext';
|
|
10
11
|
var AutoComplete = /*#__PURE__*/lazy(function () {
|
|
11
12
|
return import('@digigov/form/inputs/AutoComplete');
|
|
@@ -26,6 +27,11 @@ var FIELD_COMPONENTS = {
|
|
|
26
27
|
controlled: true,
|
|
27
28
|
component: DateInput
|
|
28
29
|
},
|
|
30
|
+
otp: {
|
|
31
|
+
wrapper: 'fieldset',
|
|
32
|
+
controlled: true,
|
|
33
|
+
component: OtpInput
|
|
34
|
+
},
|
|
29
35
|
'choice:multiple': {
|
|
30
36
|
wrapper: 'fieldset',
|
|
31
37
|
controlled: true,
|
package/es/Form.stories.js
CHANGED
|
@@ -56,7 +56,8 @@ export var FormBase = /*#__PURE__*/React.forwardRef(function FormBase(_ref, ref)
|
|
|
56
56
|
clearErrors: form.clearErrors,
|
|
57
57
|
getValues: form.getValues,
|
|
58
58
|
unregister: form.unregister,
|
|
59
|
-
componentRegistry: componentRegistry
|
|
59
|
+
componentRegistry: componentRegistry,
|
|
60
|
+
setError: form.setError
|
|
60
61
|
};
|
|
61
62
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
62
63
|
value: ctx
|
package/{esm/__stories__/AutoCompleteField.js → es/inputs/AutoComplete/__stories__/Default.js}
RENAMED
|
@@ -31,7 +31,7 @@ var _ref2 = /*#__PURE__*/React.createElement(Button, {
|
|
|
31
31
|
type: "submit"
|
|
32
32
|
}, "Submit");
|
|
33
33
|
|
|
34
|
-
export var
|
|
34
|
+
export var Default = function Default() {
|
|
35
35
|
return /*#__PURE__*/React.createElement(Suspense, {
|
|
36
36
|
fallback: _ref
|
|
37
37
|
}, /*#__PURE__*/React.createElement(FormBuilder, {
|
|
@@ -123,9 +123,10 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
123
123
|
value: date.day,
|
|
124
124
|
width: 2,
|
|
125
125
|
name: "".concat(name, "-day"),
|
|
126
|
-
|
|
126
|
+
maxLength: "2",
|
|
127
127
|
disabled: props.disabled,
|
|
128
|
-
"aria-required": props['aria-required']
|
|
128
|
+
"aria-required": props['aria-required'],
|
|
129
|
+
error: !date.day ? props.error : false
|
|
129
130
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
130
131
|
label: t('form.label.month'),
|
|
131
132
|
onChange: date.setMonth,
|
|
@@ -135,18 +136,20 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
135
136
|
value: date.month,
|
|
136
137
|
width: 2,
|
|
137
138
|
name: "".concat(props.name, "-month"),
|
|
138
|
-
|
|
139
|
+
maxLength: "2",
|
|
139
140
|
disabled: props.disabled,
|
|
140
|
-
"aria-required": props['aria-required']
|
|
141
|
+
"aria-required": props['aria-required'],
|
|
142
|
+
error: !date.month ? props.error : false
|
|
141
143
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
142
144
|
label: t('form.label.year'),
|
|
143
145
|
onChange: date.setYear,
|
|
144
146
|
value: date.year,
|
|
145
147
|
width: 4,
|
|
146
148
|
name: "".concat(props.name, "-year"),
|
|
147
|
-
|
|
149
|
+
maxLength: "4",
|
|
148
150
|
disabled: props.disabled,
|
|
149
|
-
"aria-required": props['aria-required']
|
|
151
|
+
"aria-required": props['aria-required'],
|
|
152
|
+
error: !date.year ? props.error : false
|
|
150
153
|
}));
|
|
151
154
|
};
|
|
152
155
|
export default DateInput;
|
|
@@ -20,6 +20,14 @@ export var Integer = function Integer() {
|
|
|
20
20
|
secondary: 'Εισάγετε έναν οποιοδήποτε αριθμό μεγαλύτερο από το μηδέν'
|
|
21
21
|
},
|
|
22
22
|
required: true
|
|
23
|
+
}), /*#__PURE__*/React.createElement(Field, {
|
|
24
|
+
key: "random-number-not-req",
|
|
25
|
+
name: "random-number-not-req",
|
|
26
|
+
type: "int",
|
|
27
|
+
label: {
|
|
28
|
+
primary: 'Δεύτερος τυχαίος αριθμός',
|
|
29
|
+
secondary: 'Προαιρετικό πεδίο'
|
|
30
|
+
}
|
|
23
31
|
}), _ref);
|
|
24
32
|
};
|
|
25
33
|
export default Integer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field, Fieldset } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
var FIELDS = [{
|
|
5
|
+
key: 'otp',
|
|
6
|
+
type: 'otp',
|
|
7
|
+
maxLength: 6,
|
|
8
|
+
required: true,
|
|
9
|
+
label: {
|
|
10
|
+
primary: 'Κωδικός Επιβεβαίωσης'
|
|
11
|
+
}
|
|
12
|
+
}];
|
|
13
|
+
|
|
14
|
+
var _ref = /*#__PURE__*/React.createElement(Button, {
|
|
15
|
+
type: "submit"
|
|
16
|
+
}, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
|
|
17
|
+
|
|
18
|
+
export var Default = function Default() {
|
|
19
|
+
return /*#__PURE__*/React.createElement(FormBuilder, {
|
|
20
|
+
fields: FIELDS,
|
|
21
|
+
onSubmit: function onSubmit(data) {
|
|
22
|
+
console.log(data);
|
|
23
|
+
}
|
|
24
|
+
}, /*#__PURE__*/React.createElement(Fieldset, null, FIELDS.map(function (field) {
|
|
25
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
26
|
+
key: field.key,
|
|
27
|
+
name: field.key
|
|
28
|
+
});
|
|
29
|
+
})), _ref);
|
|
30
|
+
};
|
|
31
|
+
export default Default;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
|
+
var _excluded = ["name", "maxLength"];
|
|
6
|
+
import React, { useState, useCallback } from 'react';
|
|
7
|
+
import SingleCharacterInputContainer, { SingleCharacterInputItem } from '@digigov/ui/core/SingleCharacterInputContainer';
|
|
8
|
+
export var RE_DIGIT = new RegExp(/^\d+$/);
|
|
9
|
+
export var REMOVE_SPACES = new RegExp(/\s+/g);
|
|
10
|
+
|
|
11
|
+
function useOtp(onChange, maxLength) {
|
|
12
|
+
var _useState = useState(Array(maxLength).fill('')),
|
|
13
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
14
|
+
otpValues = _useState2[0],
|
|
15
|
+
setOTPValues = _useState2[1];
|
|
16
|
+
|
|
17
|
+
var handleOtpChange = useCallback(function (otp) {
|
|
18
|
+
var otpValue = otp.join('');
|
|
19
|
+
onChange(otpValue);
|
|
20
|
+
}, [onChange]);
|
|
21
|
+
|
|
22
|
+
var itemsArray = function itemsArray(item, idx) {
|
|
23
|
+
var updatedOTPValues = _toConsumableArray(otpValues);
|
|
24
|
+
|
|
25
|
+
if (item.length === 1 || item.length === 0) {
|
|
26
|
+
updatedOTPValues[idx] = item[0] || '';
|
|
27
|
+
setOTPValues(updatedOTPValues);
|
|
28
|
+
handleOtpChange(updatedOTPValues);
|
|
29
|
+
} else if (item.length === maxLength) {
|
|
30
|
+
var valueArray = item.split('');
|
|
31
|
+
var items = [];
|
|
32
|
+
|
|
33
|
+
for (var i = 0; i < maxLength; i++) {
|
|
34
|
+
var _char = valueArray[i];
|
|
35
|
+
items.push(_char);
|
|
36
|
+
setOTPValues(items);
|
|
37
|
+
handleOtpChange(items);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var SelectionRange = useCallback(function (target) {
|
|
43
|
+
return target.setSelectionRange(0, target.value.length);
|
|
44
|
+
}, []);
|
|
45
|
+
var focusToNextInput = useCallback(function (target) {
|
|
46
|
+
var nextElement = target.nextElementSibling;
|
|
47
|
+
|
|
48
|
+
if (nextElement) {
|
|
49
|
+
nextElement.focus();
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
var focusToPrevInput = useCallback(function (target) {
|
|
53
|
+
var previousElement = target.previousElementSibling;
|
|
54
|
+
|
|
55
|
+
if (previousElement) {
|
|
56
|
+
previousElement.focus();
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
var inputOnKeyDown = useCallback(function (e, idx) {
|
|
60
|
+
var key = e.key;
|
|
61
|
+
var target = e.target;
|
|
62
|
+
var targetValue = target.value;
|
|
63
|
+
SelectionRange(target);
|
|
64
|
+
|
|
65
|
+
if (key === 'ArrowRight' || key === 'ArrowDown') {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
return focusToNextInput(target);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (key === 'ArrowLeft' || key === 'ArrowUp') {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
return focusToPrevInput(target);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
76
|
+
if (targetValue !== '') {
|
|
77
|
+
targetValue = '';
|
|
78
|
+
} else {
|
|
79
|
+
focusToPrevInput(target);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
itemsArray(targetValue, idx);
|
|
83
|
+
return e.preventDefault();
|
|
84
|
+
}
|
|
85
|
+
}, [itemsArray, focusToPrevInput, focusToNextInput]);
|
|
86
|
+
var inputOnFocus = useCallback(function (e) {
|
|
87
|
+
var target = e.target;
|
|
88
|
+
SelectionRange(target);
|
|
89
|
+
}, [SelectionRange]);
|
|
90
|
+
var inputOnChange = useCallback(function (e, idx) {
|
|
91
|
+
var target = e.target;
|
|
92
|
+
var targetValue = target.value;
|
|
93
|
+
var isTargetValueDigit = RE_DIGIT.test(targetValue);
|
|
94
|
+
|
|
95
|
+
if (!isTargetValueDigit && e.target.value !== '') {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
targetValue = isTargetValueDigit ? targetValue : '';
|
|
100
|
+
itemsArray(targetValue, idx);
|
|
101
|
+
|
|
102
|
+
if (target.value.length > 1) {
|
|
103
|
+
target.blur();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!isTargetValueDigit) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
focusToNextInput(target);
|
|
111
|
+
}, [handleOtpChange, itemsArray, inputOnKeyDown, inputOnFocus]);
|
|
112
|
+
var handleOnPaste = useCallback(function (e) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
var pastedData = e.clipboardData.getData('text/plain').replace(REMOVE_SPACES, '');
|
|
115
|
+
|
|
116
|
+
if (pastedData) {
|
|
117
|
+
itemsArray(pastedData, 0);
|
|
118
|
+
}
|
|
119
|
+
}, []);
|
|
120
|
+
return {
|
|
121
|
+
otpValues: otpValues,
|
|
122
|
+
inputOnChange: inputOnChange,
|
|
123
|
+
inputOnKeyDown: inputOnKeyDown,
|
|
124
|
+
inputOnFocus: inputOnFocus,
|
|
125
|
+
handleOnPaste: handleOnPaste
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var SingleCharacterInputItemPart = function SingleCharacterInputItemPart(_ref) {
|
|
130
|
+
var props = _extends({}, _ref);
|
|
131
|
+
|
|
132
|
+
return /*#__PURE__*/React.createElement(SingleCharacterInputItem, props);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export var OtpInput = function OtpInput(_ref2) {
|
|
136
|
+
var name = _ref2.name,
|
|
137
|
+
_ref2$maxLength = _ref2.maxLength,
|
|
138
|
+
maxLength = _ref2$maxLength === void 0 ? 6 : _ref2$maxLength,
|
|
139
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
140
|
+
|
|
141
|
+
var otp = useOtp(props.onChange, maxLength);
|
|
142
|
+
return /*#__PURE__*/React.createElement(SingleCharacterInputContainer, null, otp.otpValues.map(function (digit, idx) {
|
|
143
|
+
return /*#__PURE__*/React.createElement(SingleCharacterInputItemPart, {
|
|
144
|
+
name: "".concat(name, "-").concat(idx),
|
|
145
|
+
type: "text",
|
|
146
|
+
key: idx,
|
|
147
|
+
autoComplete: "one-time-code",
|
|
148
|
+
pattern: "\\d{1}",
|
|
149
|
+
maxLength: maxLength,
|
|
150
|
+
value: digit,
|
|
151
|
+
disabled: props.disabled,
|
|
152
|
+
"aria-required": props['aria-required'],
|
|
153
|
+
onChange: function onChange(e) {
|
|
154
|
+
return otp.inputOnChange(e, idx);
|
|
155
|
+
},
|
|
156
|
+
onInput: function onInput(e) {
|
|
157
|
+
return otp.inputOnChange(e, idx);
|
|
158
|
+
},
|
|
159
|
+
onKeyDown: function onKeyDown(e) {
|
|
160
|
+
return otp.inputOnKeyDown(e, idx);
|
|
161
|
+
},
|
|
162
|
+
onFocus: otp.inputOnFocus,
|
|
163
|
+
onPaste: otp.handleOnPaste,
|
|
164
|
+
error: !digit ? props.error : false
|
|
165
|
+
});
|
|
166
|
+
}));
|
|
167
|
+
};
|
|
168
|
+
export default OtpInput;
|
package/es/inputs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Checkboxes } from '@digigov/form/inputs/Checkboxes';
|
|
2
2
|
export { default as DateInput } from '@digigov/form/inputs/DateInput';
|
|
3
|
+
export { default as OtpInput } from '@digigov/form/inputs/OtpInput';
|
|
3
4
|
export { default as FileInput } from '@digigov/form/inputs/FileInput';
|
|
4
5
|
export { default as Input } from '@digigov/form/inputs/Input';
|
|
5
6
|
export { default as Label } from '@digigov/form/inputs/Label';
|
package/es/registry.js
CHANGED
|
@@ -20,6 +20,7 @@ import * as _digigov_form_inputs_FileInput from '@digigov/form/inputs/FileInput'
|
|
|
20
20
|
import * as _digigov_form_inputs from '@digigov/form/inputs';
|
|
21
21
|
import * as _digigov_form_inputs_Input from '@digigov/form/inputs/Input';
|
|
22
22
|
import * as _digigov_form_inputs_Label from '@digigov/form/inputs/Label';
|
|
23
|
+
import * as _digigov_form_inputs_OtpInput from '@digigov/form/inputs/OtpInput';
|
|
23
24
|
import * as _digigov_form_inputs_Radio from '@digigov/form/inputs/Radio';
|
|
24
25
|
import * as _digigov_form_inputs_Select from '@digigov/form/inputs/Select';
|
|
25
26
|
import * as _digigov_form_internal from '@digigov/form/internal';
|
|
@@ -51,6 +52,7 @@ import * as _digigov_form_validators_utils_iban from '@digigov/form/validators/u
|
|
|
51
52
|
import * as _digigov_form_validators_utils from '@digigov/form/validators/utils';
|
|
52
53
|
import * as _digigov_form_validators_utils_int from '@digigov/form/validators/utils/int';
|
|
53
54
|
import * as _digigov_form_validators_utils_number from '@digigov/form/validators/utils/number';
|
|
55
|
+
import * as _digigov_form_validators_utils_otp from '@digigov/form/validators/utils/otp';
|
|
54
56
|
import * as _digigov_form_validators_utils_phone from '@digigov/form/validators/utils/phone';
|
|
55
57
|
import * as _digigov_form_validators_utils_postal_code from '@digigov/form/validators/utils/postal_code';
|
|
56
58
|
import * as _digigov_form_validators_utils_uuid4 from '@digigov/form/validators/utils/uuid4';
|
|
@@ -92,6 +94,7 @@ export default {
|
|
|
92
94
|
'@digigov/form/inputs': lazyImport(_digigov_form_inputs),
|
|
93
95
|
'@digigov/form/inputs/Input': lazyImport(_digigov_form_inputs_Input),
|
|
94
96
|
'@digigov/form/inputs/Label': lazyImport(_digigov_form_inputs_Label),
|
|
97
|
+
'@digigov/form/inputs/OtpInput': lazyImport(_digigov_form_inputs_OtpInput),
|
|
95
98
|
'@digigov/form/inputs/Radio': lazyImport(_digigov_form_inputs_Radio),
|
|
96
99
|
'@digigov/form/inputs/Select': lazyImport(_digigov_form_inputs_Select),
|
|
97
100
|
'@digigov/form/internal': lazyImport(_digigov_form_internal),
|
|
@@ -123,6 +126,7 @@ export default {
|
|
|
123
126
|
'@digigov/form/validators/utils': lazyImport(_digigov_form_validators_utils),
|
|
124
127
|
'@digigov/form/validators/utils/int': lazyImport(_digigov_form_validators_utils_int),
|
|
125
128
|
'@digigov/form/validators/utils/number': lazyImport(_digigov_form_validators_utils_number),
|
|
129
|
+
'@digigov/form/validators/utils/otp': lazyImport(_digigov_form_validators_utils_otp),
|
|
126
130
|
'@digigov/form/validators/utils/phone': lazyImport(_digigov_form_validators_utils_phone),
|
|
127
131
|
'@digigov/form/validators/utils/postal_code': lazyImport(_digigov_form_validators_utils_postal_code),
|
|
128
132
|
'@digigov/form/validators/utils/uuid4': lazyImport(_digigov_form_validators_utils_uuid4)
|
package/es/validators/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as yup from 'yup';
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
6
|
-
import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR } from '@digigov/form/validators/utils';
|
|
6
|
+
import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, OTP_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR } from '@digigov/form/validators/utils';
|
|
7
7
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
8
8
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
9
9
|
dayjs.extend(customParseFormat);
|
|
@@ -79,6 +79,9 @@ export var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
79
79
|
iban: function iban(field) {
|
|
80
80
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
81
81
|
},
|
|
82
|
+
otp: function otp(field) {
|
|
83
|
+
return yup.string().test(OTP_VALIDATOR(field));
|
|
84
|
+
},
|
|
82
85
|
postal_code: function postal_code(field) {
|
|
83
86
|
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
84
87
|
},
|
|
@@ -2,6 +2,7 @@ import * as yup from 'yup';
|
|
|
2
2
|
export * from '@digigov/form/validators/utils/afm';
|
|
3
3
|
export * from '@digigov/form/validators/utils/file';
|
|
4
4
|
export * from '@digigov/form/validators/utils/iban';
|
|
5
|
+
export * from '@digigov/form/validators/utils/otp';
|
|
5
6
|
export * from '@digigov/form/validators/utils/phone';
|
|
6
7
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
7
8
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function validateOtp(value, maxLength) {
|
|
2
|
+
if (value.length === maxLength) {
|
|
3
|
+
return true;
|
|
4
|
+
} else {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export var OTP_VALIDATOR = function OTP_VALIDATOR(field) {
|
|
9
|
+
var maxLength = field === null || field === void 0 ? void 0 : field.maxLength;
|
|
10
|
+
return {
|
|
11
|
+
name: 'otp-validator',
|
|
12
|
+
message: {
|
|
13
|
+
key: 'form.error.otp.less_than',
|
|
14
|
+
context: {
|
|
15
|
+
maxLength: field === null || field === void 0 ? void 0 : field.maxLength
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
test: function test(value) {
|
|
19
|
+
if (!value) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return validateOtp(value, maxLength);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
package/esm/Field/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ import Radio from '@digigov/form/inputs/Radio';
|
|
|
6
6
|
import Select from '@digigov/form/inputs/Select';
|
|
7
7
|
import FileInput from '@digigov/form/inputs/FileInput';
|
|
8
8
|
import DateInput from '@digigov/form/inputs/DateInput';
|
|
9
|
+
import OtpInput from '@digigov/form/inputs/OtpInput';
|
|
9
10
|
import { FormContext } from '@digigov/form/FormContext';
|
|
10
11
|
var AutoComplete = /*#__PURE__*/lazy(function () {
|
|
11
12
|
return import('@digigov/form/inputs/AutoComplete');
|
|
@@ -26,6 +27,11 @@ var FIELD_COMPONENTS = {
|
|
|
26
27
|
controlled: true,
|
|
27
28
|
component: DateInput
|
|
28
29
|
},
|
|
30
|
+
otp: {
|
|
31
|
+
wrapper: 'fieldset',
|
|
32
|
+
controlled: true,
|
|
33
|
+
component: OtpInput
|
|
34
|
+
},
|
|
29
35
|
'choice:multiple': {
|
|
30
36
|
wrapper: 'fieldset',
|
|
31
37
|
controlled: true,
|
package/esm/Form.stories.js
CHANGED
|
@@ -56,7 +56,8 @@ export var FormBase = /*#__PURE__*/React.forwardRef(function FormBase(_ref, ref)
|
|
|
56
56
|
clearErrors: form.clearErrors,
|
|
57
57
|
getValues: form.getValues,
|
|
58
58
|
unregister: form.unregister,
|
|
59
|
-
componentRegistry: componentRegistry
|
|
59
|
+
componentRegistry: componentRegistry,
|
|
60
|
+
setError: form.setError
|
|
60
61
|
};
|
|
61
62
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
62
63
|
value: ctx
|
package/esm/index.js
CHANGED
package/{es/__stories__/AutoCompleteField.js → esm/inputs/AutoComplete/__stories__/Default.js}
RENAMED
|
@@ -31,7 +31,7 @@ var _ref2 = /*#__PURE__*/React.createElement(Button, {
|
|
|
31
31
|
type: "submit"
|
|
32
32
|
}, "Submit");
|
|
33
33
|
|
|
34
|
-
export var
|
|
34
|
+
export var Default = function Default() {
|
|
35
35
|
return /*#__PURE__*/React.createElement(Suspense, {
|
|
36
36
|
fallback: _ref
|
|
37
37
|
}, /*#__PURE__*/React.createElement(FormBuilder, {
|
|
@@ -123,9 +123,10 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
123
123
|
value: date.day,
|
|
124
124
|
width: 2,
|
|
125
125
|
name: "".concat(name, "-day"),
|
|
126
|
-
|
|
126
|
+
maxLength: "2",
|
|
127
127
|
disabled: props.disabled,
|
|
128
|
-
"aria-required": props['aria-required']
|
|
128
|
+
"aria-required": props['aria-required'],
|
|
129
|
+
error: !date.day ? props.error : false
|
|
129
130
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
130
131
|
label: t('form.label.month'),
|
|
131
132
|
onChange: date.setMonth,
|
|
@@ -135,18 +136,20 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
135
136
|
value: date.month,
|
|
136
137
|
width: 2,
|
|
137
138
|
name: "".concat(props.name, "-month"),
|
|
138
|
-
|
|
139
|
+
maxLength: "2",
|
|
139
140
|
disabled: props.disabled,
|
|
140
|
-
"aria-required": props['aria-required']
|
|
141
|
+
"aria-required": props['aria-required'],
|
|
142
|
+
error: !date.month ? props.error : false
|
|
141
143
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
142
144
|
label: t('form.label.year'),
|
|
143
145
|
onChange: date.setYear,
|
|
144
146
|
value: date.year,
|
|
145
147
|
width: 4,
|
|
146
148
|
name: "".concat(props.name, "-year"),
|
|
147
|
-
|
|
149
|
+
maxLength: "4",
|
|
148
150
|
disabled: props.disabled,
|
|
149
|
-
"aria-required": props['aria-required']
|
|
151
|
+
"aria-required": props['aria-required'],
|
|
152
|
+
error: !date.year ? props.error : false
|
|
150
153
|
}));
|
|
151
154
|
};
|
|
152
155
|
export default DateInput;
|
|
@@ -20,6 +20,14 @@ export var Integer = function Integer() {
|
|
|
20
20
|
secondary: 'Εισάγετε έναν οποιοδήποτε αριθμό μεγαλύτερο από το μηδέν'
|
|
21
21
|
},
|
|
22
22
|
required: true
|
|
23
|
+
}), /*#__PURE__*/React.createElement(Field, {
|
|
24
|
+
key: "random-number-not-req",
|
|
25
|
+
name: "random-number-not-req",
|
|
26
|
+
type: "int",
|
|
27
|
+
label: {
|
|
28
|
+
primary: 'Δεύτερος τυχαίος αριθμός',
|
|
29
|
+
secondary: 'Προαιρετικό πεδίο'
|
|
30
|
+
}
|
|
23
31
|
}), _ref);
|
|
24
32
|
};
|
|
25
33
|
export default Integer;
|