@digigov/form 1.2.0-dcbd7ded → 2.0.0-462194bf

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 (73) hide show
  1. package/Field/FieldBase/index.js +1 -0
  2. package/Field/utils/index.js +5 -5
  3. package/MultiplicityField/__stories__/PreviewDisplay/index.js +8 -2
  4. package/cjs/Field/FieldBase/index.js +1 -0
  5. package/cjs/Field/utils/index.js +5 -10
  6. package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +8 -2
  7. package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +12 -0
  8. package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +11 -16
  9. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +52 -0
  10. package/cjs/inputs/AutoCompleteInput/index.js +20 -6
  11. package/cjs/inputs/AutoCompleteInput/index.mdx +29 -0
  12. package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +3 -2
  13. package/cjs/inputs/Checkboxes/index.mdx +33 -0
  14. package/cjs/inputs/DateInput/index.mdx +23 -0
  15. package/cjs/inputs/FileInput/index.mdx +19 -0
  16. package/cjs/inputs/ImageInput/index.mdx +19 -0
  17. package/cjs/inputs/Input/index.mdx +90 -3
  18. package/cjs/inputs/OtpInput/index.js +1 -0
  19. package/cjs/inputs/OtpInput/index.mdx +23 -0
  20. package/cjs/inputs/Radio/__stories__/Conditional/index.js +3 -2
  21. package/cjs/inputs/Radio/index.mdx +33 -0
  22. package/cjs/inputs/Select/index.mdx +17 -0
  23. package/cjs/validators/utils/file/index.js +11 -19
  24. package/index.js +1 -1
  25. package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +2 -1
  26. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +1 -0
  27. package/inputs/AutoCompleteInput/__stories__/Default/index.js +9 -11
  28. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -0
  29. package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +45 -0
  30. package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +6 -0
  31. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +3 -0
  32. package/inputs/AutoCompleteInput/index.d.ts +1 -1
  33. package/inputs/AutoCompleteInput/index.js +20 -6
  34. package/inputs/AutoCompleteInput/index.mdx +29 -0
  35. package/inputs/Checkboxes/__stories__/Conditional/index.js +2 -1
  36. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -0
  37. package/inputs/Checkboxes/index.mdx +33 -0
  38. package/inputs/DateInput/index.mdx +23 -0
  39. package/inputs/FileInput/index.mdx +19 -0
  40. package/inputs/ImageInput/index.mdx +19 -0
  41. package/inputs/Input/index.mdx +90 -3
  42. package/inputs/OtpInput/index.d.ts +8 -1
  43. package/inputs/OtpInput/index.js +1 -1
  44. package/inputs/OtpInput/index.mdx +23 -0
  45. package/inputs/Radio/__stories__/Conditional/index.js +2 -1
  46. package/inputs/Radio/__stories__/Conditional.d.ts +1 -0
  47. package/inputs/Radio/index.mdx +33 -0
  48. package/inputs/Select/index.mdx +17 -0
  49. package/lazy.d.ts +1 -1
  50. package/package.json +4 -4
  51. package/src/Field/FieldBase.tsx +1 -0
  52. package/src/Field/utils.ts +4 -4
  53. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +2 -2
  54. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +1 -0
  55. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +27 -18
  56. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +54 -0
  57. package/src/inputs/AutoCompleteInput/index.mdx +29 -0
  58. package/src/inputs/AutoCompleteInput/index.tsx +24 -14
  59. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +2 -3
  60. package/src/inputs/Checkboxes/index.mdx +33 -0
  61. package/src/inputs/Checkboxes/index.tsx +2 -2
  62. package/src/inputs/DateInput/index.mdx +23 -0
  63. package/src/inputs/DateInput/index.tsx +1 -1
  64. package/src/inputs/FileInput/index.mdx +19 -0
  65. package/src/inputs/ImageInput/index.mdx +19 -0
  66. package/src/inputs/Input/index.mdx +90 -3
  67. package/src/inputs/OtpInput/index.mdx +23 -0
  68. package/src/inputs/OtpInput/index.tsx +2 -2
  69. package/src/inputs/Radio/__stories__/Conditional.tsx +2 -0
  70. package/src/inputs/Radio/index.mdx +33 -0
  71. package/src/inputs/Select/index.mdx +17 -0
  72. package/src/validators/utils/file.ts +9 -9
  73. package/validators/utils/file/index.js +11 -19
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: Radio
3
+ ---
4
+
5
+ # Radio
6
+ Input element of type `radio` are generally used in radio groups—collections of radio buttons describing a set of related options.
7
+ Radios are used to let a user select one option of a limited number of choices.
8
+
9
+ ## How to use
10
+
11
+ ### Default
12
+
13
+ <Story
14
+ packageName="@digigov/form"
15
+ component="inputs/Radio"
16
+ story="Default.tsx"
17
+ />
18
+
19
+ ### Conditional
20
+
21
+ <Story
22
+ packageName="@digigov/form"
23
+ component="inputs/Radio"
24
+ story="Conditional.tsx"
25
+ />
26
+
27
+ ### With divider
28
+
29
+ <Story
30
+ packageName="@digigov/form"
31
+ component="inputs/Radio"
32
+ story="WithDivider.tsx"
33
+ />
@@ -0,0 +1,17 @@
1
+ ---
2
+ title: Select
3
+ ---
4
+
5
+ # Select
6
+
7
+ The select element represents a control that provides a menu of options.
8
+
9
+ ## How to use
10
+
11
+ ### Default
12
+
13
+ <Story
14
+ packageName="@digigov/form"
15
+ component="inputs/Select"
16
+ story="Default.tsx"
17
+ />
@@ -5,17 +5,17 @@ const DEFAULT_FILE_MAX_SIZE = 10000000;
5
5
 
