@digigov/form 0.8.4 → 0.8.5-alpha

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 (159) hide show
  1. package/Field/utils.js +1 -0
  2. package/FieldArray/FieldArray.stories.playwright.json +168 -0
  3. package/FieldArray/__stories__/Default.js +3 -5
  4. package/FieldArray/__stories__/WithExactLength.js +3 -5
  5. package/FieldArray/index.js +1 -0
  6. package/FieldObject/index.js +1 -2
  7. package/{FormBuilder.d.ts → FormBuilder/FormBuilder.d.ts} +0 -0
  8. package/{FormBuilder.js → FormBuilder/FormBuilder.js} +0 -0
  9. package/FormBuilder/FormBuilder.mdx +271 -0
  10. package/FormBuilder/FormBuilder.stories.d.ts +7 -0
  11. package/FormBuilder/FormBuilder.stories.js +30 -0
  12. package/FormBuilder/__stories__/Default.d.ts +2 -0
  13. package/FormBuilder/__stories__/Default.js +45 -0
  14. package/FormBuilder/index.d.ts +2 -0
  15. package/FormBuilder/index.js +11 -0
  16. package/MultiplicityField/MultiplicityField.mdx +148 -0
  17. package/MultiplicityField/__stories__/Default.js +3 -5
  18. package/MultiplicityField/__stories__/WithExactLength.js +3 -5
  19. package/MultiplicityField/__stories__/WithMaxLength.js +3 -5
  20. package/MultiplicityField/__stories__/WithMinAndMaxLength.js +3 -5
  21. package/MultiplicityField/__stories__/WithMinLength.js +3 -5
  22. package/Questions/Step/StepArrayReview.js +2 -2
  23. package/Questions/__snapshots__/index.spec.tsx.snap +649 -449
  24. package/Questions/index.mdx +0 -187
  25. package/create-simple-form.mdx +515 -0
  26. package/es/Field/utils.js +1 -0
  27. package/es/FieldArray/FieldArray.stories.playwright.json +168 -0
  28. package/es/FieldArray/__stories__/Default.js +3 -5
  29. package/es/FieldArray/__stories__/WithExactLength.js +3 -5
  30. package/es/FieldArray/index.js +1 -0
  31. package/es/FieldObject/index.js +1 -2
  32. package/es/{FormBuilder.js → FormBuilder/FormBuilder.js} +0 -0
  33. package/es/FormBuilder/FormBuilder.mdx +271 -0
  34. package/es/FormBuilder/FormBuilder.stories.js +6 -0
  35. package/es/FormBuilder/__stories__/Default.js +25 -0
  36. package/es/FormBuilder/index.js +2 -0
  37. package/es/MultiplicityField/MultiplicityField.mdx +148 -0
  38. package/es/MultiplicityField/__stories__/Default.js +3 -5
  39. package/es/MultiplicityField/__stories__/WithExactLength.js +3 -5
  40. package/es/MultiplicityField/__stories__/WithMaxLength.js +3 -5
  41. package/es/MultiplicityField/__stories__/WithMinAndMaxLength.js +3 -5
  42. package/es/MultiplicityField/__stories__/WithMinLength.js +3 -5
  43. package/es/Questions/Step/StepArrayReview.js +1 -1
  44. package/es/Questions/__snapshots__/index.spec.tsx.snap +649 -449
  45. package/es/Questions/index.mdx +0 -187
  46. package/es/create-simple-form.mdx +515 -0
  47. package/es/index.mdx +37 -199
  48. package/es/inputs/Checkboxes/Checkboxes.stories.js +6 -0
  49. package/es/inputs/Checkboxes/__stories__/Default.js +43 -0
  50. package/es/inputs/DateInput/DateInput.stories.js +6 -0
  51. package/es/inputs/DateInput/__stories__/Default.js +44 -0
  52. package/es/inputs/Input/Input.stories.js +13 -0
  53. package/es/inputs/Input/__stories__/AFM.js +25 -0
  54. package/es/inputs/Input/__stories__/Boolean.js +26 -0
  55. package/es/inputs/Input/__stories__/Default.js +26 -0
  56. package/es/inputs/Input/__stories__/IBAN.js +26 -0
  57. package/es/inputs/Input/__stories__/Integer.js +26 -0
  58. package/es/inputs/Input/__stories__/MobilePhone.js +25 -0
  59. package/es/inputs/Input/__stories__/PhoneNumber.js +25 -0
  60. package/es/inputs/Input/__stories__/PostalCode.js +28 -0
  61. package/es/inputs/Input/index.mdx +0 -2
  62. package/es/inputs/Label/Label.stories.js +6 -0
  63. package/es/inputs/Label/__stories__/Default.js +30 -0
  64. package/es/inputs/Radio/Radio.stories.js +6 -0
  65. package/es/inputs/Radio/__stories__/Default.js +48 -0
  66. package/es/inputs/Select/Select.stories.js +6 -0
  67. package/es/inputs/Select/__stories__/Default.js +54 -0
  68. package/es/installation.mdx +72 -0
  69. package/es/registry.js +129 -0
  70. package/esm/Field/utils.js +1 -0
  71. package/esm/FieldArray/FieldArray.stories.playwright.json +168 -0
  72. package/esm/FieldArray/__stories__/Default.js +3 -5
  73. package/esm/FieldArray/__stories__/WithExactLength.js +3 -5
  74. package/esm/FieldArray/index.js +1 -0
  75. package/esm/FieldObject/index.js +1 -2
  76. package/esm/{FormBuilder.js → FormBuilder/FormBuilder.js} +0 -0
  77. package/esm/FormBuilder/FormBuilder.mdx +271 -0
  78. package/esm/FormBuilder/FormBuilder.stories.js +6 -0
  79. package/esm/FormBuilder/__stories__/Default.js +25 -0
  80. package/esm/FormBuilder/index.js +2 -0
  81. package/esm/MultiplicityField/MultiplicityField.mdx +148 -0
  82. package/esm/MultiplicityField/__stories__/Default.js +3 -5
  83. package/esm/MultiplicityField/__stories__/WithExactLength.js +3 -5
  84. package/esm/MultiplicityField/__stories__/WithMaxLength.js +3 -5
  85. package/esm/MultiplicityField/__stories__/WithMinAndMaxLength.js +3 -5
  86. package/esm/MultiplicityField/__stories__/WithMinLength.js +3 -5
  87. package/esm/Questions/Step/StepArrayReview.js +1 -1
  88. package/esm/Questions/__snapshots__/index.spec.tsx.snap +649 -449
  89. package/esm/Questions/index.mdx +0 -187
  90. package/esm/create-simple-form.mdx +515 -0
  91. package/esm/index.js +1 -1
  92. package/esm/index.mdx +37 -199
  93. package/esm/inputs/Checkboxes/Checkboxes.stories.js +6 -0
  94. package/esm/inputs/Checkboxes/__stories__/Default.js +43 -0
  95. package/esm/inputs/DateInput/DateInput.stories.js +6 -0
  96. package/esm/inputs/DateInput/__stories__/Default.js +44 -0
  97. package/esm/inputs/Input/Input.stories.js +13 -0
  98. package/esm/inputs/Input/__stories__/AFM.js +25 -0
  99. package/esm/inputs/Input/__stories__/Boolean.js +26 -0
  100. package/esm/inputs/Input/__stories__/Default.js +26 -0
  101. package/esm/inputs/Input/__stories__/IBAN.js +26 -0
  102. package/esm/inputs/Input/__stories__/Integer.js +26 -0
  103. package/esm/inputs/Input/__stories__/MobilePhone.js +25 -0
  104. package/esm/inputs/Input/__stories__/PhoneNumber.js +25 -0
  105. package/esm/inputs/Input/__stories__/PostalCode.js +28 -0
  106. package/esm/inputs/Input/index.mdx +0 -2
  107. package/esm/inputs/Label/Label.stories.js +6 -0
  108. package/esm/inputs/Label/__stories__/Default.js +30 -0
  109. package/esm/inputs/Radio/Radio.stories.js +6 -0
  110. package/esm/inputs/Radio/__stories__/Default.js +48 -0
  111. package/esm/inputs/Select/Select.stories.js +6 -0
  112. package/esm/inputs/Select/__stories__/Default.js +54 -0
  113. package/esm/installation.mdx +72 -0
  114. package/esm/registry.js +129 -0
  115. package/index.mdx +37 -199
  116. package/inputs/Checkboxes/Checkboxes.stories.d.ts +7 -0
  117. package/inputs/Checkboxes/Checkboxes.stories.js +30 -0
  118. package/inputs/Checkboxes/__stories__/Default.d.ts +2 -0
  119. package/inputs/Checkboxes/__stories__/Default.js +63 -0
  120. package/inputs/DateInput/DateInput.stories.d.ts +7 -0
  121. package/inputs/DateInput/DateInput.stories.js +30 -0
  122. package/inputs/DateInput/__stories__/Default.d.ts +2 -0
  123. package/inputs/DateInput/__stories__/Default.js +64 -0
  124. package/inputs/Input/Input.stories.d.ts +14 -0
  125. package/inputs/Input/Input.stories.js +128 -0
  126. package/inputs/Input/__stories__/AFM.d.ts +2 -0
  127. package/inputs/Input/__stories__/AFM.js +45 -0
  128. package/inputs/Input/__stories__/Boolean.d.ts +2 -0
  129. package/inputs/Input/__stories__/Boolean.js +46 -0
  130. package/inputs/Input/__stories__/Default.d.ts +2 -0
  131. package/inputs/Input/__stories__/Default.js +46 -0
  132. package/inputs/Input/__stories__/IBAN.d.ts +2 -0
  133. package/inputs/Input/__stories__/IBAN.js +46 -0
  134. package/inputs/Input/__stories__/Integer.d.ts +2 -0
  135. package/inputs/Input/__stories__/Integer.js +46 -0
  136. package/inputs/Input/__stories__/MobilePhone.d.ts +2 -0
  137. package/inputs/Input/__stories__/MobilePhone.js +45 -0
  138. package/inputs/Input/__stories__/PhoneNumber.d.ts +2 -0
  139. package/inputs/Input/__stories__/PhoneNumber.js +45 -0
  140. package/inputs/Input/__stories__/PostalCode.d.ts +2 -0
  141. package/inputs/Input/__stories__/PostalCode.js +48 -0
  142. package/inputs/Input/index.mdx +0 -2
  143. package/inputs/Label/Label.stories.d.ts +7 -0
  144. package/inputs/Label/Label.stories.js +30 -0
  145. package/inputs/Label/__stories__/Default.d.ts +2 -0
  146. package/inputs/Label/__stories__/Default.js +50 -0
  147. package/inputs/Radio/Radio.stories.d.ts +7 -0
  148. package/inputs/Radio/Radio.stories.js +30 -0
  149. package/inputs/Radio/__stories__/Default.d.ts +2 -0
  150. package/inputs/Radio/__stories__/Default.js +68 -0
  151. package/inputs/Select/Select.stories.d.ts +7 -0
  152. package/inputs/Select/Select.stories.js +30 -0
  153. package/inputs/Select/__stories__/Default.d.ts +2 -0
  154. package/inputs/Select/__stories__/Default.js +74 -0
  155. package/installation.mdx +72 -0
  156. package/package.json +6 -6
  157. package/registry.d.ts +59 -0
  158. package/registry.js +198 -0
  159. package/types.d.ts +1 -1
