@unicef-polymer/etools-form-builder 1.0.3 → 2.1.0-rc.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 (56) hide show
  1. package/dist/form-attachments-popup/form-attachments-popup.d.ts +10 -2
  2. package/dist/form-attachments-popup/form-attachments-popup.js +53 -48
  3. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
  4. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +79 -85
  5. package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
  6. package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +133 -112
  7. package/dist/form-fields/custom-elements.define.js +17 -5
  8. package/dist/form-fields/field-renderer-component.d.ts +20 -0
  9. package/dist/form-fields/field-renderer-component.js +245 -0
  10. package/dist/form-fields/index.d.ts +9 -5
  11. package/dist/form-fields/index.js +9 -5
  12. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
  13. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +198 -0
  14. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
  15. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
  16. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
  17. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +56 -0
  18. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
  19. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +104 -0
  20. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
  21. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +43 -0
  22. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
  23. package/dist/form-fields/single-fields/attachment-field.js +87 -0
  24. package/dist/form-fields/single-fields/base-field.d.ts +11 -0
  25. package/dist/form-fields/single-fields/base-field.js +57 -0
  26. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
  27. package/dist/form-fields/single-fields/boolean-field.js +39 -0
  28. package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
  29. package/dist/form-fields/{number-field.js → single-fields/number-field.js} +34 -21
  30. package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
  31. package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +66 -54
  32. package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
  33. package/dist/form-fields/{text-field.js → single-fields/text-field.js} +26 -21
  34. package/dist/form-fields/wide-field.d.ts +1 -1
  35. package/dist/form-fields/wide-field.js +3 -3
  36. package/dist/form-groups/form-abstract-group.d.ts +12 -12
  37. package/dist/form-groups/form-abstract-group.js +189 -166
  38. package/dist/form-groups/form-card.d.ts +1 -0
  39. package/dist/form-groups/form-card.js +35 -10
  40. package/dist/form-groups/form-collapsed-card.d.ts +3 -1
  41. package/dist/form-groups/form-collapsed-card.js +45 -25
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +6 -1
  44. package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
  45. package/dist/lib/additional-components/confirmation-dialog.js +61 -0
  46. package/dist/lib/additional-components/etools-fb-card.js +135 -128
  47. package/dist/lib/styles/attachments.styles.js +69 -66
  48. package/dist/lib/styles/form-builder-card.styles.js +46 -41
  49. package/dist/lib/styles/input-styles.js +53 -64
  50. package/dist/lib/styles/page-layout-styles.js +198 -198
  51. package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
  52. package/dist/lib/types/form-builder.types.d.ts +8 -2
  53. package/dist/lib/utils/validations.helper.d.ts +3 -3
  54. package/dist/lib/utils/validations.helper.js +7 -7
  55. package/package.json +53 -52
  56. package/dist/form-fields/base-field.d.ts +0 -20
@@ -2,35 +2,30 @@ import { html } from 'lit-element';
2
2
  // language=HTML
3
3
  export const InputStyles = html `
4
4
  <style>
5
- etools-dropdown.form-control,
6
- etools-dropdown-multi.form-control,
7
- paper-input.form-control,
8
- paper-textarea.form-control,
9
- paper-dropdown-menu.form-control,
10
- etools-currency-amount-input.form-control,
11
- datepicker-lite.form-control {
5
+ etools-dropdown,
6
+ etools-dropdown-multi,
7
+ paper-input,
8
+ paper-textarea,
9
+ paper-dropdown-menu,
10
+ etools-currency-amount-input,
11
+ datepicker-lite {
12
12
  outline: none !important;
13
13
  padding: 0 12px;
14
- color: var(--gray-mid, rgba(0, 0, 0, 0.54));
14
+ color: var(--gray-dark, rgba(0, 0, 0, 0.87));
15
15
  box-sizing: border-box;
16
- --esmm-placeholder-color: var(--gray-20, rgba(0, 0, 0, 0.2));
17
- --esmm-multi-placeholder-color: var(--gray-20, rgba(0, 0, 0, 0.2));
18
- --paper-input-container-color: rgba(0, 0, 0, 0.2);
16
+
17
+ --paper-input-container-input-color: var(--gray-dark, rgba(0, 0, 0, 0.87));
18
+ --esmm-placeholder-color: var(--gray-dark, rgba(0, 0, 0, 0.87));
19
+ --esmm-multi-placeholder-color: var(--gray-dark, rgba(0, 0, 0, 0.87));
20
+
19
21
  --paper-input-container-focus-color: var(--primary-color, #0099ff);
20
- --paper-input-container-input: {
21
- font-size: 16px;
22
- color: var(--gray-dark, rgba(0, 0, 0, 0.87));
23
- }
22
+
24
23
  --paper-input-container-label: {
25
24
  color: var(--gray-50, rgba(0, 0, 0, 0.5));
26
25
  }
27
26
 
28
27
  --paper-input-container-invalid-color: var(--module-error, #ea4022);
29
28
 
30
- --paper-input-container-disabled: {
31
- color: var(--gray-light, rgba(0, 0, 0, 0.38));
32
- opacity: 1;
33
- }
34
29
  --paper-input-char-counter: {
35
30
  color: var(--gray-light, rgba(0, 0, 0, 0.38));
36
31
  }
@@ -56,9 +51,6 @@ export const InputStyles = html `
56
51
  width: 100%;