6
6
  export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({
7
7
  name: 'file-max-size-validator',
8
- message: 'form.error.file_size',
8
+ message: {
9
+ key: 'form.error.file_size',
10
+ context: {
11
+ maxSizeToMb: (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,
12
+ },
13
+ },
9
14
  test: (value: File[]): boolean => {
10
- if (field?.extra?.limit && field?.extra?.limit.maxSize && value) {
11
- for (const file of value) {
12
- if (file.size >= field.extra.limit.maxSize) {
13
- return false;
14
- }
15
- }
16
- } else if (value) {
15
+ if (value) {
17
16
  for (const file of value) {
18
- if (file.size >= DEFAULT_FILE_MAX_SIZE) {
17
+ const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE
18
+ if (file.size > maxSize) {
19
19
  return false;
20
20
  }
21
21
  }
@@ -3,18 +3,25 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
3
3
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
4
  var DEFAULT_FILE_MAX_SIZE = 10000000;
5
5
  export var FILE_MAX_SIZE_VALIDATOR = function FILE_MAX_SIZE_VALIDATOR(field) {
6
+ var _field$extra;
6
7
  return {
7
8
  name: 'file-max-size-validator',
8
- message: 'form.error.file_size',
9
+ message: {
10
+ key: 'form.error.file_size',
11
+ context: {
12
+ maxSizeToMb: ((field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.limit.maxSize) || DEFAULT_FILE_MAX_SIZE) / 1000000
13
+ }
14
+ },
9
15
  test: function test(value) {
10
- var _field$extra, _field$extra2;
11
- if (field !== null && field !== void 0 && (_field$extra = field.extra) !== null && _field$extra !== void 0 && _field$extra.limit && field !== null && field !== void 0 && (_field$extra2 = field.extra) !== null && _field$extra2 !== void 0 && _field$extra2.limit.maxSize && value) {
16
+ if (value) {
12
17
  var _iterator = _createForOfIteratorHelper(value),
13
18
  _step;
14
19
  try {
15
20
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
21
+ var _field$extra2, _field$extra2$limit;
16
22
  var file = _step.value;
17
- if (file.size >= field.extra.limit.maxSize) {
23
+ var maxSize = (field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : (_field$extra2$limit = _field$extra2.limit) === null || _field$extra2$limit === void 0 ? void 0 : _field$extra2$limit.maxSize) || DEFAULT_FILE_MAX_SIZE;
24
+ if (file.size > maxSize) {
18
25
  return false;
19
26
  }
20
27
  }
@@ -23,21 +30,6 @@ export var FILE_MAX_SIZE_VALIDATOR = function FILE_MAX_SIZE_VALIDATOR(field) {
23
30
  } finally {
24
31
  _iterator.f();
25
32
  }
26
- } else if (value) {
27
- var _iterator2 = _createForOfIteratorHelper(value),
28
- _step2;
29
- try {
30
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
31
- var _file = _step2.value;
32
- if (_file.size >= DEFAULT_FILE_MAX_SIZE) {
33
- return false;
34
- }
35
- }
36
- } catch (err) {
37
- _iterator2.e(err);
38
- } finally {
39
- _iterator2.f();
40
- }
41
33
  }
42
34
  return true;
43
35
  }