@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/Field/utils.js +7 -0
  3. package/Form.stories.d.ts +0 -2
  4. package/Form.stories.js +0 -29
  5. package/FormBuilder/FormBuilder.js +2 -1
  6. package/es/Field/utils.js +6 -0
  7. package/es/Form.stories.js +1 -3
  8. package/es/FormBuilder/FormBuilder.js +2 -1
  9. package/es/inputs/AutoComplete/AutoComplete.stories.js +7 -0
  10. package/{esm/__stories__/AutoCompleteField.js → es/inputs/AutoComplete/__stories__/Default.js} +1 -1
  11. package/es/inputs/DateInput/index.js +9 -6
  12. package/es/inputs/Input/__stories__/Integer.js +8 -0
  13. package/es/inputs/OtpInput/OtpInput.stories.js +7 -0
  14. package/es/inputs/OtpInput/__stories__/Default.js +31 -0
  15. package/es/inputs/OtpInput/index.js +168 -0
  16. package/es/inputs/index.js +1 -0
  17. package/es/registry.js +4 -0
  18. package/es/validators/index.js +4 -1
  19. package/es/validators/utils/index.js +1 -0
  20. package/es/validators/utils/otp.js +26 -0
  21. package/esm/Field/utils.js +6 -0
  22. package/esm/Form.stories.js +1 -3
  23. package/esm/FormBuilder/FormBuilder.js +2 -1
  24. package/esm/index.js +1 -1
  25. package/esm/inputs/AutoComplete/AutoComplete.stories.js +7 -0
  26. package/{es/__stories__/AutoCompleteField.js → esm/inputs/AutoComplete/__stories__/Default.js} +1 -1
  27. package/esm/inputs/DateInput/index.js +9 -6
  28. package/esm/inputs/Input/__stories__/Integer.js +8 -0
  29. package/esm/inputs/OtpInput/OtpInput.stories.js +7 -0
  30. package/esm/inputs/OtpInput/__stories__/Default.js +31 -0
  31. package/esm/inputs/OtpInput/index.js +168 -0
  32. package/esm/inputs/index.js +1 -0
  33. package/esm/registry.js +4 -0
  34. package/esm/validators/index.js +4 -1
  35. package/esm/validators/utils/index.js +1 -0
  36. package/esm/validators/utils/otp.js +26 -0
  37. package/inputs/AutoComplete/AutoComplete.stories.d.ts +8 -0
  38. package/inputs/AutoComplete/AutoComplete.stories.js +31 -0
  39. package/inputs/AutoComplete/__stories__/Default.d.ts +1 -0
  40. package/{__stories__/AutoCompleteField.js → inputs/AutoComplete/__stories__/Default.js} +3 -3
  41. package/inputs/DateInput/index.js +9 -6
  42. package/inputs/Input/__stories__/Integer.js +8 -0
  43. package/inputs/OtpInput/OtpInput.stories.d.ts +8 -0
  44. package/inputs/OtpInput/OtpInput.stories.js +31 -0
  45. package/inputs/OtpInput/__stories__/Default.d.ts +2 -0
  46. package/inputs/OtpInput/__stories__/Default.js +52 -0
  47. package/inputs/OtpInput/index.d.ts +8 -0
  48. package/inputs/OtpInput/index.js +193 -0
  49. package/inputs/index.d.ts +1 -0
  50. package/inputs/index.js +8 -0
  51. package/package.json +4 -4
  52. package/registry.d.ts +2 -0
  53. package/registry.js +6 -0
  54. package/src/Field/utils.ts +6 -0
  55. package/src/Form.stories.js +0 -2
  56. package/src/FormBuilder/FormBuilder.tsx +1 -0
  57. package/src/inputs/AutoComplete/AutoComplete.stories.js +7 -0
  58. package/src/{__stories__/AutoCompleteField.tsx → inputs/AutoComplete/__stories__/Default.tsx} +1 -1
  59. package/src/inputs/DateInput/index.tsx +6 -3
  60. package/src/inputs/Input/__stories__/Integer.tsx +30 -18
  61. package/src/inputs/OtpInput/OtpInput.stories.js +7 -0
  62. package/src/inputs/OtpInput/__stories__/Default.tsx +32 -0
  63. package/src/inputs/OtpInput/index.tsx +164 -0
  64. package/src/inputs/index.ts +1 -0
  65. package/src/registry.js +4 -0
  66. package/src/types.tsx +2 -0
  67. package/src/validators/index.ts +2 -0
  68. package/src/validators/utils/index.ts +1 -0
  69. package/src/validators/utils/otp.ts +28 -0
  70. package/types.d.ts +2 -1
  71. package/validators/index.js +3 -0
  72. package/validators/utils/index.d.ts +1 -0
  73. package/validators/utils/index.js +14 -0
  74. package/validators/utils/otp.d.ts +4 -0
  75. package/validators/utils/otp.js +37 -0
  76. package/Form.stories.playwright.json +0 -71
  77. package/__stories__/AutoCompleteField.d.ts +0 -1
  78. package/__stories__/IntField.d.ts +0 -1
  79. package/__stories__/IntField.js +0 -56
  80. package/es/Form.stories.playwright.json +0 -71
  81. package/es/__stories__/IntField.js +0 -41
  82. package/esm/Form.stories.playwright.json +0 -71
  83. package/esm/__stories__/IntField.js +0 -41
  84. package/src/Form.stories.playwright.json +0 -71
  85. package/src/__stories__/IntField.tsx +0 -38
