@digigov/form 0.4.5 → 0.4.9
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.
- package/CHANGELOG.md +28 -1
- package/Field/index.js +35 -45
- package/Fieldset/index.js +10 -14
- package/Questions/Step/index.js +1 -0
- package/es/Field/index.js +29 -41
- package/es/Fieldset/index.js +9 -14
- package/es/Questions/Step/index.js +2 -0
- package/es/index.js +2 -0
- package/es/index.mdx +0 -3
- package/es/inputs/Checkboxes/index.js +19 -51
- package/es/inputs/FileInput/index.js +8 -42
- package/es/inputs/Input/index.js +24 -18
- package/es/inputs/Label/index.js +6 -34
- package/es/inputs/Radio/index.js +24 -87
- package/es/inputs/Select/index.js +10 -31
- package/es/utils.js +1 -0
- package/es/validators.js +4 -4
- package/esm/Field/index.js +29 -41
- package/esm/Fieldset/index.js +9 -14
- package/esm/Questions/Step/index.js +2 -0
- package/esm/index.js +3 -1
- package/esm/index.mdx +0 -3
- package/esm/inputs/Checkboxes/index.js +19 -51
- package/esm/inputs/FileInput/index.js +8 -42
- package/esm/inputs/Input/index.js +24 -18
- package/esm/inputs/Label/index.js +6 -34
- package/esm/inputs/Radio/index.js +24 -87
- package/esm/inputs/Select/index.js +10 -31
- package/esm/utils.js +1 -0
- package/esm/validators.js +4 -4
- package/index.js +1 -0
- package/index.mdx +0 -3
- package/inputs/Checkboxes/index.js +19 -53
- package/inputs/FileInput/index.js +8 -45
- package/inputs/Input/index.js +25 -18
- package/inputs/Label/index.js +6 -37
- package/inputs/Radio/index.js +26 -95
- package/inputs/Select/index.js +10 -34
- package/libs/form/src/Field/index.d.ts +10 -7
- package/libs/form/src/Fieldset/index.d.ts +9 -3
- package/libs/form/src/index.d.ts +1 -0
- package/libs/form/src/inputs/Checkboxes/index.d.ts +2 -1
- package/libs/form/src/inputs/Input/index.d.ts +1 -1
- package/libs/form/src/inputs/Radio/index.d.ts +1 -11
- package/libs/form/src/validators.d.ts +4 -2
- package/libs/ui/src/core/Accordion/index.d.ts +3 -3
- package/libs/ui/src/core/Blockquote/index.d.ts +1 -1
- package/libs/ui/src/core/Button/BackButton.d.ts +1 -1
- package/libs/ui/src/core/Button/ButtonLink.d.ts +1 -1
- package/libs/ui/src/core/Button/index.d.ts +1 -1
- package/libs/ui/src/core/NavList/NavList.d.ts +1 -1
- package/libs/ui/src/core/NavList/NavListItemBase.d.ts +1 -1
- package/libs/ui/src/typography/Caption.d.ts +1 -1
- package/libs-ui/react-core/src/Accordion/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionControls/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSection/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSectionContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/AccordionSectionHeader/index.d.ts +1 -1
- package/libs-ui/react-core/src/BackLink/index.d.ts +1 -1
- package/libs-ui/react-core/src/Blockquote/index.d.ts +1 -1
- package/libs-ui/react-core/src/Button/index.d.ts +5 -1
- package/libs-ui/react-core/src/ButtonLink/index.d.ts +1 -1
- package/libs-ui/react-core/src/CallToAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/Checkbox/index.d.ts +11 -0
- package/libs-ui/react-core/src/CheckboxItem/index.d.ts +19 -0
- package/libs-ui/react-core/src/Details/index.d.ts +1 -1
- package/libs-ui/react-core/src/DetailsContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/DetailsSummary/index.d.ts +1 -1
- package/libs-ui/react-core/src/ErrorMessage/index.d.ts +11 -0
- package/libs-ui/react-core/src/ErrorSummary/index.d.ts +1 -1
- package/libs-ui/react-core/src/Field/index.d.ts +13 -0
- package/libs-ui/react-core/src/Fieldset/index.d.ts +10 -0
- package/libs-ui/react-core/src/FieldsetLegend/index.d.ts +19 -0
- package/libs-ui/react-core/src/FileUpload/index.d.ts +14 -0
- package/libs-ui/react-core/src/Heading/index.d.ts +1 -1
- package/libs-ui/react-core/src/HeadingCaption/index.d.ts +1 -1
- package/libs-ui/react-core/src/Hint/index.d.ts +9 -0
- package/libs-ui/react-core/src/Label/index.d.ts +9 -0
- package/libs-ui/react-core/src/LabelTitle/index.d.ts +19 -0
- package/libs-ui/react-core/src/List/index.d.ts +1 -1
- package/libs-ui/react-core/src/ListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/NormalText/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBanner/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerContent/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerHeader/index.d.ts +1 -1
- package/libs-ui/react-core/src/NotificationBannerHeading/index.d.ts +1 -1
- package/libs-ui/react-core/src/Paragraph/index.d.ts +1 -1
- package/libs-ui/react-core/src/PhaseBanner/index.d.ts +1 -1
- package/libs-ui/react-core/src/PhaseBannerTag/index.d.ts +1 -1
- package/libs-ui/react-core/src/Radio/index.d.ts +10 -0
- package/libs-ui/react-core/src/RadioItem/index.d.ts +18 -0
- package/libs-ui/react-core/src/SectionBreak/index.d.ts +1 -1
- package/libs-ui/react-core/src/Select/index.d.ts +14 -0
- package/libs-ui/react-core/src/SelectOption/index.d.ts +18 -0
- package/libs-ui/react-core/src/SummaryList/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemKey/index.d.ts +1 -1
- package/libs-ui/react-core/src/SummaryListItemValue/index.d.ts +1 -1
- package/libs-ui/react-core/src/Tabs/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsHeading/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsList/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsListItem/index.d.ts +1 -1
- package/libs-ui/react-core/src/TabsPanel/index.d.ts +1 -1
- package/libs-ui/react-core/src/TextArea/index.d.ts +23 -0
- package/libs-ui/react-core/src/TextInput/index.d.ts +28 -0
- package/libs-ui/react-core/src/WarningText/index.d.ts +1 -1
- package/package.json +2 -2
- package/utils.js +1 -0
- package/validators.js +4 -4
package/es/inputs/Input/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["name", "type", "extra"];
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import
|
|
5
|
+
import TextInput from '@digigov/react-core/TextInput';
|
|
6
|
+
import TextArea from '@digigov/react-core/TextArea';
|
|
6
7
|
var TYPES_MAP = {
|
|
7
8
|
string: 'text',
|
|
8
9
|
"int": 'number',
|
|
@@ -16,11 +17,12 @@ var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
|
|
|
16
17
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
18
|
|
|
18
19
|
var _ref2 = extra || {},
|
|
19
|
-
multiline = _ref2.multiline,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
_ref2$multiline = _ref2.multiline,
|
|
21
|
+
multiline = _ref2$multiline === void 0 ? false : _ref2$multiline,
|
|
22
|
+
rows = _ref2.rows;
|
|
23
|
+
|
|
24
|
+
var _ref3 = extra || {},
|
|
25
|
+
className = _ref3.className; // if enforced to multiline use true. Derive from type otherwise.
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
multiline = multiline === true || type === 'text'; // use explicit rows value if set. Derive from multiline otherwise.
|
|
@@ -28,17 +30,21 @@ var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
|
|
|
28
30
|
rows = rows || (multiline ? 4 : 1); // translate dilosi type to HTML Input type
|
|
29
31
|
|
|
30
32
|
var fieldType = TYPES_MAP[type || 'text'] || 'text';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
|
|
34
|
+
if (multiline === true) {
|
|
35
|
+
return /*#__PURE__*/React.createElement(TextArea, _extends({
|
|
36
|
+
name: name,
|
|
37
|
+
className: className,
|
|
38
|
+
rows: rows,
|
|
39
|
+
ref: ref
|
|
40
|
+
}, props));
|
|
41
|
+
} else {
|
|
42
|
+
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
|
43
|
+
name: name,
|
|
44
|
+
type: fieldType,
|
|
45
|
+
className: className,
|
|
46
|
+
ref: ref
|
|
47
|
+
}, props));
|
|
48
|
+
}
|
|
43
49
|
});
|
|
44
50
|
export default Input;
|
package/es/inputs/Label/index.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { makeStyles } from '@material-ui/core/styles';
|
|
5
|
-
import NormalText from '@digigov/ui/typography/NormalText';
|
|
2
|
+
import LabelTitle from '@digigov/react-core/LabelTitle';
|
|
3
|
+
import Hint from '@digigov/react-core/Hint';
|
|
6
4
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
7
|
-
var useLabelStyles = makeStyles(function (theme) {
|
|
8
|
-
return {
|
|
9
|
-
labels: {
|
|
10
|
-
padding: theme.spacing(1, 0)
|
|
11
|
-
},
|
|
12
|
-
primaryLabel: {
|
|
13
|
-
fontWeight: 500,
|
|
14
|
-
lineHeight: '1.5em'
|
|
15
|
-
},
|
|
16
|
-
secondaryLabel: {
|
|
17
|
-
fontWeight: 'normal',
|
|
18
|
-
color: theme.palette.grey['700']
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
5
|
export var Label = function Label(_ref) {
|
|
23
6
|
var className = _ref.className,
|
|
24
7
|
label = _ref.label,
|
|
25
8
|
value = _ref.value;
|
|
26
|
-
var classes = useLabelStyles();
|
|
27
9
|
|
|
28
10
|
var _useTranslation = useTranslation(),
|
|
29
11
|
t = _useTranslation.t;
|
|
@@ -32,20 +14,10 @@ export var Label = function Label(_ref) {
|
|
|
32
14
|
return null;
|
|
33
15
|
}
|
|
34
16
|
|
|
35
|
-
return /*#__PURE__*/React.createElement(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, /*#__PURE__*/React.createElement(
|
|
39
|
-
item: true,
|
|
40
|
-
xs: 12
|
|
41
|
-
}, /*#__PURE__*/React.createElement(NormalText, {
|
|
42
|
-
className: classes.primaryLabel
|
|
43
|
-
}, label && label.primary && t(label.primary) || value)), label && label.secondary && /*#__PURE__*/React.createElement(Grid, {
|
|
44
|
-
item: true,
|
|
45
|
-
xs: 12
|
|
46
|
-
}, /*#__PURE__*/React.createElement(NormalText, {
|
|
47
|
-
className: classes.secondaryLabel
|
|
48
|
-
}, t(label.secondary))));
|
|
17
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LabelTitle, {
|
|
18
|
+
className: className,
|
|
19
|
+
size: "s"
|
|
20
|
+
}, label && label.primary && t(label.primary) || value), label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)));
|
|
49
21
|
};
|
|
50
22
|
Label.defaultProps = {
|
|
51
23
|
label: {}
|
package/es/inputs/Radio/index.js
CHANGED
|
@@ -1,79 +1,18 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import RadioGroup from '@material-ui/core/RadioGroup';
|
|
7
|
-
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
8
|
-
import FormControl from '@material-ui/core/FormControl';
|
|
9
|
-
import Label from '@digigov/form/inputs/Label';
|
|
3
|
+
import Radio from '@digigov/react-core/Radio';
|
|
4
|
+
import RadioItem from '@digigov/react-core/RadioItem';
|
|
5
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
10
6
|
import { useWatch } from 'react-hook-form';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
margin: theme.spacing(1, 0)
|
|
15
|
-
},
|
|
16
|
-
formControlLabelActive: {
|
|
17
|
-
backgroundColor: theme.palette.grey['200'],
|
|
18
|
-
border: "2px solid ".concat(theme.palette.primary.main)
|
|
19
|
-
},
|
|
20
|
-
formControlLabel: {
|
|
21
|
-
width: '100%',
|
|
22
|
-
alignItems: 'flex-start',
|
|
23
|
-
fontWeight: 'bolder',
|
|
24
|
-
padding: theme.spacing(0.5),
|
|
25
|
-
margin: theme.spacing(0.5, 0)
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
var _ref2 = /*#__PURE__*/React.createElement(Radio, {
|
|
31
|
-
color: "primary"
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export var RadioButton = function RadioButton(_ref) {
|
|
35
|
-
var dense = _ref.dense,
|
|
36
|
-
value = _ref.value,
|
|
37
|
-
label = _ref.label,
|
|
38
|
-
register = _ref.register,
|
|
39
|
-
active = _ref.active,
|
|
7
|
+
import Hint from '@digigov/react-core/Hint';
|
|
8
|
+
export var RadioButtonsGroup = function RadioButtonsGroup(_ref) {
|
|
9
|
+
var register = _ref.register,
|
|
40
10
|
name = _ref.name,
|
|
11
|
+
control = _ref.control,
|
|
12
|
+
_ref$extra = _ref.extra,
|
|
13
|
+
options = _ref$extra.options,
|
|
14
|
+
className = _ref$extra.className,
|
|
41
15
|
disabled = _ref.disabled;
|
|
42
|
-
var classes = useRadioButtonStyles();
|
|
43
|
-
return /*#__PURE__*/React.createElement(FormControlLabel, {
|
|
44
|
-
className: clsx(classes.formControlLabel, active && classes.formControlLabelActive, dense && classes.dense),
|
|
45
|
-
value: value,
|
|
46
|
-
name: name,
|
|
47
|
-
disabled: disabled,
|
|
48
|
-
inputRef: register,
|
|
49
|
-
control: _ref2,
|
|
50
|
-
label: /*#__PURE__*/React.createElement(Label, {
|
|
51
|
-
label: label,
|
|
52
|
-
value: value
|
|
53
|
-
})
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
var useRadioButtonsGroupStyles = makeStyles(function (theme) {
|
|
57
|
-
return {
|
|
58
|
-
formControl: {
|
|
59
|
-
margin: theme.spacing(0, 0, 2, 0),
|
|
60
|
-
width: '100%'
|
|
61
|
-
},
|
|
62
|
-
dense: {
|
|
63
|
-
margin: theme.spacing(1, 0)
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
export var RadioButtonsGroup = function RadioButtonsGroup(_ref3) {
|
|
68
|
-
var name = _ref3.name,
|
|
69
|
-
register = _ref3.register,
|
|
70
|
-
control = _ref3.control,
|
|
71
|
-
_ref3$extra = _ref3.extra,
|
|
72
|
-
options = _ref3$extra.options,
|
|
73
|
-
dense = _ref3$extra.dense,
|
|
74
|
-
className = _ref3$extra.className,
|
|
75
|
-
disabled = _ref3.disabled;
|
|
76
|
-
var classes = useRadioButtonsGroupStyles();
|
|
77
16
|
var currentValue = useWatch({
|
|
78
17
|
control: control,
|
|
79
18
|
name: name
|
|
@@ -83,26 +22,24 @@ export var RadioButtonsGroup = function RadioButtonsGroup(_ref3) {
|
|
|
83
22
|
_useState2 = _slicedToArray(_useState, 1),
|
|
84
23
|
defaultValue = _useState2[0];
|
|
85
24
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
25
|
+
var _useTranslation = useTranslation(),
|
|
26
|
+
t = _useTranslation.t;
|
|
27
|
+
|
|
28
|
+
return /*#__PURE__*/React.createElement(Radio, {
|
|
29
|
+
className: className,
|
|
90
30
|
defaultValue: defaultValue,
|
|
91
|
-
id: name
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
31
|
+
id: name
|
|
32
|
+
}, options.map(function (_ref2) {
|
|
33
|
+
var label = _ref2.label,
|
|
34
|
+
v = _ref2.value,
|
|
35
|
+
optionDisabled = _ref2.disabled;
|
|
36
|
+
return /*#__PURE__*/React.createElement(RadioItem, {
|
|
37
|
+
ref: register,
|
|
98
38
|
key: v,
|
|
99
|
-
label: label,
|
|
100
39
|
name: name,
|
|
101
|
-
active: v === currentValue,
|
|
102
40
|
value: v,
|
|
103
|
-
register: register,
|
|
104
41
|
disabled: disabled || optionDisabled
|
|
105
|
-
});
|
|
106
|
-
}))
|
|
42
|
+
}, label && label.primary && t(label.primary) || v, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)));
|
|
43
|
+
}));
|
|
107
44
|
};
|
|
108
45
|
export default RadioButtonsGroup;
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import FormControl from '@material-ui/core/FormControl';
|
|
5
|
-
import MuiSelect from '@material-ui/core/Select';
|
|
6
|
-
var useSelectStyles = makeStyles(function (theme) {
|
|
7
|
-
return {
|
|
8
|
-
formControl: {
|
|
9
|
-
minWidth: 120
|
|
10
|
-
},
|
|
11
|
-
selectEmpty: {
|
|
12
|
-
marginTop: theme.spacing(2)
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
});
|
|
2
|
+
import CoreSelect from '@digigov/react-core/Select';
|
|
3
|
+
import SelectOption from '@digigov/react-core/SelectOption';
|
|
16
4
|
|
|
17
|
-
var _ref2 = /*#__PURE__*/React.createElement(
|
|
5
|
+
var _ref2 = /*#__PURE__*/React.createElement(SelectOption, {
|
|
18
6
|
value: ""
|
|
19
7
|
});
|
|
20
8
|
|
|
@@ -24,27 +12,18 @@ export var Select = /*#__PURE__*/React.forwardRef(function WrappedSelect(_ref, r
|
|
|
24
12
|
options = _ref$extra.options,
|
|
25
13
|
className = _ref$extra.className,
|
|
26
14
|
disabled = _ref.disabled;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, /*#__PURE__*/React.createElement(MuiSelect, {
|
|
32
|
-
"native": true,
|
|
33
|
-
autoWidth: true,
|
|
34
|
-
inputRef: ref,
|
|
35
|
-
inputProps: {
|
|
36
|
-
name: name,
|
|
37
|
-
id: name
|
|
38
|
-
},
|
|
15
|
+
return /*#__PURE__*/React.createElement(CoreSelect, {
|
|
16
|
+
className: className,
|
|
17
|
+
ref: ref,
|
|
18
|
+
name: name,
|
|
39
19
|
disabled: disabled
|
|
40
20
|
}, _ref2, options.map(function (_ref3) {
|
|
41
21
|
var value = _ref3.value,
|
|
42
22
|
label = _ref3.label;
|
|
43
|
-
return /*#__PURE__*/React.createElement(
|
|
23
|
+
return /*#__PURE__*/React.createElement(SelectOption, {
|
|
44
24
|
key: value,
|
|
45
|
-
value: value
|
|
46
|
-
title: label && label.secondary
|
|
25
|
+
value: value
|
|
47
26
|
}, label && label.primary ? label.primary : value);
|
|
48
|
-
}))
|
|
27
|
+
}));
|
|
49
28
|
});
|
|
50
29
|
export default Select;
|
package/es/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
4
4
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
5
5
|
import _extends from "@babel/runtime/helpers/extends";
|
|
6
6
|
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
8
|
var parseErrorSchema = function parseErrorSchema(error, validateAllFieldCriteria) {
|
|
8
9
|
return Array.isArray(error.inner) && error.inner.length ? error.inner.reduce(function (previous, _ref) {
|
|
9
10
|
var path = _ref.path,
|
package/es/validators.js
CHANGED
|
@@ -366,7 +366,8 @@ function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
366
366
|
return fieldSchemas;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
function getYupObjectShape(
|
|
369
|
+
function getYupObjectShape( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
370
|
+
fields, yupTypeMap, validatorRegistry) {
|
|
370
371
|
if (!fields.current) {
|
|
371
372
|
var fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);
|
|
372
373
|
return yup.object().shape(fieldSchemas);
|
|
@@ -407,7 +408,6 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
407
408
|
iban: function iban(field) {
|
|
408
409
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
409
410
|
},
|
|
410
|
-
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
411
411
|
mobile_phone: function mobile_phone() {
|
|
412
412
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
413
413
|
},
|
|
@@ -419,9 +419,9 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
419
419
|
}
|
|
420
420
|
};
|
|
421
421
|
return yupTypeMap;
|
|
422
|
-
};
|
|
423
|
-
|
|
422
|
+
};
|
|
424
423
|
|
|
424
|
+
// Create a yup validation schema from given fields input
|
|
425
425
|
export function useValidationSchema(fields, validatorRegistry) {
|
|
426
426
|
return useMemo(function () {
|
|
427
427
|
var yupTypeMap = getYUPTypeMap();
|
package/esm/Field/index.js
CHANGED
|
@@ -5,15 +5,18 @@ import React, { useContext, useMemo } from 'react';
|
|
|
5
5
|
import { ConditionalField } from '@digigov/form/Field/ConditionalField';
|
|
6
6
|
import { Controller } from 'react-hook-form';
|
|
7
7
|
import { FormContext } from '@digigov/form';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import CoreField from '@digigov/react-core/Field';
|
|
9
|
+
import CoreLabel from '@digigov/react-core/Label';
|
|
10
|
+
import CoreFieldset from '@digigov/react-core/Fieldset';
|
|
11
|
+
import Hint from '@digigov/react-core/Hint';
|
|
12
|
+
import FieldsetLegend from '@digigov/react-core/FieldsetLegend';
|
|
13
|
+
import ErrorMessage from '@digigov/react-core/ErrorMessage';
|
|
10
14
|
import Input from '@digigov/form/inputs/Input';
|
|
11
15
|
import Checkboxes from '@digigov/form/inputs/Checkboxes';
|
|
12
16
|
import Radio from '@digigov/form/inputs/Radio';
|
|
13
17
|
import Select from '@digigov/form/inputs/Select';
|
|
14
18
|
import FileInput from '@digigov/form/inputs/FileInput';
|
|
15
19
|
import Label from '@digigov/form/inputs/Label';
|
|
16
|
-
import NormalText from '@digigov/ui/typography/NormalText';
|
|
17
20
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
18
21
|
var FIELD_COMPONENTS = {
|
|
19
22
|
text: {
|
|
@@ -26,10 +29,12 @@ var FIELD_COMPONENTS = {
|
|
|
26
29
|
component: FileInput
|
|
27
30
|
},
|
|
28
31
|
'choice:multiple': {
|
|
32
|
+
wrapper: 'fieldset',
|
|
29
33
|
controlled: true,
|
|
30
34
|
component: Checkboxes
|
|
31
35
|
},
|
|
32
36
|
'choice:single': {
|
|
37
|
+
wrapper: 'fieldset',
|
|
33
38
|
controlled: false,
|
|
34
39
|
component: Radio
|
|
35
40
|
}
|
|
@@ -40,56 +45,35 @@ var ALTERNATIVE_COMPONENTS = {
|
|
|
40
45
|
controlled: false
|
|
41
46
|
}
|
|
42
47
|
};
|
|
43
|
-
export var useFieldContainerStyles = makeStyles(function (theme) {
|
|
44
|
-
return {
|
|
45
|
-
fieldContainer: {
|
|
46
|
-
marginBottom: theme.spacing(2)
|
|
47
|
-
},
|
|
48
|
-
fieldLabel: {
|
|
49
|
-
fontWeight: 500
|
|
50
|
-
},
|
|
51
|
-
hint: {
|
|
52
|
-
color: theme.palette.grey['700']
|
|
53
|
-
},
|
|
54
|
-
errorContainer: {
|
|
55
|
-
borderLeft: "".concat(theme.spacing(0.5), "px solid ").concat(theme.palette.error.main, " "),
|
|
56
|
-
paddingLeft: theme.spacing(2)
|
|
57
|
-
},
|
|
58
|
-
error: {
|
|
59
|
-
color: theme.palette.error.main,
|
|
60
|
-
fontWeight: 'bolder',
|
|
61
|
-
margin: theme.spacing(2, 0)
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
48
|
|
|
66
49
|
var FieldContainer = function FieldContainer(_ref) {
|
|
67
|
-
var
|
|
50
|
+
var wrapper = _ref.wrapper,
|
|
68
51
|
label = _ref.label,
|
|
69
52
|
children = _ref.children,
|
|
70
53
|
error = _ref.error;
|
|
71
|
-
var classes = useFieldContainerStyles();
|
|
72
54
|
|
|
73
55
|
var _useTranslation = useTranslation(),
|
|
74
56
|
t = _useTranslation.t;
|
|
75
57
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
if (wrapper === 'fieldset') {
|
|
59
|
+
return /*#__PURE__*/React.createElement(CoreField, {
|
|
60
|
+
error: !!error
|
|
61
|
+
}, /*#__PURE__*/React.createElement(CoreFieldset, null, /*#__PURE__*/React.createElement(FieldsetLegend, {
|
|
62
|
+
size: "s"
|
|
63
|
+
}, label && label.primary, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)), error && /*#__PURE__*/React.createElement(ErrorMessage, null, t((error === null || error === void 0 ? void 0 : error.message) || '')))), children);
|
|
64
|
+
} else {
|
|
65
|
+
return /*#__PURE__*/React.createElement(CoreField, {
|
|
66
|
+
error: !!error
|
|
67
|
+
}, /*#__PURE__*/React.createElement(CoreLabel, null, label && /*#__PURE__*/React.createElement(Label, {
|
|
68
|
+
label: label
|
|
69
|
+
}), error && /*#__PURE__*/React.createElement(ErrorMessage, null, t((error === null || error === void 0 ? void 0 : error.message) || '')), children));
|
|
70
|
+
}
|
|
88
71
|
};
|
|
89
72
|
|
|
90
73
|
export var FieldBase = function FieldBase(props) {
|
|
91
74
|
var name = props.name,
|
|
92
75
|
Component = props.component,
|
|
76
|
+
wrapper = props.wrapper,
|
|
93
77
|
control = props.control,
|
|
94
78
|
type = props.type,
|
|
95
79
|
_props$controlled = props.controlled,
|
|
@@ -113,7 +97,8 @@ export var FieldBase = function FieldBase(props) {
|
|
|
113
97
|
return /*#__PURE__*/React.createElement(FieldContainer, {
|
|
114
98
|
label: label,
|
|
115
99
|
layout: layout,
|
|
116
|
-
error: error
|
|
100
|
+
error: error,
|
|
101
|
+
wrapper: wrapper
|
|
117
102
|
}, /*#__PURE__*/React.createElement(Controller, {
|
|
118
103
|
control: control,
|
|
119
104
|
name: name,
|
|
@@ -139,7 +124,8 @@ export var FieldBase = function FieldBase(props) {
|
|
|
139
124
|
return /*#__PURE__*/React.createElement(FieldContainer, {
|
|
140
125
|
label: label,
|
|
141
126
|
layout: layout,
|
|
142
|
-
error: error
|
|
127
|
+
error: error,
|
|
128
|
+
wrapper: wrapper
|
|
143
129
|
}, Component !== null && Component !== void 0 && Component.render ? /*#__PURE__*/React.createElement(Component, {
|
|
144
130
|
name: name,
|
|
145
131
|
ref: register,
|
|
@@ -202,6 +188,7 @@ function calculateField(children, field) {
|
|
|
202
188
|
var _FIELD_COMPONENTS$fie;
|
|
203
189
|
|
|
204
190
|
calculatedField.component = FIELD_COMPONENTS[field.type].component;
|
|
191
|
+
calculatedField.wrapper = FIELD_COMPONENTS[field.type].wrapper;
|
|
205
192
|
calculatedField.controlled = ((_FIELD_COMPONENTS$fie = FIELD_COMPONENTS[field.type]) === null || _FIELD_COMPONENTS$fie === void 0 ? void 0 : _FIELD_COMPONENTS$fie.controlled) || false;
|
|
206
193
|
} else {
|
|
207
194
|
var _FIELD_COMPONENTS$str2;
|
|
@@ -210,6 +197,7 @@ function calculateField(children, field) {
|
|
|
210
197
|
calculatedField.controlled = ((_FIELD_COMPONENTS$str2 = FIELD_COMPONENTS.string) === null || _FIELD_COMPONENTS$str2 === void 0 ? void 0 : _FIELD_COMPONENTS$str2.controlled) || false;
|
|
211
198
|
}
|
|
212
199
|
|
|
200
|
+
calculatedField.wrapper = calculatedField.wrapper || 'label';
|
|
213
201
|
return calculatedField;
|
|
214
202
|
}
|
|
215
203
|
|
package/esm/Fieldset/index.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import React, { useContext, useMemo } from 'react';
|
|
2
2
|
import Grid from '@material-ui/core/Grid';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import CoreFieldset from '@digigov/react-core/Fieldset';
|
|
4
|
+
import FieldsetLegend from '@digigov/react-core/FieldsetLegend';
|
|
5
|
+
import Hint from '@digigov/react-core/Hint';
|
|
5
6
|
import { FormContext } from '@digigov/form';
|
|
6
7
|
import Field from '@digigov/form/Field';
|
|
7
8
|
import NormalText from '@digigov/ui/typography/NormalText';
|
|
8
9
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
9
10
|
export var FieldsetLabel = function FieldsetLabel(_ref) {
|
|
10
11
|
var children = _ref.children;
|
|
11
|
-
return /*#__PURE__*/React.createElement(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
12
|
+
return /*#__PURE__*/React.createElement(FieldsetLegend, {
|
|
13
|
+
heading: true,
|
|
14
|
+
size: "xl"
|
|
15
|
+
}, children);
|
|
15
16
|
};
|
|
16
17
|
export var FieldsetCaption = function FieldsetCaption(_ref2) {
|
|
17
18
|
var children = _ref2.children;
|
|
18
|
-
return /*#__PURE__*/React.createElement(
|
|
19
|
-
item: true,
|
|
20
|
-
xs: 12
|
|
21
|
-
}, /*#__PURE__*/React.createElement(Caption, null, children));
|
|
19
|
+
return /*#__PURE__*/React.createElement(Hint, null, children);
|
|
22
20
|
};
|
|
23
21
|
export var FieldsetBody = function FieldsetBody(_ref3) {
|
|
24
22
|
var children = _ref3.children;
|
|
@@ -74,9 +72,6 @@ export var Fieldset = function Fieldset(_ref6) {
|
|
|
74
72
|
});
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
return /*#__PURE__*/React.createElement(
|
|
78
|
-
container: true,
|
|
79
|
-
spacing: 1
|
|
80
|
-
}, children);
|
|
75
|
+
return /*#__PURE__*/React.createElement(CoreFieldset, null, children);
|
|
81
76
|
};
|
|
82
77
|
export default Fieldset;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
6
|
import React, { createContext, useContext, useState } from 'react';
|
|
5
7
|
import { QuestionsContext } from '@digigov/form/Questions/';
|
|
6
8
|
import PageTitle, { PageTitleHeading } from '@digigov/ui/app/PageTitle';
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Digigov v0.4.
|
|
1
|
+
/** @license Digigov v0.4.9
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
7
|
import _extends from "@babel/runtime/helpers/extends";
|
|
8
8
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
11
|
import React, { createContext, useCallback, useRef } from 'react';
|
|
10
12
|
import { useForm } from 'react-hook-form';
|
|
11
13
|
import { yupResolver } from '@digigov/form/utils';
|
package/esm/index.mdx
CHANGED
|
@@ -3,10 +3,7 @@ title: Form
|
|
|
3
3
|
parent: docs/ui/components
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { useState, useEffect } from 'react';
|
|
7
6
|
import FormBuilder from '@digigov/form/';
|
|
8
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
9
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
10
7
|
|
|
11
8
|
export const fields = [
|
|
12
9
|
{
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
8
|
-
import Label from '@digigov/form/inputs/Label';
|
|
3
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
4
|
+
import CoreCheckboxes from '@digigov/react-core/Checkbox';
|
|
5
|
+
import CheckboxItem from '@digigov/react-core/CheckboxItem';
|
|
6
|
+
import Hint from '@digigov/react-core/Hint';
|
|
9
7
|
|
|
10
8
|
var Checkboxes = function Checkboxes(_ref) {
|
|
11
9
|
var name = _ref.name,
|
|
@@ -22,8 +20,12 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
22
20
|
var newValue;
|
|
23
21
|
|
|
24
22
|
if (evt.currentTarget.checked) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore
|
|
25
25
|
newValue = value.concat([optionValue]);
|
|
26
26
|
} else {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore
|
|
27
29
|
newValue = value.filter(function (val) {
|
|
28
30
|
return val !== optionValue;
|
|
29
31
|
});
|
|
@@ -33,56 +35,22 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
33
35
|
};
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
var _useTranslation = useTranslation(),
|
|
39
|
+
t = _useTranslation.t;
|
|
40
|
+
|
|
41
|
+
return /*#__PURE__*/React.createElement(CoreCheckboxes, {
|
|
38
42
|
className: className
|
|
39
43
|
}, options.map(function (option, key) {
|
|
40
|
-
return /*#__PURE__*/React.createElement(
|
|
44
|
+
return /*#__PURE__*/React.createElement(CheckboxItem, _extends({
|
|
45
|
+
name: name,
|
|
41
46
|
disabled: disabled,
|
|
42
|
-
key: key
|
|
47
|
+
key: key // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
,
|
|
43
50
|
checked: value.includes(option.value),
|
|
44
|
-
onChange: handleChange
|
|
45
|
-
}, option));
|
|
51
|
+
onChange: handleChange(option.value)
|
|
52
|
+
}, option), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(option.label.secondary)));
|
|
46
53
|
}));
|
|
47
54
|
};
|
|
48
55
|
|
|
49
|
-
var useCheckboxStyles = makeStyles(function (theme) {
|
|
50
|
-
return {
|
|
51
|
-
formControlLabelActive: {
|
|
52
|
-
backgroundColor: theme.palette.grey['200'],
|
|
53
|
-
border: "2px solid ".concat(theme.palette.primary.main)
|
|
54
|
-
},
|
|
55
|
-
formControlLabel: {
|
|
56
|
-
fontWeight: 'bolder',
|
|
57
|
-
padding: theme.spacing(0.5),
|
|
58
|
-
margin: theme.spacing(0.5, 0)
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
var Checkbox = function Checkbox(_ref2) {
|
|
64
|
-
var className = _ref2.className,
|
|
65
|
-
checked = _ref2.checked,
|
|
66
|
-
value = _ref2.value,
|
|
67
|
-
label = _ref2.label,
|
|
68
|
-
onChange = _ref2.onChange,
|
|
69
|
-
disabled = _ref2.disabled;
|
|
70
|
-
var classes = useCheckboxStyles();
|
|
71
|
-
return /*#__PURE__*/React.createElement(FormControlLabel, {
|
|
72
|
-
key: value,
|
|
73
|
-
className: clsx(classes.formControlLabel, checked && classes.formControlLabelActive, className),
|
|
74
|
-
control: /*#__PURE__*/React.createElement(MuiCheckbox, {
|
|
75
|
-
checked: checked,
|
|
76
|
-
disabled: disabled,
|
|
77
|
-
color: "primary",
|
|
78
|
-
onChange: onChange(value),
|
|
79
|
-
name: value
|
|
80
|
-
}),
|
|
81
|
-
label: /*#__PURE__*/React.createElement(Label, {
|
|
82
|
-
label: label,
|
|
83
|
-
value: value
|
|
84
|
-
})
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
|
|
88
56
|
export default Checkboxes;
|