@digigov/form 0.12.5 → 0.13.0

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 (95) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/Field/FieldConditional.js +8 -3
  3. package/Field/utils.js +8 -4
  4. package/es/Field/FieldConditional.js +5 -1
  5. package/es/Field/utils.js +8 -4
  6. package/es/inputs/Checkboxes/Checkboxes.stories.js +3 -1
  7. package/es/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
  8. package/es/inputs/Checkboxes/__stories__/Conditional.js +95 -0
  9. package/es/inputs/Checkboxes/__stories__/WithDivider.js +43 -0
  10. package/es/inputs/Checkboxes/index.js +44 -12
  11. package/es/inputs/Input/Input.stories.js +2 -1
  12. package/es/inputs/Input/__stories__/TextWithCharacterLimit.js +31 -0
  13. package/es/inputs/Input/index.js +22 -4
  14. package/es/inputs/Radio/Radio.stories.js +3 -1
  15. package/es/inputs/Radio/Radio.stories.playwright.json +16 -0
  16. package/es/inputs/Radio/__stories__/Conditional.js +95 -0
  17. package/es/inputs/Radio/__stories__/WithDivider.js +48 -0
  18. package/es/inputs/Radio/index.js +15 -4
  19. package/es/registry.js +3 -0
  20. package/es/validators/index.js +10 -2
  21. package/es/validators/utils/index.js +16 -2
  22. package/es/validators/utils/text_limit.js +54 -0
  23. package/esm/Field/FieldConditional.js +5 -1
  24. package/esm/Field/utils.js +8 -4
  25. package/esm/index.js +1 -1
  26. package/esm/inputs/Checkboxes/Checkboxes.stories.js +3 -1
  27. package/esm/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
  28. package/esm/inputs/Checkboxes/__stories__/Conditional.js +95 -0
  29. package/esm/inputs/Checkboxes/__stories__/WithDivider.js +43 -0
  30. package/esm/inputs/Checkboxes/index.js +44 -12
  31. package/esm/inputs/Input/Input.stories.js +2 -1
  32. package/esm/inputs/Input/__stories__/TextWithCharacterLimit.js +31 -0
  33. package/esm/inputs/Input/index.js +22 -4
  34. package/esm/inputs/Radio/Radio.stories.js +3 -1
  35. package/esm/inputs/Radio/Radio.stories.playwright.json +16 -0
  36. package/esm/inputs/Radio/__stories__/Conditional.js +95 -0
  37. package/esm/inputs/Radio/__stories__/WithDivider.js +48 -0
  38. package/esm/inputs/Radio/index.js +15 -4
  39. package/esm/registry.js +3 -0
  40. package/esm/validators/index.js +10 -2
  41. package/esm/validators/utils/index.js +16 -2
  42. package/esm/validators/utils/text_limit.js +54 -0
  43. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  44. package/inputs/Checkboxes/Checkboxes.stories.js +28 -0
  45. package/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
  46. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -0
  47. package/inputs/Checkboxes/__stories__/Conditional.js +115 -0
  48. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -0
  49. package/inputs/Checkboxes/__stories__/WithDivider.js +63 -0
  50. package/inputs/Checkboxes/index.js +52 -12
  51. package/inputs/Input/Input.stories.d.ts +1 -0
  52. package/inputs/Input/Input.stories.js +14 -0
  53. package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +2 -0
  54. package/inputs/Input/__stories__/TextWithCharacterLimit.js +51 -0
  55. package/inputs/Input/index.d.ts +4 -0
  56. package/inputs/Input/index.js +25 -4
  57. package/inputs/Label/index.d.ts +2 -0
  58. package/inputs/Radio/Radio.stories.d.ts +2 -0
  59. package/inputs/Radio/Radio.stories.js +28 -0
  60. package/inputs/Radio/Radio.stories.playwright.json +16 -0
  61. package/inputs/Radio/__stories__/Conditional.d.ts +1 -0
  62. package/inputs/Radio/__stories__/Conditional.js +115 -0
  63. package/inputs/Radio/__stories__/WithDivider.d.ts +2 -0
  64. package/inputs/Radio/__stories__/WithDivider.js +68 -0
  65. package/inputs/Radio/index.js +16 -4
  66. package/package.json +4 -4
  67. package/registry.d.ts +1 -0
  68. package/registry.js +4 -0
  69. package/src/Field/FieldConditional.tsx +8 -2
  70. package/src/Field/utils.ts +10 -4
  71. package/src/inputs/Checkboxes/Checkboxes.stories.js +2 -0
  72. package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
  73. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +100 -0
  74. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +39 -0
  75. package/src/inputs/Checkboxes/index.tsx +59 -29
  76. package/src/inputs/Input/Input.stories.js +2 -1
  77. package/src/inputs/Input/__stories__/TextWithCharacterLimit.tsx +24 -0
  78. package/src/inputs/Input/index.tsx +55 -14
  79. package/src/inputs/Label/index.tsx +2 -0
  80. package/src/inputs/Radio/Radio.stories.js +3 -0
  81. package/src/inputs/Radio/Radio.stories.playwright.json +16 -0
  82. package/src/inputs/Radio/__stories__/Conditional.tsx +97 -0
  83. package/src/inputs/Radio/__stories__/WithDivider.tsx +42 -0
  84. package/src/inputs/Radio/index.tsx +18 -1
  85. package/src/registry.js +3 -0
  86. package/src/types.tsx +4 -2
  87. package/src/validators/index.ts +8 -1
  88. package/src/validators/utils/index.ts +10 -1
  89. package/src/validators/utils/text_limit.ts +44 -0
  90. package/types.d.ts +4 -2
  91. package/validators/index.js +9 -1
  92. package/validators/utils/index.d.ts +1 -0
  93. package/validators/utils/index.js +29 -2
  94. package/validators/utils/text_limit.d.ts +4 -0
  95. package/validators/utils/text_limit.js +65 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  # Change Log - @digigov/form
