@ukhomeoffice/formio-gds-template 2.0.2 → 3.0.0-alpha
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/LICENCE.md +21 -0
- package/eslint.config.mjs +58 -0
- package/lib/components/datamap/GDSDataMap.d.ts +4 -14
- package/lib/components/datamap/GDSDataMap.js +9 -29
- package/lib/components/datetime/GDSDatetimeComponent.d.ts +30 -22
- package/lib/components/datetime/GDSDatetimeComponent.js +148 -178
- package/lib/components/index.js +4 -4
- package/lib/components/selectboxes/GDSCheckBoxes.d.ts +4 -2
- package/lib/components/selectboxes/GDSCheckBoxes.js +7 -33
- package/lib/components/time/GDSTimeComponent.d.ts +12 -10
- package/lib/components/time/GDSTimeComponent.js +59 -84
- package/lib/components/util/TimeHelper.d.ts +5 -4
- package/lib/components/util/TimeHelper.js +13 -16
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/templates/gds/button/index.js +1 -1
- package/lib/templates/gds/checkbox/index.js +1 -1
- package/lib/templates/gds/columns/index.js +1 -1
- package/lib/templates/gds/component/index.js +1 -1
- package/lib/templates/gds/container/index.js +1 -1
- package/lib/templates/gds/datagrid/index.js +1 -1
- package/lib/templates/gds/datamap/index.js +1 -1
- package/lib/templates/gds/datetime/index.js +1 -1
- package/lib/templates/gds/day/index.js +1 -1
- package/lib/templates/gds/editgrid/index.js +1 -1
- package/lib/templates/gds/field/index.js +1 -1
- package/lib/templates/gds/fieldset/index.js +1 -1
- package/lib/templates/gds/file/index.js +1 -1
- package/lib/templates/gds/iconClass.d.ts +1 -1
- package/lib/templates/gds/iconClass.js +3 -3
- package/lib/templates/gds/index.d.ts +2 -2
- package/lib/templates/gds/index.js +72 -64
- package/lib/templates/gds/input/index.js +1 -1
- package/lib/templates/gds/label/index.js +1 -1
- package/lib/templates/gds/message/index.js +1 -1
- package/lib/templates/gds/panel/index.js +1 -1
- package/lib/templates/gds/radio/index.js +1 -1
- package/lib/templates/gds/select/index.js +1 -1
- package/lib/templates/gds/selectOption/index.js +1 -1
- package/lib/templates/gds/selectboxes/index.js +1 -1
- package/lib/templates/gds/survey/index.js +1 -1
- package/lib/templates/gds/tab/index.js +1 -1
- package/lib/templates/gds/table/index.js +1 -1
- package/lib/templates/gds/template.css +16 -0
- package/lib/templates/gds/template.css.map +1 -1
- package/lib/templates/gds/time/index.js +1 -1
- package/lib/templates/gds/warning/index.js +1 -1
- package/lib/templates/gds/wizard/index.js +1 -1
- package/lib/templates/gds/wizardHeader/index.js +1 -1
- package/lib/templates/gds/wizardNav/index.js +1 -1
- package/lib/templates/index.d.ts +2 -2
- package/lib/templates/index.js +1 -1
- package/lib/types.d.ts +36 -0
- package/lib/types.js +2 -0
- package/package.json +13 -7
- package/src/components/datamap/GDSDataMap.ts +5 -14
- package/src/components/datetime/GDSDatetimeComponent.ts +109 -91
- package/src/components/selectboxes/GDSCheckBoxes.ts +7 -8
- package/src/components/time/GDSTimeComponent.ts +37 -27
- package/src/components/util/TimeHelper.ts +6 -5
- package/src/css.d.ts +4 -0
- package/src/templates/gds/iconClass.ts +1 -1
- package/src/templates/gds/index.ts +43 -33
- package/src/templates/gds/template.scss +30 -1
- package/src/types.ts +55 -0
- package/tsconfig.json +6 -3
- package/webpack.config.js +1 -1
- package/tslint.json +0 -22
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -112,6 +112,18 @@
|
|
|
112
112
|
.govuk-details {
|
|
113
113
|
margin-bottom: 0 !important;
|
|
114
114
|
}
|
|
115
|
+
.govuk-details__summary {
|
|
116
|
+
font-weight: 400 !important;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.formio-component-datagrid > [ref=messageContainer],
|
|
120
|
+
.formio-component-editgrid > [ref=messageContainer],
|
|
121
|
+
.formio-component-datamap > [ref=messageContainer],
|
|
122
|
+
.formio-component-panel > [ref=messageContainer],
|
|
123
|
+
.formio-component-container > [ref=messageContainer],
|
|
124
|
+
.formio-component-fieldset > [ref=messageContainer] {
|
|
125
|
+
display: none;
|
|
126
|
+
}
|
|
115
127
|
|
|
116
128
|
.small-button {
|
|
117
129
|
padding: 0.25rem 0.5rem;
|
|
@@ -168,4 +180,8 @@
|
|
|
168
180
|
height: auto;
|
|
169
181
|
}
|
|
170
182
|
|
|
183
|
+
.govuk-form-group--error .govuk-form-group {
|
|
184
|
+
overflow: visible;
|
|
185
|
+
}
|
|
186
|
+
|
|
171
187
|
/*# sourceMappingURL=template.css.map */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sourceRoot":"","sources":["../../../src/templates/gds/template.scss","../../../node_modules/govuk-frontend/dist/govuk/vendor/_sass-mq.scss"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKE;EACE;EACA;EACA;;AAGF;AAAA;EAEE;EACA;EACA;;;AAKJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;IACE;;EAEF;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAGF;IACE;;EAGF;IACE;IACA;;EAGF;IACE;;EAEF;IACE;;;AAKJ;EACE;;;
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../../../src/templates/gds/template.scss","../../../node_modules/govuk-frontend/dist/govuk/vendor/_sass-mq.scss"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKE;EACE;EACA;EACA;;AAGF;AAAA;EAEE;EACA;EACA;;;AAKJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;IACE;;EAEF;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAGF;IACE;;EAGF;IACE;IACA;;EAGF;IACE;;EAEF;IACE;;;AAKJ;EACE;;AAGA;EACE;;;AAaF;AAAA;AAAA;AAAA;AAAA;AAAA;EACE;;;AAIJ;EACE;EACA;EACA;;;AAIF;EACE;;AAEA;EACE;EAGA;;;AAKJ;EACE;EACA;;;AAGF;EACE;;;ACkGM;ED7FJ;IACE;;;;AAMJ;EADF;IAEI;IACA;IACA;IACA;IACA;;;;AAIJ;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE;;;AAQA;EACE","file":"template.css"}
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const form_ejs_1 = __importDefault(require("./form.ejs"));
|
|
7
7
|
exports.default = { form: form_ejs_1.default };
|
package/lib/templates/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
gds: {
|
|
3
|
-
transform(type:
|
|
3
|
+
transform(type: string, text: string): any;
|
|
4
4
|
defaultIconset: string;
|
|
5
|
-
iconClass: (iconset:
|
|
5
|
+
iconClass: (iconset: string, name: string, spinning: boolean) => string;
|
|
6
6
|
cssClasses: {
|
|
7
7
|
'has-error': string;
|
|
8
8
|
'formio-tab-link-container-active': string;
|
package/lib/templates/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const gds_1 = __importDefault(require("./gds"));
|
|
7
7
|
exports.default = {
|
|
8
8
|
gds: gds_1.default,
|
|
9
9
|
};
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DayComponent, DateTimeComponent, TimeComponent as CoreTimeComponent, SelectBoxesComponent, DataMapComponent } from '@formio/core';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal interface for DOM input-like elements.
|
|
4
|
+
* Used as the typed parameter in TimeHelper methods so callers can pass any
|
|
5
|
+
* object that has a writable `.value: string` (e.g. HTMLInputElement).
|
|
6
|
+
*/
|
|
7
|
+
export interface InputElementLike {
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The shape of a single GDS date/time field definition.
|
|
12
|
+
* Extends the base formio field definition with an optional placeholder.
|
|
13
|
+
*/
|
|
14
|
+
export type GDSFieldDefinition = {
|
|
15
|
+
type?: string;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Component schema for GDSDatetimeComponent.
|
|
21
|
+
*
|
|
22
|
+
* GDSDatetimeComponent extends the formio Day component but adds hour/minute
|
|
23
|
+
* fields (from a datetime hybrid) and uses datePicker / defaultDate from
|
|
24
|
+
* DateTimeComponent. This type captures the full shape of `this.component`
|
|
25
|
+
* as used in GDSDatetimeComponent.
|
|
26
|
+
*/
|
|
27
|
+
export type GDSDatetimeComponentSchema = Omit<DayComponent, 'suffix' | 'fields'> & Pick<DateTimeComponent, 'datePicker' | 'defaultDate'> & {
|
|
28
|
+
/** suffix is set to null in init() — null must be allowed */
|
|
29
|
+
suffix?: string | null;
|
|
30
|
+
/** fields extended with GDS hour/minute additions */
|
|
31
|
+
fields: DayComponent['fields'] & {
|
|
32
|
+
hour?: GDSFieldDefinition;
|
|
33
|
+
minute?: GDSFieldDefinition;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type { CoreTimeComponent, SelectBoxesComponent, DataMapComponent };
|
package/lib/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/formio-gds-template",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Gov UK design system formio templates",
|
|
3
|
+
"version": "3.0.0-alpha",
|
|
4
|
+
"description": "Gov UK design system formio templates — upgraded to @formio/js@5.x",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"main": "lib/index.js",
|
|
9
|
+
"types": "lib/index.d.ts",
|
|
9
10
|
"scripts": {
|
|
11
|
+
"prepack": "npm run build",
|
|
10
12
|
"test:coverage": "nyc --reporter=text mocha --reporter spec './{,!(node_modules)/**/}*.spec.js'",
|
|
11
13
|
"test": "mocha --require ts-node/register --reporter spec './{,!(node_modules)/**/}*.spec.ts'",
|
|
12
14
|
"build-sass": "sass src/templates/gds/template.scss lib/templates/gds/template.css",
|
|
@@ -15,8 +17,8 @@
|
|
|
15
17
|
"watch": "concurrently \"npm run watch-ts\" \"npm run watch-sass\"",
|
|
16
18
|
"build": "tsc && gulp templates && npm run build-sass && webpack",
|
|
17
19
|
"tag": "VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]');git add -A; git commit -nm \"Build $Version\";git push origin master;git tag v$VERSION;git push origin --tags;",
|
|
18
|
-
"lint": "
|
|
19
|
-
"lint:fix": "
|
|
20
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
21
|
+
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
|
20
22
|
"prepublish": "npm run build"
|
|
21
23
|
},
|
|
22
24
|
"pre-commit": [
|
|
@@ -40,13 +42,15 @@
|
|
|
40
42
|
},
|
|
41
43
|
"homepage": "https://github.com/UKHomeOffice/formio-gds-template#readme",
|
|
42
44
|
"peerDependencies": {
|
|
43
|
-
"
|
|
45
|
+
"@formio/core": "^2.0.0",
|
|
46
|
+
"@formio/js": "^5.0.0",
|
|
44
47
|
"govuk-frontend": "^5.0.0"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"lodash": "4.17.21"
|
|
48
51
|
},
|
|
49
52
|
"devDependencies": {
|
|
53
|
+
"@formio/core": "^2.0.0",
|
|
50
54
|
"@types/chai": "^4.3.16",
|
|
51
55
|
"@types/ejs": "^3.1.5",
|
|
52
56
|
"@types/lodash": "^4.17.5",
|
|
@@ -58,7 +62,7 @@
|
|
|
58
62
|
"chai": "^5.1.1",
|
|
59
63
|
"concurrently": "^8.2.2",
|
|
60
64
|
"css-loader": "^7.1.2",
|
|
61
|
-
"
|
|
65
|
+
"@formio/js": "^5.0.0",
|
|
62
66
|
"govuk-frontend": "^5.4.0",
|
|
63
67
|
"gulp": "^4.0.2",
|
|
64
68
|
"gulp-insert": "^0.5.0",
|
|
@@ -74,7 +78,9 @@
|
|
|
74
78
|
"style-loader": "^4.0.0",
|
|
75
79
|
"ts-node": "^10.9.2",
|
|
76
80
|
"ts-sinon": "^2.0.2",
|
|
77
|
-
"
|
|
81
|
+
"eslint": "^9.0.0",
|
|
82
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
78
84
|
"typed-scss-modules": "^8.0.1",
|
|
79
85
|
"typescript": "^5.5.2",
|
|
80
86
|
"webpack": "^5.92.1",
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import {Components} from '
|
|
1
|
+
import { Components } from '@formio/js';
|
|
2
|
+
import { DataMapComponent } from '../../types';
|
|
2
3
|
|
|
3
4
|
const Field = Components.components.field;
|
|
4
5
|
const DataMap = Components.components.datamap;
|
|
5
6
|
|
|
6
7
|
export default class GDSDataMap extends DataMap {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private getGroups: any;
|
|
10
|
-
private visibleColumns: any;
|
|
11
|
-
private hasAddButton: any;
|
|
12
|
-
private hasRemoveButtons: any;
|
|
13
|
-
private hasTopSubmit: any;
|
|
14
|
-
private hasBottomSubmit: any;
|
|
15
|
-
private hasExtraColumn: any;
|
|
16
|
-
private datagridKey: any;
|
|
17
|
-
private allowReorder: any;
|
|
18
|
-
private getColumns: any;
|
|
8
|
+
// Narrow the inherited `component: any` using the @formio/core DataMapComponent schema.
|
|
9
|
+
declare component: DataMapComponent;
|
|
19
10
|
|
|
20
|
-
public render() {
|
|
11
|
+
public render(): string {
|
|
21
12
|
const columns = this.getColumns();
|
|
22
13
|
return Field.prototype.render.call(this, this.renderTemplate('datamap', {
|
|
23
14
|
rows: this.getRows(),
|
|
@@ -1,34 +1,54 @@
|
|
|
1
|
-
import {Components} from '
|
|
2
|
-
import FormioUtils from '
|
|
1
|
+
import { Components } from '@formio/js';
|
|
2
|
+
import { Utils as FormioUtils } from '@formio/js';
|
|
3
3
|
import * as _ from 'lodash';
|
|
4
4
|
import moment from 'moment';
|
|
5
5
|
import TimeHelper from '../util/TimeHelper';
|
|
6
|
+
import { GDSDatetimeComponentSchema } from '../../types';
|
|
6
7
|
|
|
7
8
|
const Field = Components.components.field;
|
|
8
9
|
const Day = Components.components.day;
|
|
9
10
|
|
|
10
|
-
// @ts-ignore
|
|
11
11
|
export default class GDSDatetimeComponent extends Day {
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// Narrow the inherited `component: any` to the GDS datetime schema type.
|
|
14
|
+
// @formio/core provides the DayComponent + DateTimeComponent shapes;
|
|
15
|
+
// GDSDatetimeComponentSchema extends them with hour/minute fields.
|
|
16
|
+
declare component: GDSDatetimeComponentSchema;
|
|
17
|
+
|
|
18
|
+
// Narrow inherited base-class properties from `any` / `{}` to precise types.
|
|
19
|
+
// `declare` emits no runtime code — it only refines the type in this subclass.
|
|
20
|
+
declare refs: {
|
|
21
|
+
hour: HTMLInputElement;
|
|
22
|
+
minute: HTMLInputElement;
|
|
23
|
+
day: HTMLInputElement;
|
|
24
|
+
month: HTMLInputElement;
|
|
25
|
+
year: HTMLInputElement;
|
|
26
|
+
input: HTMLInputElement[];
|
|
27
|
+
};
|
|
28
|
+
declare dataValue: string;
|
|
29
|
+
declare data: Record<string, unknown>;
|
|
30
|
+
declare validators: string[];
|
|
31
|
+
declare shouldDisabled: boolean;
|
|
32
|
+
declare triggerChange: () => void;
|
|
33
|
+
|
|
34
|
+
get format(): string {
|
|
14
35
|
return 'DD-MM-YYYY';
|
|
15
36
|
}
|
|
16
|
-
|
|
17
|
-
get defaultValue() {
|
|
37
|
+
|
|
38
|
+
get defaultValue(): string {
|
|
18
39
|
let defaultValue = this.component.defaultValue;
|
|
19
40
|
if (!defaultValue && this.component.defaultDate) {
|
|
20
41
|
defaultValue = FormioUtils.getDateSetting(this.component.defaultDate);
|
|
21
42
|
defaultValue = defaultValue ? moment(defaultValue).format() : '';
|
|
22
43
|
}
|
|
23
|
-
return defaultValue;
|
|
44
|
+
return defaultValue ?? '';
|
|
24
45
|
}
|
|
25
46
|
|
|
26
|
-
|
|
27
|
-
get emptyValue() {
|
|
47
|
+
get emptyValue(): null {
|
|
28
48
|
return null;
|
|
29
49
|
}
|
|
30
50
|
|
|
31
|
-
get parts() {
|
|
51
|
+
get parts(): { day: string | null; month: string | null; year: string | null; hour: string | null; minute: string | null } {
|
|
32
52
|
return {
|
|
33
53
|
day: this.getFieldValue('day'),
|
|
34
54
|
month: this.getFieldValue('month'),
|
|
@@ -38,25 +58,18 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
38
58
|
};
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
private refs: any;
|
|
42
|
-
private component: any;
|
|
43
|
-
private updateValue: any;
|
|
44
|
-
private renderField: any;
|
|
45
|
-
private inputDefinition: any;
|
|
46
|
-
private checkComponentValidity: any;
|
|
47
|
-
private triggerChange: any;
|
|
48
|
-
|
|
49
61
|
private timeHelper: TimeHelper = new TimeHelper();
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
// element typed as `any` to match the base Day.attach(element: any) override signature
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
public attach(element: any): Promise<void> {
|
|
66
|
+
this.loadRefs(element, { hour: 'single', minute: 'single' });
|
|
67
|
+
|
|
53
68
|
this.addEventListener(this.refs.hour, 'input', () => {
|
|
54
69
|
this.timeHelper.checkAndValidateHour(this.refs.hour);
|
|
55
70
|
this.setPristine(false);
|
|
56
71
|
this.checkComponentValidity(this.data, true);
|
|
57
|
-
this.updateValue(null, {
|
|
58
|
-
modified: true,
|
|
59
|
-
});
|
|
72
|
+
this.updateValue(null, { modified: true });
|
|
60
73
|
this.triggerChange();
|
|
61
74
|
});
|
|
62
75
|
|
|
@@ -64,9 +77,7 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
64
77
|
this.timeHelper.checkAndValidateMinutes(this.refs.minute);
|
|
65
78
|
this.setPristine(false);
|
|
66
79
|
this.checkComponentValidity(this.data, true);
|
|
67
|
-
this.updateValue(null, {
|
|
68
|
-
modified: true,
|
|
69
|
-
});
|
|
80
|
+
this.updateValue(null, { modified: true });
|
|
70
81
|
this.triggerChange();
|
|
71
82
|
});
|
|
72
83
|
|
|
@@ -94,42 +105,46 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
94
105
|
this.timeHelper.validateDateInput(this.refs.month, 2);
|
|
95
106
|
});
|
|
96
107
|
|
|
97
|
-
|
|
98
108
|
return superAttach;
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
public init() {
|
|
111
|
+
public init(): void {
|
|
102
112
|
super.init();
|
|
103
|
-
|
|
113
|
+
// @formio/js@5.x: this.validators is not pre-populated by the base class; guard before filtering
|
|
114
|
+
this.validators = (this.validators || []).filter((v) => v !== 'day').concat(['date']);
|
|
104
115
|
|
|
105
|
-
this.component.maxDate = this.component.datePicker
|
|
106
|
-
this.component.minDate = this.component.datePicker
|
|
116
|
+
this.component.maxDate = this.component.datePicker?.maxDate ?? undefined;
|
|
117
|
+
this.component.minDate = this.component.datePicker?.minDate ?? undefined;
|
|
107
118
|
this.component.suffix = null;
|
|
108
119
|
|
|
109
|
-
this.component.fields.day.required = this.component.validate
|
|
110
|
-
this.component.fields.month.required = this.component.validate
|
|
111
|
-
this.component.fields.year.required = this.component.validate
|
|
120
|
+
this.component.fields.day.required = this.component.validate?.required;
|
|
121
|
+
this.component.fields.month.required = this.component.validate?.required;
|
|
122
|
+
this.component.fields.year.required = this.component.validate?.required;
|
|
112
123
|
this.component.fields.hour = {
|
|
113
|
-
type: 'number',
|
|
114
|
-
|
|
124
|
+
type: 'number',
|
|
125
|
+
placeholder: 'HH',
|
|
126
|
+
required: this.component.validate?.required,
|
|
115
127
|
};
|
|
116
128
|
this.component.fields.minute = {
|
|
117
|
-
type: 'number',
|
|
118
|
-
|
|
129
|
+
type: 'number',
|
|
130
|
+
placeholder: 'MM',
|
|
131
|
+
required: this.component.validate?.required,
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
135
|
+
// elements typed as `any` to match the base Day.setErrorClasses(elements: any, ...) override signature
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
public setErrorClasses(elements: any, dirty: any, hasError: any): void {
|
|
138
|
+
super.setErrorClasses([this.refs.hour, this.refs.minute, ...elements], dirty, hasError);
|
|
125
139
|
}
|
|
126
140
|
|
|
127
|
-
|
|
128
|
-
|
|
141
|
+
// elements typed as `any` to match the base Component.removeInputError(elements: any) signature
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
+
public removeInputError(elements: any): void {
|
|
129
144
|
super.removeInputError([this.refs.hour, this.refs.minute, ...elements]);
|
|
130
145
|
}
|
|
131
146
|
|
|
132
|
-
public render() {
|
|
147
|
+
public render(): string {
|
|
133
148
|
return Field.prototype.render.call(this, this.renderTemplate('datetime', {
|
|
134
149
|
component: this.component,
|
|
135
150
|
dataValue: this.dataValue,
|
|
@@ -143,8 +158,10 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
143
158
|
}));
|
|
144
159
|
}
|
|
145
160
|
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
// value typed as `any` to match the base Day.getDate(value: any): null | string signature
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
163
|
+
public getDate(value: any): string | null {
|
|
164
|
+
const defaults: Array<string | number | undefined> = [];
|
|
148
165
|
const [DAY, MONTH, YEAR, HOUR, MINUTE] = [0, 1, 2, 3, 4];
|
|
149
166
|
const defaultValue = value || this.component.defaultValue;
|
|
150
167
|
|
|
@@ -156,35 +173,37 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
156
173
|
defaults[YEAR] = defaultDate.format('YYYY');
|
|
157
174
|
defaults[HOUR] = defaultDate.format('HH');
|
|
158
175
|
defaults[MINUTE] = defaultDate.format('mm');
|
|
159
|
-
} catch
|
|
176
|
+
} catch {
|
|
160
177
|
// ignored
|
|
161
178
|
}
|
|
162
179
|
}
|
|
163
180
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
const day: number = this.processField('day', defaults, DAY);
|
|
182
|
+
const month: number = this.processField('month', defaults, MONTH);
|
|
183
|
+
const year: number = this.processField('year', defaults, YEAR);
|
|
184
|
+
const hour: number = this.processField('hour', defaults, HOUR);
|
|
185
|
+
const minute: number = this.processField('minute', defaults, MINUTE);
|
|
169
186
|
|
|
170
187
|
if (!day && !month && !year && (!hour && !minute)) {
|
|
171
188
|
return null;
|
|
172
189
|
}
|
|
173
190
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
const dayStr = day.toString().padStart(2, '0');
|
|
192
|
+
const monthStr = month.toString().padStart(2, '0');
|
|
193
|
+
const yearStr = year.toString().padStart(4, '0');
|
|
194
|
+
const hourStr = hour.toString().padStart(2, '0');
|
|
195
|
+
const minuteStr = minute.toString().padStart(2, '0');
|
|
179
196
|
|
|
180
|
-
const toMoment = moment(`${
|
|
197
|
+
const toMoment = moment(`${yearStr}-${monthStr}-${dayStr} ${hourStr}:${minuteStr}`, 'YYYY-MM-DD HH:mm');
|
|
181
198
|
return toMoment.format();
|
|
182
199
|
}
|
|
183
200
|
|
|
184
|
-
|
|
201
|
+
// name typed as `any` to match the base Day.getFieldValue(name: any): number signature
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
public getFieldValue(name: any): string | null {
|
|
185
204
|
if (this.dataValue && this.dataValue !== 'Invalid date') {
|
|
186
205
|
try {
|
|
187
|
-
let val = null;
|
|
206
|
+
let val: string | null = null;
|
|
188
207
|
const date = moment(this.dataValue, 'YYYY-MM-DD HH:mm');
|
|
189
208
|
|
|
190
209
|
switch (name) {
|
|
@@ -205,27 +224,27 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
205
224
|
break;
|
|
206
225
|
}
|
|
207
226
|
return val;
|
|
208
|
-
} catch
|
|
227
|
+
} catch {
|
|
209
228
|
return null;
|
|
210
229
|
}
|
|
211
230
|
}
|
|
212
231
|
return null;
|
|
213
232
|
}
|
|
214
233
|
|
|
215
|
-
public boolValue(value) {
|
|
234
|
+
public boolValue(value: unknown): boolean {
|
|
216
235
|
if (_.isBoolean(value)) {
|
|
217
236
|
return value;
|
|
218
|
-
}
|
|
219
|
-
else if (_.isString(value)) {
|
|
237
|
+
} else if (_.isString(value)) {
|
|
220
238
|
return (value.toLowerCase() === 'true');
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
239
|
+
} else {
|
|
223
240
|
return !!value;
|
|
224
241
|
}
|
|
225
242
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
243
|
+
|
|
244
|
+
// value typed as `any` to match the base Day.setValueAt(index: number, value: any) signature
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
246
|
+
public setValueAt(index: number, value: any): void {
|
|
247
|
+
// temporary solution to avoid input reset on invalid date.
|
|
229
248
|
if (!value || value === 'Invalid date') {
|
|
230
249
|
return;
|
|
231
250
|
}
|
|
@@ -243,51 +262,48 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
243
262
|
if (this.refs.hour) {
|
|
244
263
|
this.refs.hour.value = date.format('HH');
|
|
245
264
|
}
|
|
246
|
-
|
|
247
265
|
if (this.refs.minute) {
|
|
248
266
|
this.refs.minute.value = date.format('mm');
|
|
249
267
|
}
|
|
250
268
|
}
|
|
251
|
-
|
|
252
269
|
}
|
|
253
270
|
|
|
254
|
-
public getValueAt(index) {
|
|
255
|
-
//
|
|
271
|
+
public getValueAt(index: number): string | null {
|
|
272
|
+
// `date` is a public getter declared on DayComponent: get date(): string | null
|
|
256
273
|
const date = this.date;
|
|
257
274
|
if (date) {
|
|
258
275
|
this.refs.input[index].value = date;
|
|
259
276
|
return this.refs.input[index].value;
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
277
|
+
} else {
|
|
262
278
|
this.refs.input[index].value = '';
|
|
263
279
|
return null;
|
|
264
280
|
}
|
|
265
281
|
}
|
|
266
282
|
|
|
267
|
-
|
|
283
|
+
// value typed as `any` to match the base Component.normalizeValue(value: any): any signature
|
|
284
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
285
|
+
public normalizeValue(value: any): any {
|
|
268
286
|
return value;
|
|
269
287
|
}
|
|
270
288
|
|
|
271
|
-
|
|
272
|
-
|
|
289
|
+
// setting/value typed as `any` to match the base Day.validateRequired(setting: any, value: any) signature
|
|
290
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
|
+
public validateRequired(setting: any, value: any): boolean {
|
|
292
|
+
const { day, month, year, minute, hour } = this.parts;
|
|
273
293
|
|
|
274
|
-
if (this.component.validate
|
|
294
|
+
if (this.component.validate?.required && (!day || parseInt(day, 10) === 0)) {
|
|
275
295
|
return false;
|
|
276
296
|
}
|
|
277
|
-
|
|
278
|
-
if (this.component.validate.required && (!month || parseInt(month, 10) === 0)) {
|
|
297
|
+
if (this.component.validate?.required && (!month || parseInt(month, 10) === 0)) {
|
|
279
298
|
return false;
|
|
280
299
|
}
|
|
281
|
-
|
|
282
|
-
if (this.component.validate.required && (!year || parseInt(year, 10) === 0)) {
|
|
300
|
+
if (this.component.validate?.required && (!year || parseInt(year, 10) === 0)) {
|
|
283
301
|
return false;
|
|
284
302
|
}
|
|
285
|
-
|
|
286
|
-
if (this.component.validate.required && ((this.refs.minute && this.refs.minute.value === '') || !minute)) {
|
|
303
|
+
if (this.component.validate?.required && (this.refs.minute.value === '' || !minute)) {
|
|
287
304
|
return false;
|
|
288
305
|
}
|
|
289
|
-
|
|
290
|
-
if (this.component.validate.required && ((this.refs.hour && this.refs.hour.value === '') || !hour)) {
|
|
306
|
+
if (this.component.validate?.required && (this.refs.hour.value === '' || !hour)) {
|
|
291
307
|
return false;
|
|
292
308
|
}
|
|
293
309
|
|
|
@@ -297,13 +313,15 @@ export default class GDSDatetimeComponent extends Day {
|
|
|
297
313
|
return !this.isEmpty(value);
|
|
298
314
|
}
|
|
299
315
|
|
|
300
|
-
private processField(field: string, defaults:
|
|
301
|
-
|
|
316
|
+
private processField(field: string, defaults: Array<string | number | undefined>, fieldIndex: number): number {
|
|
317
|
+
const refKey = field as keyof typeof this.refs;
|
|
318
|
+
const ref = this.refs[refKey];
|
|
319
|
+
const inputRef = ref instanceof HTMLInputElement ? ref : undefined;
|
|
320
|
+
let fieldValue: number | undefined = inputRef ? parseInt(inputRef.value, 10) : undefined;
|
|
302
321
|
if (fieldValue === undefined || _.isNaN(fieldValue)) {
|
|
303
|
-
fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? defaults[fieldIndex] : 0;
|
|
322
|
+
fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? Number(defaults[fieldIndex]) : 0;
|
|
304
323
|
}
|
|
305
324
|
return fieldValue;
|
|
306
|
-
|
|
307
325
|
}
|
|
308
326
|
|
|
309
327
|
}
|