@digigov/form 1.2.0-a7ffb5dc → 2.0.0-0edebf87

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 (87) hide show
  1. package/Field/FieldBase/index.js +1 -0
  2. package/Field/utils/index.js +5 -5
  3. package/FieldObject/index.js +1 -1
  4. package/MultiplicityField/__stories__/PreviewDisplay/index.js +8 -2
  5. package/MultiplicityField/index.js +6 -1
  6. package/cjs/Field/FieldBase/index.js +1 -0
  7. package/cjs/Field/utils/index.js +5 -10
  8. package/cjs/FieldObject/index.js +2 -2
  9. package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +8 -2
  10. package/cjs/MultiplicityField/index.js +10 -5
  11. package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +12 -0
  12. package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +11 -16
  13. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +52 -0
  14. package/cjs/inputs/AutoCompleteInput/index.js +22 -8
  15. package/cjs/inputs/AutoCompleteInput/index.mdx +29 -0
  16. package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +3 -2
  17. package/cjs/inputs/Checkboxes/index.js +2 -2
  18. package/cjs/inputs/Checkboxes/index.mdx +33 -0
  19. package/cjs/inputs/DateInput/index.mdx +23 -0
  20. package/cjs/inputs/FileInput/index.mdx +19 -0
  21. package/cjs/inputs/ImageInput/index.mdx +19 -0
  22. package/cjs/inputs/Input/index.js +2 -2
  23. package/cjs/inputs/Input/index.mdx +90 -3
  24. package/cjs/inputs/OtpInput/index.js +1 -0
  25. package/cjs/inputs/OtpInput/index.mdx +23 -0
  26. package/cjs/inputs/Radio/__stories__/Conditional/index.js +3 -2
  27. package/cjs/inputs/Radio/index.js +2 -2
  28. package/cjs/inputs/Radio/index.mdx +33 -0
  29. package/cjs/inputs/Select/index.mdx +17 -0
  30. package/cjs/validators/utils/file/index.js +11 -19
  31. package/index.js +1 -1
  32. package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +2 -1
  33. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +1 -0
  34. package/inputs/AutoCompleteInput/__stories__/Default/index.js +9 -11
  35. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -0
  36. package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +45 -0
  37. package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +6 -0
  38. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +3 -0
  39. package/inputs/AutoCompleteInput/index.d.ts +1 -1
  40. package/inputs/AutoCompleteInput/index.js +21 -7
  41. package/inputs/AutoCompleteInput/index.mdx +29 -0
  42. package/inputs/Checkboxes/__stories__/Conditional/index.js +2 -1
  43. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -0
  44. package/inputs/Checkboxes/index.js +1 -1
  45. package/inputs/Checkboxes/index.mdx +33 -0
  46. package/inputs/DateInput/index.mdx +23 -0
  47. package/inputs/FileInput/index.mdx +19 -0
  48. package/inputs/ImageInput/index.mdx +19 -0
  49. package/inputs/Input/index.js +1 -1
  50. package/inputs/Input/index.mdx +90 -3
  51. package/inputs/OtpInput/index.d.ts +8 -1
  52. package/inputs/OtpInput/index.js +1 -1
  53. package/inputs/OtpInput/index.mdx +23 -0
  54. package/inputs/Radio/__stories__/Conditional/index.js +2 -1
  55. package/inputs/Radio/__stories__/Conditional.d.ts +1 -0
  56. package/inputs/Radio/index.js +1 -1
  57. package/inputs/Radio/index.mdx +33 -0
  58. package/inputs/Select/index.mdx +17 -0
  59. package/lazy.d.ts +1 -1
  60. package/package.json +4 -4
  61. package/src/Field/FieldBase.tsx +1 -0
  62. package/src/Field/utils.ts +4 -4
  63. package/src/FieldObject/index.tsx +1 -1
  64. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +2 -2
  65. package/src/MultiplicityField/index.tsx +7 -8
  66. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +1 -0
  67. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +27 -18
  68. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +54 -0
  69. package/src/inputs/AutoCompleteInput/index.mdx +29 -0
  70. package/src/inputs/AutoCompleteInput/index.tsx +25 -15
  71. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +2 -3
  72. package/src/inputs/Checkboxes/index.mdx +33 -0
  73. package/src/inputs/Checkboxes/index.tsx +3 -3
  74. package/src/inputs/DateInput/index.mdx +23 -0
  75. package/src/inputs/DateInput/index.tsx +1 -1
  76. package/src/inputs/FileInput/index.mdx +19 -0
  77. package/src/inputs/ImageInput/index.mdx +19 -0
  78. package/src/inputs/Input/index.mdx +90 -3
  79. package/src/inputs/Input/index.tsx +1 -1
  80. package/src/inputs/OtpInput/index.mdx +23 -0
  81. package/src/inputs/OtpInput/index.tsx +2 -2
  82. package/src/inputs/Radio/__stories__/Conditional.tsx +2 -0
  83. package/src/inputs/Radio/index.mdx +33 -0
  84. package/src/inputs/Radio/index.tsx +1 -1
  85. package/src/inputs/Select/index.mdx +17 -0
  86. package/src/validators/utils/file.ts +9 -9
  87. package/validators/utils/file/index.js +11 -19
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: Checkbox
3
+ ---
4
+
5
+ # Checkboxes
6
+ Input element of type `checkbox` are rendered by default as boxes that are checked when activated.
7
+ Checkboxes are used to let a user select one or more options of a limited number of choices.
8
+
9
+ ## How to use
10
+
11
+ ### Default
12
+
13
+ <Story
14
+ packageName="@digigov/form"
15
+ component="inputs/Checkboxes"
16
+ story="Default.tsx"
17
+ />
18
+
19
+ ### Conditional
20
+
21
+ <Story
22
+ packageName="@digigov/form"
23
+ component="inputs/Checkboxes"
24
+ story="Conditional.tsx"
25
+ />
26
+
27
+ ### With divider
28
+
29
+ <Story
30
+ packageName="@digigov/form"
31
+ component="inputs/Checkboxes"
32
+ story="WithDivider.tsx"
33
+ />
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
2
2
  import { Field } from '@digigov/form';