@@ -0,0 +1,148 @@
1
+ ---
2
+ id: MultiplicityField
3
+ title: Multiplicity Field
4
+ sidebar_label: Recursively ask user data
5
+ ---
6
+
7
+ import LeadText from "@site/src/components/LeadText";
8
+
9
+ <LeadText>Multiplicity field enables users add instances of a particular schema for an
10
+ arbitrary amount of times until they are done. It can be used with a fixed
11
+ length of instances, or a minimum and maximum length.</LeadText>
12
+
13
+ ## What we are trying to achieve
14
+
15
+ This field was developed as an accessible and guided way to fill arrays with
16
+ objects described by a schema. For example, we can define the schema for a usual form by describing the fields
17
+ it will render.
18
+
19
+ These fields may describe an entity and its properties and it can be reused
20
+ multiple times to generate data objects following this schema.
21
+
22
+ ```js
23
+ const fields = [
24
+ {
25
+ key: "fullname",
26
+ name: "fullname",
27
+ type: "string",
28
+ required: true
29
+ },
30
+ {
31
+ key: "afm",
32
+ name: "afm",
33
+ type: "afm",
34
+ required: true
35
+ },
36
+ ];
37
+ ```
38
+
39
+ We aim to have semantically correct and valid forms. What this means is that we
40
+ cannot mix form-related HTML elements (eg. form, input, label) with generic ones
41
+ (eg. div, cards, custom components). React will start throwing warnings left and
42
+ right if we try to add a paragraph element inside a form.
43
+
44
+ Apart from this, Digigov Form recommends using forms in their original way of
45
+ filling and validating inputs, then submitting the form as a whole. The process
46
+ repeats if validation fails or proceeds if validation is successful. In any
47
+ case, it is imperative to provide meaningful information to the users on
48
+ how they proceed to fix the validation errors.
49
+
50
+ Last but not least, we should make our interfaces entirely accessible to screen
51
+ readers and other accessibilty tools and this requirement adds another dimension
52
+ to this problem. Forms and fields should read like a well-written piece of text
53
+ and make sense to the users. Thus we should avoid the use of magic UX solutions
54
+ that require users to have some well-developed digital skills and most of the
55
+ time are used for expert users.
56
+
57
+ Users should fill in data as this schema dictates, and every time they add
58
+ something we should ask them if they want to continue adding or escape the loop.
59
+ We can also add some limitations so we can ask for an array with specific
60
+ cardinality. In this way we can validate each form state regardless of whether a
61
+ user is in the process of data input or reviewing what they've added. In any
62
+ case, the form should guide users through steps and validation errors, and avoid
63
+ giving too much freedom in actions that could lead to estranged users losing
64
+ their way out of the maze.
65
+
66
+ But how can we code this feature as part of a Digigov form?
67
+
68
+ ## Enter the Multiplicity field
69
+
70
+ To deal with this problem, we have decided to create a composite field that uses
71
+ externally defined object schema alongside some internal helpers. This field in
72
+ fact is considered as a single key-value pair by the form. The only difference is that
73
+ the value will be of type `Array` instead of any other primitive used for a
74
+ field type.
75
+
76
+ The component internally uses the
77
+ [useFieldArray](https://www.react-hook-form.com/api/usefieldarray) hook from
78
+ react-hook-form.
79
+
80
+ ```jsx live
81
+ import React from 'react';
82
+ import Form, { Field } from '@digigov/form';
83
+
84
+ export default function SimpleForm() {
85
+ return <Form>
86
+ <Field
87
+ key="children"
88
+ label={{ primary: "Children" }}
89
+ type="array"
90
+ multiplicity={true}
91
+ extra={{
92
+
93
+ label: {
94
+ object: {
95
+ title: 'Συνυπογράφοντας',
96
+ title_added: 'Οι συνυπογράφοντες που έχετε προσθέσει',
97
+ add: 'Προσθήκη',
98
+ delete: 'Αφαίρεση συνυπογράφοντος',
99
+ },
100
+ question: {
101
+ title: 'Do you want to add any additional children?',
102
+ objectLabel: {
103
+ primary: 'Προσθήκη νέου συνυπογράφοντα',
104
+ secondary: 'Συμπληρώστε τα στοιχεία και μετά πατήστε «Προσθήκη»',
105
+ },
106
+ yes: 'Yes',
107
+ no: 'No',
108
+ },
109
+ },
110
+ of: {
111
+ type: 'object',
112
+ label: {
113
+ primary: 'Στοιχεία συνυπογράφοντα',
114
+ secondary: 'Δείτε και αλλάξτε τα στοιχεία του συνυπογράφοντα',
115
+ },
116
+ extra: {
117
+ fields: [
118
+ {
119
+ key: 'afm',
120
+ type: 'afm',
121
+ required: true,
122
+ label: { primary: 'ΑΦΜ' },
123
+ },
124
+ {
125
+ key: 'firstName',
126
+ required: true,
127
+ type: 'string',
128
+ label: {
129
+ primary: 'Όνομα',
130
+ },
131
+ },
132
+ {
133
+ key: 'lastName',
134
+ required: true,
135
+ type: 'string',
136
+ label: {
137
+ primary: 'Επώνυμο',
138
+ },
139
+ },
140
+ ],
141
+ },
142
+ },
143
+ }}
144
+ required
145
+ />
146
+ </Form>
147
+ }
148
+ ```
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import FormBuilder, { Field } from '@digigov/form';
4
4
  import { Button } from '@digigov/ui/core';
5
5
  var fields = [{
@@ -83,9 +83,7 @@ var _ref = /*#__PURE__*/React.createElement(Button, {
83
83
  }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
84
84
 
85
85
  export var Default = function Default() {
86
- return /*#__PURE__*/React.createElement(Suspense, {
87
- fallback: "loading"
88
- }, /*#__PURE__*/React.createElement(FormBuilder, {
86
+ return /*#__PURE__*/React.createElement(FormBuilder, {
89
87
  onSubmit: function onSubmit(data) {
90
88
  debugger;
91
89
  console.log(data);
@@ -96,5 +94,5 @@ export var Default = function Default() {
96
94
  name: "multiplicity"
97
95
  }, fields[1])), /*#__PURE__*/React.createElement(Field, _extends({
98
96
  name: "phonenumber"
99
- }, fields[2])), _ref));
97
+ }, fields[2])), _ref);
100
98
  };
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import FormBuilder, { Field } from '@digigov/form';
4
4
  import { Button } from '@digigov/ui/core';
5
5
  var fields = [{
@@ -78,9 +78,7 @@ var _ref = /*#__PURE__*/React.createElement(Button, {
78
78
  }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
79
79
 
80
80
  export var WithExactLength = function WithExactLength() {
81
- return /*#__PURE__*/React.createElement(Suspense, {
82
- fallback: "loading"
83
- }, /*#__PURE__*/React.createElement(FormBuilder, {
81
+ return /*#__PURE__*/React.createElement(FormBuilder, {
84
82
  onSubmit: function onSubmit(data) {
85
83
  debugger;
86
84
  console.log(data);
@@ -91,5 +89,5 @@ export var WithExactLength = function WithExactLength() {
91
89
  name: "multiplicity"
92
90
  }, fields[1])), /*#__PURE__*/React.createElement(Field, _extends({
93
91
  name: "phonenumber"
94
- }, fields[2])), _ref));
92
+ }, fields[2])), _ref);
95
93
  };
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import FormBuilder, { Field } from '@digigov/form';
4
4
  import { Button } from '@digigov/ui/core';
5
5
  var fields = [{
@@ -81,9 +81,7 @@ var _ref = /*#__PURE__*/React.createElement(Button, {
81
81
  }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
82
82
 
83
83
  export var WithMaxLength = function WithMaxLength() {
84
- return /*#__PURE__*/React.createElement(Suspense, {
85
- fallback: "loading"
86
- }, /*#__PURE__*/React.createElement(FormBuilder, {
84
+ return /*#__PURE__*/React.createElement(FormBuilder, {
87
85
  onSubmit: function onSubmit(data) {
88
86
  debugger;
89
87
  console.log(data);
@@ -94,5 +92,5 @@ export var WithMaxLength = function WithMaxLength() {
94
92
  name: "multiplicity"
95
93
  }, fields[1])), /*#__PURE__*/React.createElement(Field, _extends({
96
94
  name: "phonenumber"
97
- }, fields[2])), _ref));
95
+ }, fields[2])), _ref);
98
96
  };
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import FormBuilder, { Field } from '@digigov/form';
4
4
  import { Button } from '@digigov/ui/core';
5
5
  var fields = [{
@@ -82,9 +82,7 @@ var _ref = /*#__PURE__*/React.createElement(Button, {
82
82
  }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
83
83
 
84
84
  export var WithMinAndMaxLength = function WithMinAndMaxLength() {
85
- return /*#__PURE__*/React.createElement(Suspense, {
86
- fallback: "loading"
87
- }, /*#__PURE__*/React.createElement(FormBuilder, {
85
+ return /*#__PURE__*/React.createElement(FormBuilder, {
88
86
  onSubmit: function onSubmit(data) {
89
87
  debugger;
90
88
  console.log(data);
@@ -95,5 +93,5 @@ export var WithMinAndMaxLength = function WithMinAndMaxLength() {
95
93
  name: "multiplicity"
96
94
  }, fields[1])), /*#__PURE__*/React.createElement(Field, _extends({
97
95
  name: "phonenumber"
98
- }, fields[2])), _ref));
96
+ }, fields[2])), _ref);
99
97
  };
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import FormBuilder, { Field } from '@digigov/form';
4
4
  import { Button } from '@digigov/ui/core';
5
5
  var fields = [{
@@ -81,9 +81,7 @@ var _ref = /*#__PURE__*/React.createElement(Button, {
81
81
  }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
82
82
 
83
83
  export var WithMinLength = function WithMinLength() {
84
- return /*#__PURE__*/React.createElement(Suspense, {
85
- fallback: "loading"
86
- }, /*#__PURE__*/React.createElement(FormBuilder, {
84
+ return /*#__PURE__*/React.createElement(FormBuilder, {
87
85
  onSubmit: function onSubmit(data) {
88
86
  debugger;
89
87
  console.log(data);
@@ -94,5 +92,5 @@ export var WithMinLength = function WithMinLength() {
94
92
  name: "multiplicity"
95
93
  }, fields[1])), /*#__PURE__*/React.createElement(Field, _extends({
96
94
  name: "phonenumber"
97
- }, fields[2])), _ref));
95
+ }, fields[2])), _ref);
98
96
  };
@@ -2,7 +2,7 @@ import React, { useContext } from 'react';
2
2
  import { QuestionsContext } from '@digigov/form/Questions/QuestionsContext';
3
3
  import PageTitle, { PageTitleHeading } from '@digigov/ui/app/PageTitle';
4
4
  import Button from '@digigov/ui/core/Button';
5
- import { FormBuilder } from '@digigov/form/FormBuilder';
5
+ import FormBuilder from '@digigov/form/FormBuilder';
6
6
  import { Field } from '@digigov/form/Field';
7
7
  import { Fieldset } from '@digigov/form/Fieldset';
8
8
  import Label from '@digigov/form/inputs/Label';