package/src/registry.js CHANGED
@@ -21,6 +21,7 @@ import * as _digigov_form_inputs_FileInput from '@digigov/form/inputs/FileInput'
21
21
  import * as _digigov_form_inputs from '@digigov/form/inputs';
22
22
  import * as _digigov_form_inputs_Input from '@digigov/form/inputs/Input';
23
23
  import * as _digigov_form_inputs_Label from '@digigov/form/inputs/Label';
24
+ import * as _digigov_form_inputs_OtpInput from '@digigov/form/inputs/OtpInput';
24
25
  import * as _digigov_form_inputs_Radio from '@digigov/form/inputs/Radio';
25
26
  import * as _digigov_form_inputs_Select from '@digigov/form/inputs/Select';
26
27
  import * as _digigov_form_internal from '@digigov/form/internal';
@@ -52,6 +53,7 @@ import * as _digigov_form_validators_utils_iban from '@digigov/form/validators/u
52
53
  import * as _digigov_form_validators_utils from '@digigov/form/validators/utils';
53
54
  import * as _digigov_form_validators_utils_int from '@digigov/form/validators/utils/int';
54
55
  import * as _digigov_form_validators_utils_number from '@digigov/form/validators/utils/number';
56
+ import * as _digigov_form_validators_utils_otp from '@digigov/form/validators/utils/otp';
55
57
  import * as _digigov_form_validators_utils_phone from '@digigov/form/validators/utils/phone';
56
58
  import * as _digigov_form_validators_utils_postal_code from '@digigov/form/validators/utils/postal_code';
57
59
  import * as _digigov_form_validators_utils_uuid4 from '@digigov/form/validators/utils/uuid4'
