@ukhomeoffice/cop-react-form-renderer 1.0.0-gamma → 1.0.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.
- package/dist/components/FormPage/FormPage.test.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +1 -1
- package/dist/components/PageActions/ActionButton.test.js +1 -1
- package/dist/components/PageActions/PageActions.test.js +3 -3
- package/dist/components/index.js +8 -0
- package/dist/models/ComponentTypes.js +3 -1
- package/dist/models/PageAction.js +9 -7
- package/dist/utils/Component/getComponent.js +8 -0
- package/dist/utils/Component/getComponent.test.js +32 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/package.json +9 -8
- package/dist/index.test.js +0 -18
|
@@ -140,7 +140,7 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
140
140
|
// Check to see whether the action is able to proceed, which in
|
|
141
141
|
// in the case of a submission will validate the fields in the page.
|
|
142
142
|
if (_helpers.default.canActionProceed(action, formState.page, onError)) {
|
|
143
|
-
if (action.type ===
|
|
143
|
+
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
144
144
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
145
145
|
} else {
|
|
146
146
|
// Submit.
|
|
@@ -59,7 +59,7 @@ describe('components', function () {
|
|
|
59
59
|
while (1) {
|
|
60
60
|
switch (_context2.prev = _context2.next) {
|
|
61
61
|
case 0:
|
|
62
|
-
ACTION =
|
|
62
|
+
ACTION = _models.PageAction.TYPES.SUBMIT;
|
|
63
63
|
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_ActionButton.default, {
|
|
64
64
|
action: ACTION,
|
|
65
65
|
onAction: ON_ACTION
|
|
@@ -55,7 +55,7 @@ describe('components', function () {
|
|
|
55
55
|
while (1) {
|
|
56
56
|
switch (_context2.prev = _context2.next) {
|
|
57
57
|
case 0:
|
|
58
|
-
ACTIONS = [
|
|
58
|
+
ACTIONS = [_models.PageAction.TYPES.SUBMIT];
|
|
59
59
|
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
|
|
60
60
|
actions: ACTIONS,
|
|
61
61
|
onAction: ON_ACTION
|
|
@@ -120,11 +120,11 @@ describe('components', function () {
|
|
|
120
120
|
switch (_context4.prev = _context4.next) {
|
|
121
121
|
case 0:
|
|
122
122
|
NAVIGATE = {
|
|
123
|
-
type:
|
|
123
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
124
124
|
url: '/alpha',
|
|
125
125
|
label: 'Alpha'
|
|
126
126
|
};
|
|
127
|
-
ACTIONS = [NAVIGATE,
|
|
127
|
+
ACTIONS = [NAVIGATE, _models.PageAction.TYPES.SUBMIT];
|
|
128
128
|
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
|
|
129
129
|
actions: ACTIONS,
|
|
130
130
|
onAction: ON_ACTION
|
package/dist/components/index.js
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "FormRenderer", {
|
|
|
27
27
|
return _FormRenderer.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "SummaryList", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _SummaryList.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
|
|
31
37
|
var _CheckYourAnswers = _interopRequireDefault(require("./CheckYourAnswers"));
|
|
32
38
|
|
|
@@ -36,4 +42,6 @@ var _FormPage = _interopRequireDefault(require("./FormPage"));
|
|
|
36
42
|
|
|
37
43
|
var _FormRenderer = _interopRequireDefault(require("./FormRenderer"));
|
|
38
44
|
|
|
45
|
+
var _SummaryList = _interopRequireDefault(require("./SummaryList"));
|
|
46
|
+
|
|
39
47
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -12,6 +12,7 @@ var TYPE_INSET_TEXT = 'inset-text';
|
|
|
12
12
|
var TYPE_PHONE_NUMBER = 'phone-number';
|
|
13
13
|
var TYPE_RADIOS = 'radios';
|
|
14
14
|
var TYPE_TEXT = 'text';
|
|
15
|
+
var TYPE_TEXT_AREA = 'textarea';
|
|
15
16
|
var ComponentTypes = {
|
|
16
17
|
AUTOCOMPLETE: TYPE_AUTOCOMPLETE,
|
|
17
18
|
EMAIL: TYPE_EMAIL,
|
|
@@ -20,7 +21,8 @@ var ComponentTypes = {
|
|
|
20
21
|
INSET_TEXT: TYPE_INSET_TEXT,
|
|
21
22
|
PHONE_NUMBER: TYPE_PHONE_NUMBER,
|
|
22
23
|
RADIOS: TYPE_RADIOS,
|
|
23
|
-
TEXT: TYPE_TEXT
|
|
24
|
+
TEXT: TYPE_TEXT,
|
|
25
|
+
TEXT_AREA: TYPE_TEXT_AREA
|
|
24
26
|
};
|
|
25
27
|
var _default = ComponentTypes;
|
|
26
28
|
exports.default = _default;
|
|
@@ -9,19 +9,18 @@ var _DefaultPageActions;
|
|
|
9
9
|
|
|
10
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var TYPE_NAVIGATE = 'navigate';
|
|
13
13
|
var TYPE_SAVE_AND_CONTINUE = 'saveAndContinue';
|
|
14
14
|
var TYPE_SAVE_AND_RETURN = 'saveAndReturn';
|
|
15
|
+
var TYPE_SUBMIT = 'submit';
|
|
15
16
|
var PageActionTypes = {
|
|
16
|
-
|
|
17
|
+
NAVIGATE: TYPE_NAVIGATE,
|
|
17
18
|
SAVE_AND_CONTINUE: TYPE_SAVE_AND_CONTINUE,
|
|
18
|
-
SAVE_AND_RETURN: TYPE_SAVE_AND_RETURN
|
|
19
|
+
SAVE_AND_RETURN: TYPE_SAVE_AND_RETURN,
|
|
20
|
+
SUBMIT: TYPE_SUBMIT
|
|
19
21
|
};
|
|
20
22
|
exports.PageActionTypes = PageActionTypes;
|
|
21
|
-
var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPageActions,
|
|
22
|
-
type: TYPE_SUBMIT,
|
|
23
|
-
validate: true
|
|
24
|
-
}), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_CONTINUE, {
|
|
23
|
+
var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPageActions, TYPE_NAVIGATE, undefined), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_CONTINUE, {
|
|
25
24
|
type: TYPE_SAVE_AND_CONTINUE,
|
|
26
25
|
validate: true,
|
|
27
26
|
label: 'Save and continue'
|
|
@@ -30,6 +29,9 @@ var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPage
|
|
|
30
29
|
validate: false,
|
|
31
30
|
label: 'Save and return later',
|
|
32
31
|
classModifiers: 'secondary'
|
|
32
|
+
}), _defineProperty(_DefaultPageActions, TYPE_SUBMIT, {
|
|
33
|
+
type: TYPE_SUBMIT,
|
|
34
|
+
validate: true
|
|
33
35
|
}), _DefaultPageActions);
|
|
34
36
|
exports.DefaultPageActions = DefaultPageActions;
|
|
35
37
|
var PageAction = {
|
|
@@ -67,6 +67,11 @@ var getRadios = function getRadios(config) {
|
|
|
67
67
|
}));
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
var getTextArea = function getTextArea(config) {
|
|
71
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
72
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextArea, attrs);
|
|
73
|
+
};
|
|
74
|
+
|
|
70
75
|
var getTextInput = function getTextInput(config) {
|
|
71
76
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
72
77
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, attrs);
|
|
@@ -88,6 +93,9 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
88
93
|
case _models.ComponentTypes.PHONE_NUMBER:
|
|
89
94
|
return getTextInput(config);
|
|
90
95
|
|
|
96
|
+
case _models.ComponentTypes.TEXT_AREA:
|
|
97
|
+
return getTextArea(config);
|
|
98
|
+
|
|
91
99
|
case _models.ComponentTypes.AUTOCOMPLETE:
|
|
92
100
|
return getAutocomplete(config);
|
|
93
101
|
|
|
@@ -325,5 +325,37 @@ describe('utils', function () {
|
|
|
325
325
|
});
|
|
326
326
|
});
|
|
327
327
|
});
|
|
328
|
+
it('should return an appropriately rendered textarea component', function () {
|
|
329
|
+
var ID = 'test-id';
|
|
330
|
+
var FIELD_ID = 'field-id';
|
|
331
|
+
var LABEL = 'label';
|
|
332
|
+
var ROWS = 13;
|
|
333
|
+
var COMPONENT = {
|
|
334
|
+
type: _models.ComponentTypes.TEXT_AREA,
|
|
335
|
+
id: ID,
|
|
336
|
+
fieldId: FIELD_ID,
|
|
337
|
+
label: LABEL,
|
|
338
|
+
rows: ROWS,
|
|
339
|
+
'data-testid': ID
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
var _render10 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
343
|
+
container = _render10.container;
|
|
344
|
+
|
|
345
|
+
var _getAllByTestId9 = (0, _react.getAllByTestId)(container, ID),
|
|
346
|
+
_getAllByTestId10 = _slicedToArray(_getAllByTestId9, 2),
|
|
347
|
+
formGroup = _getAllByTestId10[0],
|
|
348
|
+
textarea = _getAllByTestId10[1];
|
|
349
|
+
|
|
350
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
351
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
352
|
+
var label = formGroup.childNodes[0];
|
|
353
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
354
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
355
|
+
expect(textarea.tagName).toEqual('TEXTAREA');
|
|
356
|
+
expect(textarea.classList).toContain('govuk-textarea');
|
|
357
|
+
expect(textarea.getAttribute('rows')).toEqual("".concat(ROWS));
|
|
358
|
+
expect(textarea.id).toEqual(ID);
|
|
359
|
+
});
|
|
328
360
|
});
|
|
329
361
|
});
|
|
@@ -8,7 +8,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
|
|
10
10
|
// Local imports
|
|
11
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT];
|
|
11
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA];
|
|
12
12
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
13
13
|
|
|
14
14
|
var isEditable = function isEditable(options) {
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
7
7
|
"test": "react-scripts test",
|
|
8
|
+
"test:coverage": "yarn test --coverage --watchAll=false",
|
|
8
9
|
"lint": "eslint --ext .js,.jsx src",
|
|
9
|
-
"storybook:start": "start-storybook --docs --no-manager-cache -p 6007",
|
|
10
|
+
"storybook:start": "start-storybook --docs -s src/assets --no-manager-cache -p 6007",
|
|
10
11
|
"storybook:build": "build-storybook --docs -s src/assets",
|
|
11
12
|
"storybook:deploy": "yarn deploy-storybook",
|
|
12
13
|
"storybook": "yarn storybook:start",
|
|
13
14
|
"deploy-storybook": "storybook-to-ghpages -e storybook-static",
|
|
14
15
|
"compile": "yarn clean && cross-env NODE_ENV=production babel src --out-dir dist --copy-files && yarn post-compile",
|
|
15
|
-
"post-compile": "rimraf dist/**/*.test.* dist/**/*.stories.* dist/json dist/assets"
|
|
16
|
+
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/json dist/assets"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@ukhomeoffice/cop-react-components": "^0.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^0.7.0",
|
|
19
20
|
"axios": "^0.21.1",
|
|
20
21
|
"govuk-frontend": "^3.13.0",
|
|
21
22
|
"web-vitals": "^1.0.1"
|
|
@@ -44,14 +45,14 @@
|
|
|
44
45
|
"cross-env": "^7.0.3",
|
|
45
46
|
"html-react-parser": "^0.10.5",
|
|
46
47
|
"node-sass": "^6.0.1",
|
|
47
|
-
"react": "^
|
|
48
|
-
"react-dom": "^
|
|
48
|
+
"react": "^16.13.1",
|
|
49
|
+
"react-dom": "^16.13.1",
|
|
49
50
|
"react-scripts": "4.0.3",
|
|
50
51
|
"storybook-addon-mock": "^2.0.1"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"react": "^
|
|
54
|
-
"react-dom": "^
|
|
54
|
+
"react": "^16.13.1",
|
|
55
|
+
"react-dom": "^16.13.1",
|
|
55
56
|
"react-scripts": "4.0.3"
|
|
56
57
|
},
|
|
57
58
|
"optionalDependencies": {
|
package/dist/index.test.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
var _ = _interopRequireWildcard(require("."));
|
|
6
|
-
|
|
7
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
|
|
11
|
-
// Local imports
|
|
12
|
-
it('should have exported everything appropriately', function () {
|
|
13
|
-
expect(_.default).toBeDefined();
|
|
14
|
-
expect(_.FormTypes).toBeDefined();
|
|
15
|
-
expect(_.HubFormats).toBeDefined();
|
|
16
|
-
expect(_.intercepts).toBeDefined();
|
|
17
|
-
expect(_.Utils).toBeDefined();
|
|
18
|
-
});
|