57
52
  font-size: 12px;
58
53
  }
59
- --paper-input-container-underline: {
60
- border-color: rgba(0, 0, 0, 0.2) !important;
61
- }
62
54
 
63
55
  --paper-input-container-shared-input-style: {
64
56
  font-size: 16px;
@@ -74,44 +66,44 @@ export const InputStyles = html `
74
66
  overflow: hidden;
75
67
  }
76
68
 
77
- --iron-autogrow-textarea-placeholder: {
78
- color: var(--gray-20, rgba(0, 0, 0, 0.2)) !important;
79
- }
80
69
  --iron-autogrow-textarea: {
81
70
  padding: 0;
82
71
  }
83
72
  }
84
73
 
85
- paper-input-container.form-control,
86
- etools-dropdown-multi[disabled].disabled-as-readonly.form-control,
87
- etools-dropdown[disabled].disabled-as-readonly.form-control,
88
- paper-textarea[disabled].disabled-as-readonly.form-control,
89
- paper-dropdown-menu[disabled].disabled-as-readonly.form-control,
90
- paper-input[disabled].disabled-as-readonly.form-control,
91
- datepicker-lite[disabled].disabled-as-readonly.form-control {
74
+ etools-dropdown-multi[disabled],
75
+ etools-dropdown[disabled],
76
+ paper-textarea[disabled],
77
+ paper-dropdown-menu[disabled],
78
+ paper-input[disabled],
79
+ datepicker-lite[disabled] {
80
+ --paper-input-container-focus-color: var(
81
+ --paper-input-container-label_-_color,
82
+ var(--paper-input-container-color, var(--secondary-text-color))
83
+ );
92
84
  --paper-input-container: {
93
85
  opacity: 1 !important;
94
86
  }
95
87
  --paper-input-container-underline: {
96
- border-bottom: none !important;
97
- display: none !important;
88
+ border-bottom: 1px dashed var(--gray-20, rgba(0, 0, 0, 0.2));
89
+ display: block !important;
98
90
  }
99
91
  --paper-input-container-underline-focus: {
100
92
  display: none;
101
93
  }
102
- --paper-input-container-color: rgba(0, 0, 0, 0.2) !important;
94
+ --esmm-select-cursor: initial;
103
95
  }
104
96
 
105
- etools-dropdown-multi[disabled].without-border.form-control,
106
- etools-dropdown[disabled].without-border.form-control,
107
- paper-textarea[disabled].without-border.form-control,
108
- paper-input[disabled].without-border.form-control,
109
- datepicker-lite[disabled].without-border.form-control {
110
- --paper-input-container-label: {
111
- color: var(--gray-50, rgba(0, 0, 0, 0.5)) !important;
112
- }
113
- --esmm-placeholder-color: rgba(0, 0, 0, 0.16) !important;
114
- --esmm-multi-placeholder-color: rgba(0, 0, 0, 0.16) !important;
97
+ etools-dropdown-multi[readonly],
98
+ etools-dropdown[readonly],
99
+ paper-textarea[readonly],
100
+ paper-dropdown-menu[readonly],
101
+ paper-input[readonly],
102
+ datepicker-lite[readonly] {
103
+ --paper-input-container-focus-color: var(
104
+ --paper-input-container-label_-_color,
105
+ var(--paper-input-container-color, var(--secondary-text-color))
106
+ );
115
107
  --paper-input-container: {
116
108
  opacity: 1 !important;
117
109
  }
@@ -125,27 +117,24 @@ export const InputStyles = html `
125
117
  --paper-input-container-underline-disabled: {
126
118
  display: none;
127
119
  }
128
- --iron-autogrow-textarea-placeholder: {
129
- color: var(--gray-mid-dark, rgba(0, 0, 0, 0.7)) !important;
130
- }
131
- --paper-input-container-color: var(--gray-mid-dark, rgba(0, 0, 0, 0.7));
120
+ --esmm-select-cursor: initial;
132
121
  }