@@ -96,6 +98,7 @@ export default {
96
98
  '@digigov/form/inputs': lazyImport(_digigov_form_inputs),
97
99
  '@digigov/form/inputs/Input': lazyImport(_digigov_form_inputs_Input),
98
100
  '@digigov/form/inputs/Label': lazyImport(_digigov_form_inputs_Label),
101
+ '@digigov/form/inputs/OtpInput': lazyImport(_digigov_form_inputs_OtpInput),
99
102
  '@digigov/form/inputs/Radio': lazyImport(_digigov_form_inputs_Radio),
100
103
  '@digigov/form/inputs/Select': lazyImport(_digigov_form_inputs_Select),
101
104
  '@digigov/form/internal': lazyImport(_digigov_form_internal),
@@ -127,6 +130,7 @@ export default {
127
130
  '@digigov/form/validators/utils': lazyImport(_digigov_form_validators_utils),
128
131
  '@digigov/form/validators/utils/int': lazyImport(_digigov_form_validators_utils_int),
129
132
  '@digigov/form/validators/utils/number': lazyImport(_digigov_form_validators_utils_number),
133
+ '@digigov/form/validators/utils/otp': lazyImport(_digigov_form_validators_utils_otp),
130
134
  '@digigov/form/validators/utils/phone': lazyImport(_digigov_form_validators_utils_phone),
131
135
  '@digigov/form/validators/utils/postal_code': lazyImport(_digigov_form_validators_utils_postal_code),
132
136
  '@digigov/form/validators/utils/uuid4': lazyImport(_digigov_form_validators_utils_uuid4)
package/src/types.tsx CHANGED
@@ -30,6 +30,7 @@ export interface FieldSpec {
30
30
  | 'choice:single'
31
31
  | 'mobile_phone'
32
32
  | 'date'
33
+ | 'otp'
33
34
  | 'afm'
34
35
  | 'iban'
35
36
  | 'file'
@@ -38,6 +39,7 @@ export interface FieldSpec {
38
39
  | 'array'
39
40
  | 'object';
40
41
  component?: any;
42
+ maxLength?: number;
41
43
  condition?: Record<string, FieldCondition>;
42
44
  controlled?: boolean;
43
45
  label?: FieldLabelProps;
@@ -9,6 +9,7 @@ import {
9
9
  AFM_VALIDATOR,
10
10
  FILE_MAX_SIZE_VALIDATOR,
11
11
  IBAN_VALIDATOR,
12
+ OTP_VALIDATOR,
12
13
  MOBILE_PHONE_VALIDATOR,
13
14
  PHONE_NUMBER_VALIDATOR,
14
15
  POSTALCODE_VALIDATOR,
@@ -105,6 +106,7 @@ export const getYUPTypeMap = (): Record<string, any> => {
105
106
  afm: (): yup.StringSchema => yup.string().test(AFM_VALIDATOR),
106
107
  uuid4: (): yup.StringSchema => yup.string().test(UUID4_VALIDATOR),
107
108
  iban: (field): yup.StringSchema => yup.string().test(IBAN_VALIDATOR(field)),
109
+ otp: (field): yup.StringSchema => yup.string().test(OTP_VALIDATOR(field)),
108
110
  postal_code: (field): yup.StringSchema =>
109
111
  yup.string().test(POSTALCODE_VALIDATOR(field)),
110
112
  mobile_phone: (): yup.StringSchema =>
@@ -5,6 +5,7 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
5
5
  export * from '@digigov/form/validators/utils/afm';
6
6
  export * from '@digigov/form/validators/utils/file';
7
7
  export * from '@digigov/form/validators/utils/iban';
8
+ export * from '@digigov/form/validators/utils/otp';
8
9
  export * from '@digigov/form/validators/utils/phone';
9
10
  export * from '@digigov/form/validators/utils/postal_code';
10
11
  export * from '@digigov/form/validators/utils/uuid4';
@@ -0,0 +1,28 @@
1
+ import { FieldSpec } from '@digigov/form/types';
2
+ import { ValidatorSchema } from '@digigov/form/validators/types';
3
+ export function validateOtp(value: string, maxLength: number): boolean {
4
+ if (value.length === maxLength) {
5
+ return true;
6
+ } else {
7
+ return false;
8
+ }
9
+ }
10
+
11
+ export const OTP_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
12
+ const maxLength = field?.maxLength;
13
+ return {
14
+ name: 'otp-validator',
15
+ message: {
16
+ key: 'form.error.otp.less_than',
17
+ context: {
18
+ maxLength: field?.maxLength,
19
+ },
20
+ },
21
+ test: (value: string): boolean => {
22
+ if (!value) {
23
+ return true;
24
+ }
25
+ return validateOtp(value, maxLength as number);
26
+ },
27
+ };
28
+ };
package/types.d.ts CHANGED
@@ -17,8 +17,9 @@ export interface FieldCondition {
17
17
  }
18
18
  export interface FieldSpec {
19
19
  key: string;
20
- type?: 'int' | 'string' | 'text' | 'boolean' | 'email' | 'uuid4' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'date' | 'afm' | 'iban' | 'file' | 'postal_code' | 'phone_number' | 'array' | 'object';
20
+ type?: 'int' | 'string' | 'text' | 'boolean' | 'email' | 'uuid4' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'date' | 'otp' | 'afm' | 'iban' | 'file' | 'postal_code' | 'phone_number' | 'array' | 'object';
21
21
  component?: any;
22
+ maxLength?: number;
22
23
  condition?: Record<string, FieldCondition>;
23
24
  controlled?: boolean;
24
25
  label?: FieldLabelProps;
@@ -104,6 +104,9 @@ var getYUPTypeMap = function getYUPTypeMap() {
104
104
  iban: function iban(field) {
105
105
  return yup.string().test((0, _utils.IBAN_VALIDATOR)(field));
106
106
  },
107
+ otp: function otp(field) {
108
+ return yup.string().test((0, _utils.OTP_VALIDATOR)(field));
109
+ },
107
110
  postal_code: function postal_code(field) {
108
111
  return yup.string().test((0, _utils.POSTALCODE_VALIDATOR)(field));
109
112
  },
@@ -4,6 +4,7 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
4
4
  export * from '@digigov/form/validators/utils/afm';
5
5
  export * from '@digigov/form/validators/utils/file';
6
6
  export * from '@digigov/form/validators/utils/iban';
7
+ export * from '@digigov/form/validators/utils/otp';
7
8
  export * from '@digigov/form/validators/utils/phone';
8
9
  export * from '@digigov/form/validators/utils/postal_code';
9
10
  export * from '@digigov/form/validators/utils/uuid4';
@@ -58,6 +58,20 @@ Object.keys(_iban).forEach(function (key) {
58
58
  });
59
59
  });
60
60
 
61
+ var _otp = require("@digigov/form/validators/utils/otp");
62
+
63
+ Object.keys(_otp).forEach(function (key) {
64
+ if (key === "default" || key === "__esModule") return;
65
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
66
+ if (key in exports && exports[key] === _otp[key]) return;
67
+ Object.defineProperty(exports, key, {
68
+ enumerable: true,
69
+ get: function get() {
70
+ return _otp[key];
71
+ }
72
+ });
73
+ });
74
+
61
75
  var _phone = require("@digigov/form/validators/utils/phone");
62
76
 
63
77
  Object.keys(_phone).forEach(function (key) {
@@ -0,0 +1,4 @@
1
+ import { FieldSpec } from '@digigov/form/types';
2
+ import { ValidatorSchema } from '@digigov/form/validators/types';
3
+ export declare function validateOtp(value: string, maxLength: number): boolean;
4
+ export declare const OTP_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OTP_VALIDATOR = void 0;
7
+ exports.validateOtp = validateOtp;
8
+
9
+ function validateOtp(value, maxLength) {
10
+ if (value.length === maxLength) {
11
+ return true;
12
+ } else {
13
+ return false;
14
+ }
15
+ }
16
+
17
+ var OTP_VALIDATOR = function OTP_VALIDATOR(field) {
18
+ var maxLength = field === null || field === void 0 ? void 0 : field.maxLength;
19
+ return {
20
+ name: 'otp-validator',
21
+ message: {
22
+ key: 'form.error.otp.less_than',
23
+ context: {
24
+ maxLength: field === null || field === void 0 ? void 0 : field.maxLength
25
+ }
26
+ },
27
+ test: function test(value) {
28
+ if (!value) {
29
+ return true;
30
+ }
31
+
32
+ return validateOtp(value, maxLength);
33
+ }
34
+ };
35
+ };
36
+
37
+ exports.OTP_VALIDATOR = OTP_VALIDATOR;
@@ -1,71 +0,0 @@
1
- {
2
- "version": "4",
3
- "stories": {
4
- "digigov-form--int-field": {
5
- "actionSets": [
6
- {
7
- "actions": [
8
- {
9
- "name": "click",
10
- "args": {
11
- "selector": "html>body>div:nth-child(5)>form>button"
12
- }
13
- },
14
- {
15
- "name": "type",
16
- "args": {
17
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
18
- "text": "2.2"
19
- }
20
- },
21
- {
22
- "name": "click",
23
- "args": {
24
- "selector": "html>body>div:nth-child(5)>form>button"
25
- }
26
- }
27
- ],
28
- "id": "7wMj7iTumGC-",
29
- "title": "Show validation errors"
30
- },
31
- {
32
- "actions": [
33
- {
34
- "name": "keyboard.press",
35
- "args": {
36
- "key": "Tab"
37
- }
38
- },
39
- {
40
- "name": "keyboard.press",
41
- "args": {
42
- "key": "Tab"
43
- }
44
- }
45
- ],
46
- "id": "e7W6ZshKZmsE",
47
- "title": "Focus with keyboard"
48
- },
49
- {
50
- "actions": [
51
- {
52
- "name": "type",
53
- "args": {
54
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
55
- "text": "1"
56
- }
57
- },
58
- {
59
- "name": "click",
60
- "args": {
61
- "selector": "html>body>div:nth-child(5)>form>button"
62
- }
63
- }
64
- ],
65
- "id": "DBqARxwPma5a",
66
- "title": "Add number"
67
- }
68
- ]
69
- }
70
- }
71
- }
@@ -1 +0,0 @@
1
- export declare const AutoCompleteField: () => JSX.Element;
@@ -1 +0,0 @@
1
- export declare const IntField: () => JSX.Element;
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.IntField = void 0;
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _FormBuilder = _interopRequireDefault(require("@digigov/form/FormBuilder"));
13
-
14
- var _Field = require("@digigov/form/Field");
15
-
16
- var _Button = _interopRequireDefault(require("@digigov/ui/core/Button"));
17
-
18
- var fields = [{
19
- key: 'number_required',
20
- label: {
21
- primary: 'A positive number',
22
- secondary: 'required'
23
- },
24
- required: true,
25
- type: 'int'
26
- }, {
27
- key: 'number_not_required',
28
- label: {
29
- primary: 'A positive number',
30
- secondary: 'not required'
31
- },
32
- required: false,
33
- type: 'int'
34
- }];
35
- var initialValues = {};
36
-
37
- var _ref = /*#__PURE__*/_react["default"].createElement(_Button["default"], {
38
- type: "submit"
39
- }, "Submit");
40
-
41
- var IntField = function IntField() {
42
- return /*#__PURE__*/_react["default"].createElement(_FormBuilder["default"], {
43
- fields: fields,
44
- onSubmit: function onSubmit(data) {
45
- console.log(data);
46
- },
47
- initial: initialValues
48
- }, fields.map(function (field) {
49
- return /*#__PURE__*/_react["default"].createElement(_Field.Field, {
50
- key: field.key,
51
- name: field.key
52
- });
53
- }), _ref);
54
- };
55
-
56
- exports.IntField = IntField;
@@ -1,71 +0,0 @@
1
- {
2
- "version": "4",
3
- "stories": {
4
- "digigov-form--int-field": {
5
- "actionSets": [
6
- {
7
- "actions": [
8
- {
9
- "name": "click",
10
- "args": {
11
- "selector": "html>body>div:nth-child(5)>form>button"
12
- }
13
- },
14
- {
15
- "name": "type",
16
- "args": {
17
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
18
- "text": "2.2"
19
- }
20
- },
21
- {
22
- "name": "click",
23
- "args": {
24
- "selector": "html>body>div:nth-child(5)>form>button"
25
- }
26
- }
27
- ],
28
- "id": "7wMj7iTumGC-",
29
- "title": "Show validation errors"
30
- },
31
- {
32
- "actions": [
33
- {
34
- "name": "keyboard.press",
35
- "args": {
36
- "key": "Tab"
37
- }
38
- },
39
- {
40
- "name": "keyboard.press",
41
- "args": {
42
- "key": "Tab"
43
- }
44
- }
45
- ],
46
- "id": "e7W6ZshKZmsE",
47
- "title": "Focus with keyboard"
48
- },
49
- {
50
- "actions": [
51
- {
52
- "name": "type",
53
- "args": {
54
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
55
- "text": "1"
56
- }
57
- },
58
- {
59
- "name": "click",
60
- "args": {
61
- "selector": "html>body>div:nth-child(5)>form>button"
62
- }
63
- }
64
- ],
65
- "id": "DBqARxwPma5a",
66
- "title": "Add number"
67
- }
68
- ]
69
- }
70
- }
71
- }
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import FormBuilder from '@digigov/form/FormBuilder';
3
- import { Field } from '@digigov/form/Field';
4
- import Button from '@digigov/ui/core/Button';
5
- var fields = [{
6
- key: 'number_required',
7
- label: {
8
- primary: 'A positive number',
9
- secondary: 'required'
10
- },
11
- required: true,
12
- type: 'int'
13
- }, {
14
- key: 'number_not_required',
15
- label: {
16
- primary: 'A positive number',
17
- secondary: 'not required'
18
- },
19
- required: false,
20
- type: 'int'
21
- }];
22
- var initialValues = {};
23
-
24
- var _ref = /*#__PURE__*/React.createElement(Button, {
25
- type: "submit"
26
- }, "Submit");
27
-
28
- export var IntField = function IntField() {
29
- return /*#__PURE__*/React.createElement(FormBuilder, {
30
- fields: fields,
31
- onSubmit: function onSubmit(data) {
32
- console.log(data);
33
- },
34
- initial: initialValues
35
- }, fields.map(function (field) {
36
- return /*#__PURE__*/React.createElement(Field, {
37
- key: field.key,
38
- name: field.key
39
- });
40
- }), _ref);
41
- };
@@ -1,71 +0,0 @@
1
- {
2
- "version": "4",
3
- "stories": {
4
- "digigov-form--int-field": {
5
- "actionSets": [
6
- {
7
- "actions": [
8
- {
9
- "name": "click",
10
- "args": {
11
- "selector": "html>body>div:nth-child(5)>form>button"
12
- }
13
- },
14
- {
15
- "name": "type",
16
- "args": {
17
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
18
- "text": "2.2"
19
- }
20
- },
21
- {
22
- "name": "click",
23
- "args": {
24
- "selector": "html>body>div:nth-child(5)>form>button"
25
- }
26
- }
27
- ],
28
- "id": "7wMj7iTumGC-",
29
- "title": "Show validation errors"
30
- },
31
- {
32
- "actions": [
33
- {
34
- "name": "keyboard.press",
35
- "args": {
36
- "key": "Tab"
37
- }
38
- },
39
- {
40
- "name": "keyboard.press",
41
- "args": {
42
- "key": "Tab"
43
- }
44
- }
45
- ],
46
- "id": "e7W6ZshKZmsE",
47
- "title": "Focus with keyboard"
48
- },
49
- {
50
- "actions": [
51
- {
52
- "name": "type",
53
- "args": {
54
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
55
- "text": "1"
56
- }
57
- },
58
- {
59
- "name": "click",
60
- "args": {
61
- "selector": "html>body>div:nth-child(5)>form>button"
62
- }
63
- }
64
- ],
65
- "id": "DBqARxwPma5a",
66
- "title": "Add number"
67
- }
68
- ]
69
- }
70
- }
71
- }
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import FormBuilder from '@digigov/form/FormBuilder';
3
- import { Field } from '@digigov/form/Field';
4
- import Button from '@digigov/ui/core/Button';
5
- var fields = [{
6
- key: 'number_required',
7
- label: {
8
- primary: 'A positive number',
9
- secondary: 'required'
10
- },
11
- required: true,
12
- type: 'int'
13
- }, {
14
- key: 'number_not_required',
15
- label: {
16
- primary: 'A positive number',
17
- secondary: 'not required'
18
- },
19
- required: false,
20
- type: 'int'
21
- }];
22
- var initialValues = {};
23
-
24
- var _ref = /*#__PURE__*/React.createElement(Button, {
25
- type: "submit"
26
- }, "Submit");
27
-
28
- export var IntField = function IntField() {
29
- return /*#__PURE__*/React.createElement(FormBuilder, {
30
- fields: fields,
31
- onSubmit: function onSubmit(data) {
32
- console.log(data);
33
- },
34
- initial: initialValues
35
- }, fields.map(function (field) {
36
- return /*#__PURE__*/React.createElement(Field, {
37
- key: field.key,
38
- name: field.key
39
- });
40
- }), _ref);
41
- };
@@ -1,71 +0,0 @@
1
- {
2
- "version": "4",
3
- "stories": {
4
- "digigov-form--int-field": {
5
- "actionSets": [
6
- {
7
- "actions": [
8
- {
9
- "name": "click",
10
- "args": {
11
- "selector": "html>body>div:nth-child(5)>form>button"
12
- }
13
- },
14
- {
15
- "name": "type",
16
- "args": {
17
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
18
- "text": "2.2"
19
- }
20
- },
21
- {
22
- "name": "click",
23
- "args": {
24
- "selector": "html>body>div:nth-child(5)>form>button"
25
- }
26
- }
27
- ],
28
- "id": "7wMj7iTumGC-",
29
- "title": "Show validation errors"
30
- },
31
- {
32
- "actions": [
33
- {
34
- "name": "keyboard.press",
35
- "args": {
36
- "key": "Tab"
37
- }
38
- },
39
- {
40
- "name": "keyboard.press",
41
- "args": {
42
- "key": "Tab"
43
- }
44
- }
45
- ],
46
- "id": "e7W6ZshKZmsE",
47
- "title": "Focus with keyboard"
48
- },
49
- {
50
- "actions": [
51
- {
52
- "name": "type",
53
- "args": {
54
- "selector": "html>body>div:nth-child(5)>form>div:nth-child(1)>label>input",
55
- "text": "1"
56
- }
57
- },
58
- {
59
- "name": "click",
60
- "args": {
61
- "selector": "html>body>div:nth-child(5)>form>button"
62
- }
63
- }
64
- ],
65
- "id": "DBqARxwPma5a",
66
- "title": "Add number"
67
- }
68
- ]
69
- }
70
- }
71
- }
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
- import FormBuilder from '@digigov/form/FormBuilder';
3
- import { Field } from '@digigov/form/Field';
4
- import { FieldSpec } from '@digigov/form/types';
5
- import Button from '@digigov/ui/core/Button';
6
- const fields: FieldSpec[] = [
7
- {
8
- key: 'number_required',
9
- label: { primary: 'A positive number', secondary: 'required' },
10
- required: true,
11
- type: 'int',
12
- },
13
- {
14
- key: 'number_not_required',
15
- label: { primary: 'A positive number', secondary: 'not required' },
16
- required: false,
17
- type: 'int',
18
- },
19
- ];
20
-
21
- const initialValues = {};
22
-
23
- export const IntField = () => {
24
- return (
25
- <FormBuilder
26
- fields={fields}
27
- onSubmit={(data) => {
28
- console.log(data);
29
- }}
30
- initial={initialValues}
31
- >
32
- {fields.map((field) => (
33
- <Field key={field.key} name={field.key} />
34
- ))}
35
- <Button type="submit">Submit</Button>
36
- </FormBuilder>
37
- );
38
- };