3
3
  import { ControlledFieldProps } from '@digigov/form/Field/types';
4
4
  import { FieldOptionProps } from '@digigov/form/inputs/Label';
5
- import { CheckboxConditional } from '@digigov/react-core';
5
+ import { CheckboxConditional } from '@digigov/react-core/CheckboxConditional';
6
6
  import CoreCheckboxes from '@digigov/react-core/Checkbox';
7
7
  import CheckboxItem from '@digigov/react-core/CheckboxItem';
8
8
  import Hint from '@digigov/react-core/Hint';
@@ -17,14 +17,14 @@ export interface CheckboxesProps
17
17
  };
18
18
  }
19
19
 
20
- export const Checkboxes: React.FC<CheckboxesProps> = function Checkboxes({
20
+ export const Checkboxes: React.FC<CheckboxesProps> = ({
21
21
  name,
22
22
  onChange,
23
23
  value,
24
24
  extra: { options, className },
25
25
  disabled,
26
26
  ...props
27
- }) {
27
+ }) => {
28
28
  if (!value) value = [];
29
29
  const handleChange = (optionValue, idx, show) => (evt): void => {
30
30
  let newValue;
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: Date Input
3
+ ---
4
+
5
+ # Date input
6
+
7
+
8
+
9
+ Input element of type `date` create input fields that let the user enter a date,
10
+ either with a textbox that validates the input or a special date picker interface.
11
+
12
+ ## How to use
13
+
14
+ ### Default
15
+
16
+ <Story
17
+ packageName="@digigov/form"
18
+ component="inputs/DateInput"
19
+ story="Default.tsx"
20
+ />
21
+
22
+
23
+
@@ -78,7 +78,7 @@ const DatePart = ({ label, ...props }) => {
78
78
  return <CoreDateInputItem {...props}>{label}</CoreDateInputItem>;
79
79
  };
80
80
 
81
- export const DateInput = function DateInput({ name, type, ...props }) {
81
+ export const DateInput = ({ name, type, ...props }) => {
82
82
  const { t } = useTranslation();
83
83
  const [initial] = useState(props.value);
84
84
  const value = useMemo(() => {
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: File Input
3
+ ---
4
+
5
+ # File input
6
+
7
+
8
+
9
+ Input element of type `file` let the user choose one or more files from their device storage.
10
+
11
+ ## How to use
12
+
13
+ ### Default
14
+
15
+ <Story
16
+ packageName="@digigov/form"
17
+ component="inputs/FileInput"
18
+ story="Default.tsx"
19
+ />
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: Image Input
3
+ ---
4
+
5
+ # Image input
6
+
7
+
8
+
9
+ Input element of type `image` defines an image as a submit button, i.e. submit buttons that take the form of an image rather than text.
10
+
11
+ ## How to use
12
+
13
+ ### Default
14
+
15
+ <Story
16
+ packageName="@digigov/form"
17
+ component="inputs/ImageInput"
18
+ story="Default.tsx"
19
+ />
@@ -1,8 +1,95 @@
1
1
  ---
2
2
  title: Input
3
- parent: docs/ui/components
4
3
  ---
4
+
5
+ # Input
6
+
7
+
8
+
9
+ The input element of type `string` is used to create interactive controls for web-based forms in order to accept data from the user;
10
+ a wide variety of types of input data and control widgets are available, depending on the device and user agent. The input element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input types and attributes.
11
+
12
+ ## How to use
13
+
14
+ ### Default
15
+
16
+ <Story
17
+ packageName="@digigov/form"
18
+ component="inputs/Input"
19
+ story="Default.tsx"
20
+ />
21
+
22
+ ### Boolean
23
+
24
+ <Story
25
+ packageName="@digigov/form"
26
+ component="inputs/Input"
27
+ story="Boolean.tsx"
28
+ />
29
+ ### AFM
30
+
31
+ <Story
32
+ packageName="@digigov/form"
33
+ component="inputs/Input"
34
+ story="AFM.tsx"
35
+ />
36
+
37
+ ### IBAN
38
+
39
+ <Story
40
+ packageName="@digigov/form"
41
+ component="inputs/Input"
42
+ story="IBAN.tsx"
43
+ />
44
+
45
+ ### Integer
46
+
47
+ <Story
48
+ packageName="@digigov/form"
49
+ component="inputs/Input"
50
+ story="Default.tsx"
51
+ />
52
+
53
+ ### Landline number
54
+
55
+ <Story
56
+ packageName="@digigov/form"
57
+ component="inputs/Input"
58
+ story="LandlineNumber.tsx"
59
+ />
60
+
61
+ ### Mobile phone
62
+
63
+ <Story
64
+ packageName="@digigov/form"
65
+ component="inputs/Input"
66
+ story="MobilePhone.tsx"
67
+ />
68
+
69
+ ### Phone number
70
+
71
+ <Story
72
+ packageName="@digigov/form"
73
+ component="inputs/Input"
74
+ story="PhoneNumber.tsx"
75
+ />
76
+
77
+ ### Postal code
78
+
79
+ <Story
80
+ packageName="@digigov/form"
81
+ component="inputs/Input"
82
+ story="PostalCode.tsx"
83
+ />
84
+
85
+ ### Text with character limit
86
+
87
+ <Story
88
+ packageName="@digigov/form"
89
+ component="inputs/Input"
90
+ story="TextWithCharacterLimit.tsx"
91
+ />
92
+
93
+
5
94
 
6
- ## Example
7
95
 
8
- <Input type="text" />
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useWatch } from 'react-hook-form';
3
3
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
4
- import { Hint } from '@digigov/react-core';
4
+ import { Hint } from '@digigov/react-core/Hint';
5
5
  import TextArea from '@digigov/react-core/TextArea';
6
6
  import TextInput from '@digigov/react-core/TextInput';
7
7
  import { useTranslation } from '@digigov/ui/i18n';
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: OTP Input
3
+ ---
4
+
5
+ # OTP input
6
+
7
+
8
+
9
+ A one-time password (OTP) input element of type `otp`, also known as a one-time PIN, one-time authorization code (OTAC) or dynamic password, is a password that is valid for only one login session or transaction,
10
+ on a computer system or other digital device.
11
+
12
+ ## How to use
13
+
14
+ ### Default
15
+
16
+ <Story
17
+ packageName="@digigov/form"
18
+ component="inputs/OtpInput"
19
+ story="Default.tsx"
20
+ />
21
+
22
+
23
+
@@ -6,7 +6,7 @@ import SingleCharacterInputs, {
6
6
  export const RE_DIGIT = new RegExp(/^\d+$/);
7
7
  export const REMOVE_SPACES = new RegExp(/\s+/g);
8
8
 
9
- function useOtp(onChange, maxLength) {
9
+ export function useOtp(onChange, maxLength) {
10
10
  const [otpValues, setOtpValues] = useState(Array<string>(maxLength).fill(''));
11
11
  const handleChange = useCallback(
12
12
  (otp: string[]) => {
@@ -123,7 +123,7 @@ const SingleCharacterInputPart = ({ ...props }) => {
123
123
  return <SingleCharacterInput {...props} />;
124
124
  };
125
125
 
126
- export const OtpInput = function OtpInput({ name, maxLength = 6, ...props }) {
126
+ export const OtpInput = ({ name, maxLength = 6, ...props }) => {
127
127
  const otp = useOtp(props.onChange, maxLength);
128
128
  return (
129
129
  <SingleCharacterInputs>
@@ -95,3 +95,5 @@ export const Conditional = () => (
95
95
  <Button type="submit">Συνέχεια</Button>
96
96
  </FormBuilder>
97
97
  );
98
+
99
+ export default Conditional;
@@ -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
+ />
@@ -3,7 +3,7 @@ import { useWatch } from 'react-hook-form';
3
3
  import { Field } from '@digigov/form';
4
4
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
5
5
  import { FieldOptionProps } from '@digigov/form/inputs/Label';
6
- import { RadioConditional } from '@digigov/react-core';
6
+ import { RadioConditional } from '@digigov/react-core/RadioConditional';
7
7
  import Hint from '@digigov/react-core/Hint';
8
8
  import RadioContainer from '@digigov/react-core/RadioContainer';
9
9
  import RadioItem from '@digigov/react-core/RadioItem';
@@ -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
  }