133
122
 
134
- etools-dropdown-multi.required:not([disabled]).form-control,
135
- etools-dropdown-multi[required]:not([disabled]).form-control,
136
- etools-dropdown-multi[required].readonly-required.form-control,
137
- etools-dropdown.required:not([disabled]).form-control,
138
- etools-dropdown[required]:not([disabled]).form-control,
139
- etools-dropdown[required].readonly-required.form-control,
140
- paper-dropdown-menu.required:not([disabled]).form-control,
141
- paper-dropdown-menu[required]:not([disabled]).form-control,
142
- paper-dropdown-menu[required].readonly-required.form-control,
143
- paper-textarea.required:not([disabled]).form-control,
144
- paper-textarea[required]:not([disabled]).form-control,
145
- paper-textarea[required].readonly-required.form-control,
146
- paper-input.required:not([disabled]).form-control,
147
- paper-input[required].readonly-required.form-control,
148
- paper-input[required]:not([disabled]).form-control {
123
+ etools-dropdown-multi.required:not([disabled]),
124
+ etools-dropdown-multi[required]:not([disabled]),
125
+ etools-dropdown-multi[required].readonly-required,
126
+ etools-dropdown.required:not([disabled]),
127
+ etools-dropdown[required]:not([disabled]),
128
+ etools-dropdown[required].readonly-required,
129
+ paper-dropdown-menu.required:not([disabled]),
130
+ paper-dropdown-menu[required]:not([disabled]),
131
+ paper-dropdown-menu[required].readonly-required,
132
+ paper-textarea.required:not([disabled]),
133
+ paper-textarea[required]:not([disabled]),
134
+ paper-textarea[required].readonly-required,
135
+ paper-input.required:not([disabled]),
136
+ paper-input[required].readonly-required,
137
+ paper-input[required]:not([disabled]) {
149
138
  --paper-input-container-label: {
150
139
  background: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221235%22%20height%3D%221175%22%3E%3Cpath%20fill%3D%22%23de0000%22%20d%3D%22M0%2C449h1235l-999%2C726%20382-1175%20382%2C1175z%22%2F%3E%3C%2Fsvg%3E')
151
140
  no-repeat 98% 14%/7px;
@@ -1,201 +1,201 @@
1
1
  import { css } from 'lit-element';
2
2
  // language=CSS
3
- export const pageLayoutStyles = css `
4
- .page-content {
5
- margin: 24px;
6
- }
7
-
8
- .page-content.filters {
9
- padding: 8px 24px;
10
- }
11
-
12
- .pr-25 {
13
- padding-right: 25px !important;
14
- }
15
- .pr-45 {
16
- padding-right: 45px !important;
17
- }
18
-
19
- .f1 {
20
- flex: 1;
21
- }
22
- .f2 {
23
- flex: 2;
24
- }
25
- .f3 {
26
- flex: 3;
27
- }
28
- .f4 {
29
- flex: 4;
30
- }
31
- .f5 {
32
- flex: 5;
33
- }
34
- .f6 {
35
- flex: 6;
36
- }
37
- .f7 {
38
- flex: 7;
39
- }
40
- .f8 {
41
- flex: 8;
42
- }
43
-
44
- .w4 {
45
- width: 4%;
46
- }
47
- .w5 {
48
- width: 5%;
49
- }
50
- .w7 {
51
- width: 7%;
52
- }
53
- .w8 {
54
- width: 8%;
55
- }
56
- .w9 {
57
- width: 9%;
58
- }
59
- .w10 {
60
- width: 10%;
61
- }
62
- .w13 {
63
- width: 13%;
64
- }
65
- .w14 {
66
- width: 14%;
67
- }
68
- .w15 {
69
- width: 15%;
70
- }
71
- .w16 {
72
- width: 16%;
73
- }
74
- .w17 {
75
- width: 17%;
76
- }
77
- .w18 {
78
- width: 18%;
79
- }
80
- .w20 {
81
- width: 20%;
82
- }
83
- .w25 {
84
- width: 25%;
85
- }
86
- .w30 {
87
- width: 30%;
88
- }
89
- .w35 {
90
- width: 35%;
91
- }
92
- .w45 {
93
- width: 45%;
94
- }
95
- .w40 {
96
- width: 40%;
97
- }
98
- .w50 {
99
- width: 50%;
100
- }
101
- .w60 {
102
- width: 60%;
103
- }
104
- .w65 {
105
- width: 65%;
106
- }
107
- .w70 {
108
- width: 70%;
109
- }
110
- .w75 {
111
- width: 75%;
112
- }
113
- .w80 {
114
- width: 80%;
115
- }
116
- .w90 {
117
- width: 90%;
118
- }
119
- .w95 {
120
- width: 95%;
121
- }
122
- .w96 {
123
- width: 96%;
124
- }
125
- .w100 {
126
- width: 100%;
127
- }
128
-
129
- .w30px {
130
- width: 30px;
131
- }
132
- .w35px {
133
- width: 35px;
134
- }
135
- .w40px {
136
- width: 40px;
137
- }
138
- .w45px {
139
- width: 45px;
140
- }
141
- .w50px {
142
- width: 50px;
143
- }
144
- .w60px {
145
- width: 60px;
146
- }
147
- .w65px {
148
- width: 65px;
149
- }
150
- .w80px {
151
- width: 80px;
152
- }
153
- .w90px {
154
- width: 90px;
155
- }
156
- .w100px {
157
- width: 100px;
158
- }
159
- .w110px {
160
- width: 110px;
161
- }
162
- .w120px {
163
- width: 120px;
164
- }
165
- .w130px {
166
- width: 130px;
167
- }
168
- .w140px {
169
- width: 140px;
170
- }
171
- .w150px {
172
- width: 150px;
173
- }
174
- .w160px {
175
- width: 160px;
176
- }
177
- .w180px {
178
- width: 180px;
179
- }
180
- .w200px {
181
- width: 200px;
182
- }
183
- .w210px {
184
- width: 210px;
185
- }
186
- .w300px {
187
- width: 300px;
188
- }
189
- .w310px {
190
- width: 310px;
191
- }
192
- .w330px {
193
- width: 330px;
194
- }
195
-
196
- @media (max-width: 768px) {
197
- .page-content {
198
- margin: 8px;
199
- }
200
- }
3
+ export const pageLayoutStyles = css `
4
+ .page-content {
5
+ margin: 24px 24px 0;
6
+ }
7
+
8
+ .page-content.filters {
9
+ padding: 8px 24px;
10
+ }
11
+
12
+ .pr-25 {
13
+ padding-right: 25px !important;
14
+ }
15
+ .pr-45 {
16
+ padding-right: 45px !important;
17
+ }
18
+
19
+ .f1 {
20
+ flex: 1;
21
+ }
22
+ .f2 {
23
+ flex: 2;
24
+ }
25
+ .f3 {
26
+ flex: 3;
27
+ }
28
+ .f4 {
29
+ flex: 4;
30
+ }
31
+ .f5 {
32
+ flex: 5;
33
+ }
34
+ .f6 {
35
+ flex: 6;
36
+ }
37
+ .f7 {
38
+ flex: 7;
39
+ }
40
+ .f8 {
41
+ flex: 8;
42
+ }
43
+
44
+ .w4 {
45
+ width: 4%;
46
+ }
47
+ .w5 {
48
+ width: 5%;
49
+ }
50
+ .w7 {
51
+ width: 7%;
52
+ }
53
+ .w8 {
54
+ width: 8%;
55
+ }
56
+ .w9 {
57
+ width: 9%;
58
+ }
59
+ .w10 {
60
+ width: 10%;
61
+ }
62
+ .w13 {
63
+ width: 13%;
64
+ }
65
+ .w14 {
66
+ width: 14%;
67
+ }
68
+ .w15 {
69
+ width: 15%;
70
+ }
71
+ .w16 {
72
+ width: 16%;
73
+ }
74
+ .w17 {
75
+ width: 17%;
76
+ }
77
+ .w18 {
78
+ width: 18%;
79
+ }
80
+ .w20 {
81
+ width: 20%;
82
+ }
83
+ .w25 {
84
+ width: 25%;
85
+ }
86
+ .w30 {
87
+ width: 30%;
88
+ }
89
+ .w35 {
90
+ width: 35%;
91
+ }
92
+ .w45 {
93
+ width: 45%;
94
+ }
95
+ .w40 {
96
+ width: 40%;
97
+ }
98
+ .w50 {
99
+ width: 50%;
100
+ }
101
+ .w60 {
102
+ width: 60%;
103
+ }
104
+ .w65 {
105
+ width: 65%;
106
+ }
107
+ .w70 {
108
+ width: 70%;
109
+ }
110
+ .w75 {
111
+ width: 75%;
112
+ }
113
+ .w80 {
114
+ width: 80%;
115
+ }
116
+ .w90 {
117
+ width: 90%;
118
+ }
119
+ .w95 {
120
+ width: 95%;
121
+ }
122
+ .w96 {
123
+ width: 96%;
124
+ }
125
+ .w100 {
126
+ width: 100%;
127
+ }
128
+
129
+ .w30px {
130
+ width: 30px;
131
+ }
132
+ .w35px {
133
+ width: 35px;
134
+ }
135
+ .w40px {
136
+ width: 40px;
137
+ }
138
+ .w45px {
139
+ width: 45px;
140
+ }
141
+ .w50px {
142
+ width: 50px;
143
+ }
144
+ .w60px {
145
+ width: 60px;
146
+ }
147
+ .w65px {
148
+ width: 65px;
149
+ }
150
+ .w80px {
151
+ width: 80px;
152
+ }
153
+ .w90px {
154
+ width: 90px;
155
+ }
156
+ .w100px {
157
+ width: 100px;
158
+ }
159
+ .w110px {
160
+ width: 110px;
161
+ }
162
+ .w120px {
163
+ width: 120px;
164
+ }
165
+ .w130px {
166
+ width: 130px;
167
+ }
168
+ .w140px {
169
+ width: 140px;
170
+ }
171
+ .w150px {
172
+ width: 150px;
173
+ }
174
+ .w160px {
175
+ width: 160px;
176
+ }
177
+ .w180px {
178
+ width: 180px;
179
+ }
180
+ .w200px {
181
+ width: 200px;
182
+ }
183
+ .w210px {
184
+ width: 210px;
185
+ }
186
+ .w300px {
187
+ width: 300px;
188
+ }
189
+ .w310px {
190
+ width: 310px;
191
+ }
192
+ .w330px {
193
+ width: 330px;
194
+ }
195
+
196
+ @media (max-width: 768px) {
197
+ .page-content {
198
+ margin: 8px;
199
+ }
200
+ }
201
201
  `;
@@ -42,7 +42,7 @@ export interface IFormBuilderAbstractGroup {
42
42
  * Use it to update current group value:
43
43
  * @value-changed="${(event) => this.valueChanged(event, BlueprintGroup.name)}"
44
44
  */
45
- renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult;
45
+ renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
46
46
  }
47
47
  export interface IFormBuilderCard extends IFormBuilderAbstractGroup {
48
48
  /**
@@ -73,7 +73,7 @@ export interface IFormBuilderCollapsedCard extends IFormBuilderAbstractGroup, IF
73
73
  * else { super.renderGroup(groupStructure); }
74
74
  *
75
75
  */
76
- renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult;
76
+ renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
77
77
  /**
78
78
  * Use openDialog method. Call valueChanged() on popup resolve with confirmed === true
79
79
  */
@@ -19,7 +19,7 @@ export declare type BlueprintGroup = {
19
19
  repeatable: boolean;
20
20
  required: boolean;
21
21
  title: string | null;
22
- children: (BlueprintGroup | BlueprintField)[];
22
+ children: (BlueprintGroup | BlueprintField | Information)[];
23
23
  };
24
24
  export declare type BlueprintField = {
25
25
  type: 'field';
@@ -28,7 +28,7 @@ export declare type BlueprintField = {
28
28
  name: string;
29
29
  repeatable: boolean;
30
30
  required: boolean;
31
- input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float';
31
+ input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float' | 'file';
32
32
  label: string;
33
33
  validations: string[];
34
34
  help_text: string;
@@ -36,6 +36,12 @@ export declare type BlueprintField = {
36
36
  default_value: null;
37
37
  options_key: null;
38
38
  };
39
+ export declare type Information = {
40
+ type: 'information';
41
+ extra: GenericObject;
42
+ styling: string[];
43
+ text: string;
44
+ };
39
45
  /** Metadata for blueprint structure */
40
46
  export declare type BlueprintMetadata = {
41
47
  options: GenericObject<BlueprintMetadataOptions>;
@@ -6,7 +6,7 @@ export declare enum Validations {
6
6
  }
7
7
  export declare type MaxLengthValidation = {
8
8
  name: Validations.MAX_LENGTH;
9
- [Validations.MAX_LENGTH]: string;
9
+ [Validations.MAX_LENGTH]: number;
10
10
  };
11
11
  export declare type RegexValidation = {
12
12
  name: Validations.REGEX;
@@ -14,12 +14,12 @@ export declare type RegexValidation = {
14
14
  };
15
15
  export declare type GreaterValidation = {
16
16
  name: Validations.GREATER_THAN;
17
- [Validations.GREATER_THAN]: string;
17
+ threshold: number;
18
18
  allow_equality: boolean;
19
19
  };
20
20
  export declare type LowerValidation = {
21
21
  name: Validations.LOWER_THAN;
22
- [Validations.LOWER_THAN]: string;
22
+ threshold: number;
23
23
  allow_equality: boolean;
24
24
  };
25
25
  export declare type FieldValidator = MaxLengthValidation | RegexValidation | GreaterValidation | LowerValidation;
@@ -18,17 +18,17 @@ export function validate(validators, value) {
18
18
  function checkValidation(validation, value) {
19
19
  switch (validation.name) {
20
20
  case Validations.MAX_LENGTH:
21
- const maxLength = Number(validation[Validations.MAX_LENGTH]);
21
+ const maxLength = Number(validation[Validations.MAX_LENGTH]) + 1;
22
22
  return String(value).length < maxLength ? null : `Text must be less than ${maxLength} character`;
23
23
  case Validations.REGEX:
24
- // TODO: Implements Regex validation
25
- return null;
24
+ const regex = new RegExp(`^${validation[Validations.REGEX]}$`);
25
+ return regex.test(String(value)) ? null : `Doesn't match allowed pattern`;
26
26
  case Validations.GREATER_THAN:
27
- const greaterThan = Number(validation[Validations.GREATER_THAN]) - Number(validation.allow_equality);
28
- return Number(value) > greaterThan ? null : `Number must be greater than ${greaterThan} character`;
27
+ const greaterThan = Number(validation.threshold) - Number(validation.allow_equality);
28
+ return Number(value) > greaterThan ? null : `Number must be greater than ${greaterThan}`;
29
29
  case Validations.LOWER_THAN:
30
- const lowerThan = Number(validation[Validations.LOWER_THAN]) + Number(validation.allow_equality);
31
- return Number(value) < lowerThan ? null : `Number must be lower than ${lowerThan} character`;
30
+ const lowerThan = Number(validation.threshold) + Number(validation.allow_equality);
31
+ return Number(value) < lowerThan ? null : `Number must be lower than ${lowerThan}`;
32
32
  default:
33
33
  return null;
34
34
  }