2
2
 
3
- This log was last generated on Tue, 13 Jun 2023 09:12:26 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 20 Jul 2023 12:53:54 GMT and should not be manually modified.
4
+
5
+ ## 0.13.0
6
+ Thu, 20 Jul 2023 12:53:54 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Add limit logic to text, add validation rules
11
+
12
+ ### Patches
13
+
14
+ - Add conditional nested fields in checkboxes and radios using the mechanism
15
+ - Update registry
16
+ - Add stories with divider at Checkbox and Radio.
17
+
18
+ ## 0.12.5
19
+ Mon, 26 Jun 2023 12:04:49 GMT
20
+
21
+ _Version update only_
4
22
 
5
23
  ## 0.12.2
6
24
  Tue, 13 Jun 2023 09:12:26 GMT
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = exports.FieldConditional = void 0;
9
9
 
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
13
 
12
14
  var _react = _interopRequireDefault(require("react"));
13
15
 
@@ -25,7 +27,7 @@ var ChildFieldMemo = /*#__PURE__*/_react["default"].memo(function ChildField(_re
25
27
  register = _ref.register,
26
28
  error = _ref.error;
27
29
  var newField = (0, _utils.evaluateFieldWithConditions)(field, dependencies);
28
- return /*#__PURE__*/_react["default"].createElement(_FieldBase.FieldBase, (0, _extends2["default"])({}, newField, {
30
+ return /*#__PURE__*/_react["default"].createElement(_FieldBase.FieldBase, (0, _extends3["default"])({}, newField, {
29
31
  name: newField.key,
30
32
  reset: reset,
31
33
  control: control,
@@ -57,10 +59,13 @@ var FieldConditional = function FieldConditional(_ref2) {
57
59
  reset = _ref2.reset,
58
60
  error = _ref2.error;
59
61
  var dependencyKeys = Object.keys(field.condition);
60
- var variables = (0, _reactHookForm.useWatch)({
62
+ var dependencyValues = (0, _reactHookForm.useWatch)({
61
63
  name: dependencyKeys,
62
64
  control: control
63
65
  });
66
+ var variables = dependencyKeys.reduce(function (data, fieldKey, index) {
67
+ return (0, _extends3["default"])({}, data, (0, _defineProperty2["default"])({}, fieldKey, dependencyValues[index]));
68
+ }, {});
64
69
  return /*#__PURE__*/_react["default"].createElement(ChildFieldMemo, {
65
70
  dependencies: variables,
66
71
  field: field,
package/Field/utils.js CHANGED
@@ -171,11 +171,15 @@ function evaluateFieldWithConditions(field, variables) {
171
171
 
172
172
  if (variables) {
173
173
  for (var key in variables) {
174
- if (field.condition[key] && field.condition[key].is === variables[key]) {
175
- var then = field.condition[key].then || {};
174
+ if (field.condition[key] && field.condition[key].is) {
175
+ var is = field.condition[key].is;
176
176
 
177
- for (var attr in then) {
178
- newField[attr] = then[attr];
177
+ if (is === variables[key] || Array.isArray(variables[key]) && variables[key].includes(is)) {
178
+ var then = field.condition[key].then || {};
179
+
180
+ for (var attr in then) {
181
+ newField[attr] = then[attr];
182
+ }
179
183
  }
180
184
  } else if (field.condition[key]) {
181
185
  var otherwise = field.condition[key]["else"] || {};
@@ -1,3 +1,4 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _extends from "@babel/runtime/helpers/extends";
2
3
  import React from 'react';
3
4
  import { useWatch } from 'react-hook-form';
@@ -42,10 +43,13 @@ export var FieldConditional = function FieldConditional(_ref2) {
42
43
  reset = _ref2.reset,
43
44
  error = _ref2.error;
44
45
  var dependencyKeys = Object.keys(field.condition);
45
- var variables = useWatch({
46
+ var dependencyValues = useWatch({
46
47
  name: dependencyKeys,
47
48
  control: control
48
49
  });
50
+ var variables = dependencyKeys.reduce(function (data, fieldKey, index) {
51
+ return _extends({}, data, _defineProperty({}, fieldKey, dependencyValues[index]));
52
+ }, {});
49
53
  return /*#__PURE__*/React.createElement(ChildFieldMemo, {
50
54
  dependencies: variables,
51
55
  field: field,
package/es/Field/utils.js CHANGED
@@ -138,11 +138,15 @@ export function evaluateFieldWithConditions(field, variables) {
138
138
 
139
139
  if (variables) {
140
140
  for (var key in variables) {
141
- if (field.condition[key] && field.condition[key].is === variables[key]) {
142
- var then = field.condition[key].then || {};
141
+ if (field.condition[key] && field.condition[key].is) {
142
+ var is = field.condition[key].is;
143
143
 
144
- for (var attr in then) {
145
- newField[attr] = then[attr];
144
+ if (is === variables[key] || Array.isArray(variables[key]) && variables[key].includes(is)) {
145
+ var then = field.condition[key].then || {};
146
+
147
+ for (var attr in then) {
148
+ newField[attr] = then[attr];
149
+ }
146
150
  }
147
151
  } else if (field.condition[key]) {
148
152
  var otherwise = field.condition[key]["else"] || {};
@@ -4,4 +4,6 @@ export default {
4
4
  component: Checkboxes,
5
5
  displayName: 'Checkboxes'
6
6
  };
7
- export * from '@digigov/form/inputs/Checkboxes/__stories__/Default';
7
+ export * from '@digigov/form/inputs/Checkboxes/__stories__/Default';
8
+ export * from '@digigov/form/inputs/Checkboxes/__stories__/WithDivider';
9
+ export * from '@digigov/form/inputs/Checkboxes/__stories__/Conditional';
@@ -64,6 +64,22 @@
64
64
  "title": "Focus and check using keyboard, click box and submit"
65
65
  }
66
66
  ]
67
+ },
68
+ "digigov-form-inputs-checkboxes--conditional": {
69
+ "actionSets": [
70
+ {
71
+ "actions": [
72
+ {
73
+ "name": "click",
74
+ "args": {
75
+ "selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(1)>label>input"
76
+ }
77
+ }
78
+ ],
79
+ "id": "zpUjNzrqwtmW",
80
+ "title": "Checkboxes conditional action"
81
+ }
82
+ ]
67
83
  }
68
84
  }
69
85
  }
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/core';
4
+ var fields = [{
5
+ key: 'landline',
6
+ type: 'phone_number',
7
+ label: {
8
+ secondary: 'Εισάγετε το νούμερο του σταθερού σας τηλεφώνου.'
9
+ },
10
+ enabled: false,
11
+ condition: {
12
+ auth_form: {
13
+ is: 'via_mobile_phone',
14
+ then: {
15
+ enabled: true,
16
+ required: true
17
+ }
18
+ }
19
+ }
20
+ }, {
21
+ key: 'mobile_phone',
22
+ type: 'mobile_phone',
23
+ label: {
24
+ secondary: 'Εισάγετε το νούμερο του κινητού σας τηλεφώνου.'
25
+ },
26
+ enabled: false,
27
+ condition: {
28
+ auth_form: {
29
+ is: 'via_mobile_phone',
30
+ then: {
31
+ enabled: true,
32
+ required: true
33
+ }
34
+ }
35
+ }
36
+ }, {
37
+ key: 'email',
38
+ type: 'email',
39
+ label: {
40
+ secondary: 'Εισάγετε την διεύθυνση του ηλεκτρονικού σας ταχυδρομείου.'
41
+ },
42
+ enabled: false,
43
+ condition: {
44
+ auth_form: {
45
+ is: 'via_email',
46
+ then: {
47
+ enabled: true,
48
+ required: true
49
+ }
50
+ }
51
+ }
52
+ }, {
53
+ key: 'auth_form',
54
+ type: 'choice:multiple',
55
+ required: true,
56
+ label: {
57
+ primary: 'Επιλέξτε μέθοδο πιστοποίησης',
58
+ secondary: 'Για την ολοκλήρωση της δήλωσης σας, θα χρειαστεί επιπλέον πιστοποίηση. Θα σας στείλουμε ένα κωδικό μιας χρήσης είτε στο τηλέφωνο είτε στην ηλεκτρονική σας διεύθυνση.'
59
+ },
60
+ extra: {
61
+ options: [{
62
+ key: 'via_mobile_phone',
63
+ label: {
64
+ primary: 'Mέσω κινητού τηλεφώνου'
65
+ },
66
+ value: 'via_mobile_phone',
67
+ show: ['mobile_phone', 'landline']
68
+ }, {
69
+ key: 'via_email',
70
+ label: {
71
+ primary: 'Μέσω διεύθυνσης ηλεκτρονικού ταχυδρομείου (e-mail)'
72
+ },
73
+ value: 'via_email',
74
+ show: ['email']
75
+ }]
76
+ }
77
+ }];
78
+
79
+ var _ref = /*#__PURE__*/React.createElement(Field, {
80
+ key: "auth_form",
81
+ name: "auth_form"
82
+ });
83
+
84
+ var _ref2 = /*#__PURE__*/React.createElement(Button, {
85
+ type: "submit"
86
+ }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
87
+
88
+ export var Conditional = function Conditional() {
89
+ return /*#__PURE__*/React.createElement(FormBuilder, {
90
+ onSubmit: function onSubmit(data) {
91
+ console.log(data);
92
+ },
93
+ fields: fields
94
+ }, _ref, _ref2);
95
+ };
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/core';
4
+
5
+ var _ref = /*#__PURE__*/React.createElement(Button, {
6
+ type: "submit"
7
+ }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
8
+
9
+ export var WithDivider = function WithDivider() {
10
+ return /*#__PURE__*/React.createElement(FormBuilder, {
11
+ onSubmit: function onSubmit(data) {
12
+ console.log(data);
13
+ }
14
+ }, /*#__PURE__*/React.createElement(Field, {
15
+ key: 'string',
16
+ name: "string",
17
+ type: "choice:multiple",
18
+ required: true,
19
+ label: {
20
+ primary: 'Πώς αισθάνεστε αυτή τη στιγμή;'
21
+ },
22
+ extra: {
23
+ options: [{
24
+ label: {
25
+ primary: 'Έχω συνάχι'
26
+ },
27
+ value: 'runny-nose'
28
+ }, {
29
+ label: {
30
+ primary: 'Έχω πυρετό'
31
+ },
32
+ value: 'fever'
33
+ }, {
34
+ label: {
35
+ primary: 'Αισθάνομαι κούραση'
36
+ },
37
+ value: 'fatigue',
38
+ divider: 'ή'
39
+ }]
40
+ }
41
+ }), _ref);
42
+ };
43
+ export default WithDivider;
@@ -1,11 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["name", "onChange", "value", "extra", "disabled"];
4
- import React from 'react';
4
+ var _excluded = ["name", "onChange", "value", "extra", "disabled"],
5
+ _excluded2 = ["label", "value", "show", "disabled", "selected"];
6
+ import React, { useState } from 'react';
5
7
  import { useTranslation } from '@digigov/ui/app/i18n';
6
8
  import CoreCheckboxes from '@digigov/react-core/Checkbox';
7
9
  import CheckboxItem from '@digigov/react-core/CheckboxItem';
8
10
  import Hint from '@digigov/react-core/Hint';
11
+ import { Field } from '@digigov/form';
12
+ import { CheckboxConditional } from '@digigov/react-core';
9
13
  export var Checkboxes = function Checkboxes(_ref) {
10
14
  var name = _ref.name,
11
15
  onChange = _ref.onChange,
@@ -18,7 +22,7 @@ export var Checkboxes = function Checkboxes(_ref) {
18
22
 
19
23
  if (!value) value = [];
20
24
 
21
- var handleChange = function handleChange(optionValue) {
25
+ var handleChange = function handleChange(optionValue, idx, show) {
22
26
  return function (evt) {
23
27
  var newValue;
24
28
 
@@ -32,6 +36,14 @@ export var Checkboxes = function Checkboxes(_ref) {
32
36
  newValue = value.filter(function (val) {
33
37
  return val !== optionValue;
34
38
  });
39
+ }
40
+
41
+ if (show && show.length > 0) {
42
+ setChecked(function (items) {
43
+ return items.map(function (item, index) {
44
+ return index === idx ? !item : item;
45
+ });
46
+ });
35
47
  } // reset value to undefined instead of an empty array
36
48
  // so the error state mechanism can throw validation errors
37
49
 
@@ -44,17 +56,32 @@ export var Checkboxes = function Checkboxes(_ref) {
44
56
  var _useTranslation = useTranslation(),
45
57
  t = _useTranslation.t;
46
58
 
59
+ var _useState = useState(Array(options.length).fill(false)),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ checked = _useState2[0],
62
+ setChecked = _useState2[1];
63
+
47
64
  return /*#__PURE__*/React.createElement(CoreCheckboxes, {
48
65
  className: className
49
- }, options.map(function (option, key) {
50
- return /*#__PURE__*/React.createElement(CheckboxItem, _extends({
66
+ }, options.map(function (_ref2, index) {
67
+ var _value;
68
+
69
+ var label = _ref2.label,
70
+ v = _ref2.value,
71
+ show = _ref2.show,
72
+ optionDisabled = _ref2.disabled,
73
+ selected = _ref2.selected,
74
+ option = _objectWithoutProperties(_ref2, _excluded2);
75
+
76
+ return /*#__PURE__*/React.createElement(React.Fragment, {
77
+ key: index
78
+ }, /*#__PURE__*/React.createElement(CheckboxItem, _extends({
79
+ key: "".concat(name, ".").concat(index),
51
80
  name: name,
52
- disabled: disabled,
53
- key: key // eslint-disable-next-line @typescript-eslint/ban-ts-comment
54
- // @ts-ignore
55
- ,
56
- checked: value.includes(option.value),
57
- onChange: handleChange(option.value)
81
+ value: v,
82
+ disabled: disabled || optionDisabled,
83
+ checked: (_value = value) === null || _value === void 0 ? void 0 : _value.includes(v),
84
+ onChange: handleChange(v, index, show)
58
85
  }, option, _extends({}, props, {
59
86
  reset: undefined,
60
87
  defaultValue: undefined,
@@ -62,7 +89,12 @@ export var Checkboxes = function Checkboxes(_ref) {
62
89
  required: undefined,
63
90
  'aria-describedby': undefined,
64
91
  type: 'checkbox'
65
- })), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(option.label.secondary)));
92
+ })), label && label.primary && t(label.primary) || value, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary))), !!checked[index] && show && /*#__PURE__*/React.createElement(CheckboxConditional, null, show.map(function (fieldName) {
93
+ return /*#__PURE__*/React.createElement(Field, {
94
+ name: fieldName,
95
+ key: fieldName
96
+ });
97
+ })), selected && selected());
66
98
  }));
67
99
  };
68
100
  export default Checkboxes;
@@ -11,4 +11,5 @@ export * from '@digigov/form/inputs/Input/__stories__/PhoneNumber';
11
11
  export * from '@digigov/form/inputs/Input/__stories__/MobilePhone';
12
12
  export * from '@digigov/form/inputs/Input/__stories__/AFM';
13
13
  export * from '@digigov/form/inputs/Input/__stories__/IBAN';
14
- export * from '@digigov/form/inputs/Input/__stories__/PostalCode';
14
+ export * from '@digigov/form/inputs/Input/__stories__/PostalCode';
15
+ export * from '@digigov/form/inputs/Input/__stories__/TextWithCharacterLimit';
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/core';
4
+
5
+ var _ref = /*#__PURE__*/React.createElement(Button, {
6
+ type: "submit"
7
+ }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
8
+
9
+ export var TextWithCharacterLimit = function TextWithCharacterLimit() {
10
+ return /*#__PURE__*/React.createElement(FormBuilder, {
11
+ onSubmit: function onSubmit(data) {
12
+ console.log(data);
13
+ }
14
+ }, /*#__PURE__*/React.createElement(Field, {
15
+ key: "text",
16
+ name: "text",
17
+ type: "text",
18
+ label: {
19
+ primary: 'Μπορείτε να δώσετε περισσότερες πληροφορίες;'
20
+ },
21
+ required: true,
22
+ extra: {
23
+ limit: {
24
+ min: 3,
25
+ max: 10
26
+ },
27
+ multiline: true
28
+ }
29
+ }), _ref);
30
+ };
31
+ export default TextWithCharacterLimit;
@@ -1,9 +1,12 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["name", "type", "extra"];
3
+ var _excluded = ["name", "control", "type", "extra"];
4
4
  import React from 'react';
5
5
  import TextInput from '@digigov/react-core/TextInput';
6
6
  import TextArea from '@digigov/react-core/TextArea';
7
+ import { Hint } from '@digigov/react-core';
8
+ import { useWatch } from 'react-hook-form';
9
+ import { useTranslation } from '@digigov/ui/app/i18n';
7
10
  var TYPES_MAP = {
8
11
  string: 'text',
9
12
  "int": 'text',
@@ -12,14 +15,17 @@ var TYPES_MAP = {
12
15
  };
13
16
  export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
14
17
  var name = _ref.name,
18
+ control = _ref.control,
15
19
  type = _ref.type,
16
20
  extra = _ref.extra,
17
21
  props = _objectWithoutProperties(_ref, _excluded);
18
22
 
23
+ // eslint-disable-next-line prefer-const
19
24
  var _ref2 = extra || {},
20
25
  _ref2$multiline = _ref2.multiline,
21
26
  multiline = _ref2$multiline === void 0 ? false : _ref2$multiline,
22
- rows = _ref2.rows;
27
+ rows = _ref2.rows,
28
+ limit = _ref2.limit;
23
29
 
24
30
  var _ref3 = extra || {},
25
31
  className = _ref3.className; // if enforced to multiline use true. Derive from type otherwise.
@@ -31,8 +37,16 @@ export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref
31
37
 
32
38
  var fieldType = TYPES_MAP[type || 'text'] || 'text';
33
39
 
40
+ var _useTranslation = useTranslation(),
41
+ t = _useTranslation.t;
42
+
43
+ var currentValue = useWatch({
44
+ control: control,
45
+ name: name
46
+ });
47
+
34
48
  if (multiline === true) {
35
- return /*#__PURE__*/React.createElement(TextArea, _extends({
49
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextArea, _extends({
36
50
  name: name,
37
51
  className: className,
38
52
  rows: rows,
@@ -41,7 +55,11 @@ export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref
41
55
  reset: undefined,
42
56
  required: undefined,
43
57
  type: fieldType
44
- })));
58
+ }))), (limit === null || limit === void 0 ? void 0 : limit.max) && /*#__PURE__*/React.createElement(Hint, null, currentValue === undefined || (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) >= 0 && (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) <= (limit === null || limit === void 0 ? void 0 : limit.max) ? /*#__PURE__*/React.createElement("span", null, t('form.info.text.you_have'), ' ', /*#__PURE__*/React.createElement("b", null, !currentValue ? limit.max : (limit === null || limit === void 0 ? void 0 : limit.max) - (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length)), ' ', currentValue && (limit === null || limit === void 0 ? void 0 : limit.max) - (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) === 1 ? "".concat(t('form.info.text.character')) : "".concat(t('form.info.text.characters')), ' ', t('form.info.text.remaining'), ".") : /*#__PURE__*/React.createElement("span", {
59
+ style: {
60
+ color: '#b60202'
61
+ }
62
+ }, t('form.info.text.you_have'), ' ', /*#__PURE__*/React.createElement("b", null, currentValue && (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) - (limit === null || limit === void 0 ? void 0 : limit.max)), ' ', (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) - (limit === null || limit === void 0 ? void 0 : limit.max) === 1 ? "".concat(t('form.info.text.character')) : "".concat(t('form.info.text.characters')), ' ', t('form.info.text.too_many'), ".")));
45
63
  } else {
46
64
  return /*#__PURE__*/React.createElement(TextInput, _extends({
47
65
  name: name,
@@ -4,4 +4,6 @@ export default {
4
4
  component: Radio,
5
5
  displayName: 'Radio'
6
6
  };
7
- export * from '@digigov/form/inputs/Radio/__stories__/Default';
7
+ export * from '@digigov/form/inputs/Radio/__stories__/Default';
8
+ export * from '@digigov/form/inputs/Radio/__stories__/WithDivider';
9
+ export * from '@digigov/form/inputs/Radio/__stories__/Conditional';
@@ -52,6 +52,22 @@
52
52
  "title": "select option with keyboard and submit"
53
53
  }
54
54
  ]
55
+ },
56
+ "digigov-form-inputs-radio--conditional": {
57
+ "actionSets": [
58
+ {
59
+ "actions": [
60
+ {
61
+ "name": "click",
62
+ "args": {
63
+ "selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(1)>div>label>input"
64
+ }
65
+ }
66
+ ],
67
+ "id": "LAUEuHh58XiI",
68
+ "title": "Radio conditional action"
69
+ }
70
+ ]
55
71
  }
56
72
  }
57
73
  }
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/core';
4
+ var fields = [{
5
+ key: 'landline',
6
+ type: 'phone_number',
7
+ label: {
8
+ secondary: 'Εισάγετε το νούμερο του σταθερού σας τηλεφώνου.'
9
+ },
10
+ enabled: false,
11
+ condition: {
12
+ auth_form: {
13
+ is: 'via_mobile_phone',
14
+ then: {
15
+ enabled: true,
16
+ required: true
17
+ }
18
+ }
19
+ }
20
+ }, {
21
+ key: 'mobile_phone',
22
+ type: 'mobile_phone',
23
+ label: {
24
+ secondary: 'Εισάγετε το νούμερο του κινητού σας τηλεφώνου.'
25
+ },
26
+ enabled: false,
27
+ condition: {
28
+ auth_form: {
29
+ is: 'via_mobile_phone',
30
+ then: {
31
+ enabled: true,
32
+ required: true
33
+ }
34
+ }
35
+ }
36
+ }, {
37
+ key: 'email',
38
+ type: 'email',
39
+ label: {
40
+ secondary: 'Εισάγετε την διεύθυνση του ηλεκτρονικού σας ταχυδρομείου.'
41
+ },
42
+ enabled: false,
43
+ condition: {
44
+ auth_form: {
45
+ is: 'via_email',
46
+ then: {
47
+ enabled: true,
48
+ required: true
49
+ }
50
+ }
51
+ }
52
+ }, {
53
+ key: 'auth_form',
54
+ type: 'choice:single',
55
+ required: true,
56
+ label: {
57
+ primary: 'Επιλέξτε μέθοδο πιστοποίησης',
58
+ secondary: 'Για την ολοκλήρωση της δήλωσης σας, θα χρειαστεί επιπλέον πιστοποίηση. Θα σας στείλουμε ένα κωδικό μιας χρήσης είτε στο τηλέφωνο είτε στην ηλεκτρονική σας διεύθυνση.'
59
+ },
60
+ extra: {
61
+ options: [{
62
+ key: 'via_mobile_phone',
63
+ label: {
64
+ primary: 'Mέσω κινητού τηλεφώνου'
65
+ },
66
+ value: 'via_mobile_phone',
67
+ show: ['mobile_phone', 'landline']
68
+ }, {
69
+ key: 'via_email',
70
+ label: {
71
+ primary: 'Μέσω διεύθυνσης ηλεκτρονικού ταχυδρομείου (e-mail)'
72
+ },
73
+ value: 'via_email',
74
+ show: ['email']
75
+ }]
76
+ }
77
+ }];
78
+
79
+ var _ref = /*#__PURE__*/React.createElement(Field, {
80
+ key: "auth_form",
81
+ name: "auth_form"
82
+ });
83
+
84
+ var _ref2 = /*#__PURE__*/React.createElement(Button, {
85
+ type: "submit"
86
+ }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
87
+
88
+ export var Conditional = function Conditional() {
89
+ return /*#__PURE__*/React.createElement(FormBuilder, {
90
+ onSubmit: function onSubmit(data) {
91
+ console.log(data);
92
+ },
93
+ fields: fields
94
+ }, _ref, _ref2);
95
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/core';
4
+
5
+ var _ref = /*#__PURE__*/React.createElement(Button, {
6
+ type: "submit"
7
+ }, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
8
+
9
+ export var WithDivider = function WithDivider() {
10
+ return /*#__PURE__*/React.createElement(FormBuilder, {
11
+ onSubmit: function onSubmit(data) {
12
+ console.log(data);
13
+ }
14
+ }, /*#__PURE__*/React.createElement(Field, {
15
+ key: 'string',
16
+ name: "string",
17
+ type: "choice:single",
18
+ required: true,
19
+ label: {
20
+ primary: 'Ποια ειναι η χώρα της διαμονής σας;'
21
+ },
22
+ extra: {
23
+ options: [{
24
+ label: {
25
+ primary: 'Ελλάδα'
26
+ },
27
+ value: 'greece'
28
+ }, {
29
+ label: {
30
+ primary: 'Κύπρος'
31
+ },
32
+ value: 'cyprus'
33
+ }, {
34
+ label: {
35
+ primary: 'Χώρα της Ευρωπαϊκής Ένωσης'
36
+ },
37
+ value: 'eu'
38
+ }, {
39
+ label: {
40
+ primary: 'Ηνωμένες Πολιτείες της Αμερικής'
41
+ },
42
+ value: 'usa',
43
+ divider: 'ή'
44
+ }]
45
+ }
46
+ }), _ref);
47
+ };
48
+ export default WithDivider;