@ukhomeoffice/formio-gds-template 2.0.1 → 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/README.md +3 -1
- 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 +172 -176
- package/lib/components/index.js +7 -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 +62 -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 +5 -2
- package/lib/templates/gds/button/index.js +4 -1
- package/lib/templates/gds/checkbox/index.js +4 -1
- package/lib/templates/gds/columns/index.js +4 -1
- package/lib/templates/gds/component/index.js +4 -1
- package/lib/templates/gds/container/index.js +4 -1
- package/lib/templates/gds/datagrid/form.ejs.js +1 -1
- package/lib/templates/gds/datagrid/index.js +4 -1
- package/lib/templates/gds/datamap/index.js +4 -1
- package/lib/templates/gds/datetime/index.js +4 -1
- package/lib/templates/gds/day/index.js +4 -1
- package/lib/templates/gds/editgrid/index.js +4 -1
- package/lib/templates/gds/field/index.js +4 -1
- package/lib/templates/gds/fieldset/index.js +4 -1
- package/lib/templates/gds/file/index.js +4 -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 +75 -64
- package/lib/templates/gds/input/index.js +4 -1
- package/lib/templates/gds/label/index.js +4 -1
- package/lib/templates/gds/message/index.js +4 -1
- package/lib/templates/gds/panel/index.js +4 -1
- package/lib/templates/gds/radio/index.js +4 -1
- package/lib/templates/gds/select/index.js +4 -1
- package/lib/templates/gds/selectOption/index.js +4 -1
- package/lib/templates/gds/selectboxes/index.js +4 -1
- package/lib/templates/gds/survey/index.js +4 -1
- package/lib/templates/gds/tab/index.js +4 -1
- package/lib/templates/gds/table/index.js +4 -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 +4 -1
- package/lib/templates/gds/warning/index.js +4 -1
- package/lib/templates/gds/wizard/index.js +4 -1
- package/lib/templates/gds/wizardHeader/index.js +4 -1
- package/lib/templates/gds/wizardNav/index.js +4 -1
- package/lib/templates/index.d.ts +2 -2
- package/lib/templates/index.js +4 -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 +110 -92
- package/src/components/selectboxes/GDSCheckBoxes.ts +7 -8
- package/src/components/time/GDSTimeComponent.ts +38 -28
- package/src/components/util/TimeHelper.ts +6 -5
- package/src/css.d.ts +4 -0
- package/src/templates/gds/datagrid/form.ejs +1 -1
- 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 +8 -4
- package/webpack.config.js +1 -1
- package/dist/gds.js +0 -2
- package/dist/gds.js.LICENSE.txt +0 -41
- package/tslint.json +0 -22
|
@@ -31,46 +31,56 @@ import wizard from './wizard';
|
|
|
31
31
|
import wizardHeader from './wizardHeader';
|
|
32
32
|
import wizardNav from './wizardNav';
|
|
33
33
|
|
|
34
|
+
// Unwrap CJS default exports to handle ESM/CJS interop in Vite.
|
|
35
|
+
// Uses a generic so the return type matches the input type — no `any` needed.
|
|
36
|
+
const unwrap = <T>(mod: T | { default: T }): T =>
|
|
37
|
+
(mod !== null && typeof mod === 'object' && 'default' in (mod as object))
|
|
38
|
+
? (mod as { default: T }).default
|
|
39
|
+
: (mod as T);
|
|
40
|
+
|
|
34
41
|
export default {
|
|
35
|
-
transform(type, text) {
|
|
42
|
+
transform(type: string, text: string) {
|
|
36
43
|
if (!text) {
|
|
37
44
|
return text;
|
|
38
45
|
}
|
|
39
46
|
if (type === 'class') {
|
|
40
|
-
|
|
47
|
+
const key = text.toString();
|
|
48
|
+
return Object.prototype.hasOwnProperty.call(this.cssClasses, key)
|
|
49
|
+
? this.cssClasses[key as keyof typeof this.cssClasses]
|
|
50
|
+
: text;
|
|
41
51
|
}
|
|
42
52
|
return text;
|
|
43
53
|
},
|
|
44
54
|
defaultIconset: 'fa',
|
|
45
|
-
iconClass,
|
|
46
|
-
cssClasses,
|
|
47
|
-
button,
|
|
48
|
-
checkbox,
|
|
49
|
-
columns,
|
|
50
|
-
component,
|
|
51
|
-
container,
|
|
52
|
-
datetime,
|
|
53
|
-
day,
|
|
54
|
-
datagrid,
|
|
55
|
-
datamap,
|
|
56
|
-
input,
|
|
57
|
-
editgrid,
|
|
58
|
-
field,
|
|
59
|
-
file,
|
|
60
|
-
fieldset,
|
|
61
|
-
label,
|
|
62
|
-
message,
|
|
63
|
-
panel,
|
|
64
|
-
radio,
|
|
65
|
-
select,
|
|
66
|
-
selectboxes,
|
|
67
|
-
selectOption,
|
|
68
|
-
survey,
|
|
69
|
-
table,
|
|
70
|
-
tab,
|
|
71
|
-
time,
|
|
72
|
-
warning,
|
|
73
|
-
wizard,
|
|
74
|
-
wizardHeader,
|
|
75
|
-
wizardNav,
|
|
55
|
+
iconClass: unwrap(iconClass),
|
|
56
|
+
cssClasses: unwrap(cssClasses),
|
|
57
|
+
button: unwrap(button),
|
|
58
|
+
checkbox: unwrap(checkbox),
|
|
59
|
+
columns: unwrap(columns),
|
|
60
|
+
component: unwrap(component),
|
|
61
|
+
container: unwrap(container),
|
|
62
|
+
datetime: unwrap(datetime),
|
|
63
|
+
day: unwrap(day),
|
|
64
|
+
datagrid: unwrap(datagrid),
|
|
65
|
+
datamap: unwrap(datamap),
|
|
66
|
+
input: unwrap(input),
|
|
67
|
+
editgrid: unwrap(editgrid),
|
|
68
|
+
field: unwrap(field),
|
|
69
|
+
file: unwrap(file),
|
|
70
|
+
fieldset: unwrap(fieldset),
|
|
71
|
+
label: unwrap(label),
|
|
72
|
+
message: unwrap(message),
|
|
73
|
+
panel: unwrap(panel),
|
|
74
|
+
radio: unwrap(radio),
|
|
75
|
+
select: unwrap(select),
|
|
76
|
+
selectboxes: unwrap(selectboxes),
|
|
77
|
+
selectOption: unwrap(selectOption),
|
|
78
|
+
survey: unwrap(survey),
|
|
79
|
+
table: unwrap(table),
|
|
80
|
+
tab: unwrap(tab),
|
|
81
|
+
time: unwrap(time),
|
|
82
|
+
warning: unwrap(warning),
|
|
83
|
+
wizard: unwrap(wizard),
|
|
84
|
+
wizardHeader: unwrap(wizardHeader),
|
|
85
|
+
wizardNav: unwrap(wizardNav),
|
|
76
86
|
};
|
|
@@ -82,6 +82,25 @@
|
|
|
82
82
|
|
|
83
83
|
.govuk-details {
|
|
84
84
|
margin-bottom: 0 !important;
|
|
85
|
+
|
|
86
|
+
// govuk-frontend@5.x sets font-weight:bold on the summary — reset to normal
|
|
87
|
+
&__summary {
|
|
88
|
+
font-weight: 400 !important;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// @formio/js@5.x injects error messages into messageContainer on container components
|
|
93
|
+
// (datagrid, editgrid, datamap, panel) which causes double error messages since child
|
|
94
|
+
// components already show their own errors. Hide the outer messageContainer for these types.
|
|
95
|
+
.formio-component-datagrid,
|
|
96
|
+
.formio-component-editgrid,
|
|
97
|
+
.formio-component-datamap,
|
|
98
|
+
.formio-component-panel,
|
|
99
|
+
.formio-component-container,
|
|
100
|
+
.formio-component-fieldset {
|
|
101
|
+
> [ref="messageContainer"] {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
85
104
|
}
|
|
86
105
|
|
|
87
106
|
.small-button {
|
|
@@ -144,4 +163,14 @@
|
|
|
144
163
|
|
|
145
164
|
.govuk-select.auto-height {
|
|
146
165
|
height: auto;
|
|
147
|
-
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// govuk-frontend@5.4+ sets overflow:clip (with auto visible fallback) on
|
|
169
|
+
// .govuk-form-group--error to contain the error border. This clips the focus
|
|
170
|
+
// rings and left borders of nested formio child components. Reset it so
|
|
171
|
+
// nested form groups are never clipped.
|
|
172
|
+
.govuk-form-group--error {
|
|
173
|
+
.govuk-form-group {
|
|
174
|
+
overflow: visible;
|
|
175
|
+
}
|
|
176
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DayComponent,
|
|
3
|
+
DateTimeComponent,
|
|
4
|
+
TimeComponent as CoreTimeComponent,
|
|
5
|
+
SelectBoxesComponent,
|
|
6
|
+
DataMapComponent,
|
|
7
|
+
} from '@formio/core';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Minimal interface for DOM input-like elements.
|
|
11
|
+
* Used as the typed parameter in TimeHelper methods so callers can pass any
|
|
12
|
+
* object that has a writable `.value: string` (e.g. HTMLInputElement).
|
|
13
|
+
*/
|
|
14
|
+
export interface InputElementLike {
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The shape of a single GDS date/time field definition.
|
|
20
|
+
* Extends the base formio field definition with an optional placeholder.
|
|
21
|
+
*/
|
|
22
|
+
export type GDSFieldDefinition = {
|
|
23
|
+
type?: string;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Component schema for GDSDatetimeComponent.
|
|
30
|
+
*
|
|
31
|
+
* GDSDatetimeComponent extends the formio Day component but adds hour/minute
|
|
32
|
+
* fields (from a datetime hybrid) and uses datePicker / defaultDate from
|
|
33
|
+
* DateTimeComponent. This type captures the full shape of `this.component`
|
|
34
|
+
* as used in GDSDatetimeComponent.
|
|
35
|
+
*/
|
|
36
|
+
export type GDSDatetimeComponentSchema =
|
|
37
|
+
// Omit `suffix` from the base so our wider `string | null` declaration wins
|
|
38
|
+
// the intersection (BaseComponent declares `suffix?: string`, which would
|
|
39
|
+
// collapse `string | null` back to `string` in a plain &-intersection).
|
|
40
|
+
// Also omit `fields` so we can extend it with hour/minute below.
|
|
41
|
+
Omit<DayComponent, 'suffix' | 'fields'> &
|
|
42
|
+
Pick<DateTimeComponent, 'datePicker' | 'defaultDate'> & {
|
|
43
|
+
/** suffix is set to null in init() — null must be allowed */
|
|
44
|
+
suffix?: string | null;
|
|
45
|
+
/** fields extended with GDS hour/minute additions */
|
|
46
|
+
fields: DayComponent['fields'] & {
|
|
47
|
+
hour?: GDSFieldDefinition;
|
|
48
|
+
minute?: GDSFieldDefinition;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Re-export @formio/core schema types used as `declare component` overrides
|
|
53
|
+
// in each GDS component class. Aliased to avoid colliding with the @formio/js
|
|
54
|
+
// runtime class variables (e.g. `const Time = Components.components.time`).
|
|
55
|
+
export type { CoreTimeComponent, SelectBoxesComponent, DataMapComponent };
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"lib": ["es2018", "dom"],
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
5
7
|
"preserveConstEnums": true,
|
|
6
8
|
"outDir": "lib",
|
|
7
|
-
"noImplicitAny":
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
8
11
|
"sourceMap": false,
|
|
9
12
|
"declaration": true,
|
|
10
|
-
"rootDir": "src"
|
|
13
|
+
"rootDir": "src",
|
|
14
|
+
"esModuleInterop": true
|
|
11
15
|
},
|
|
12
16
|
"include": [
|
|
13
17
|
"src/*.ts",
|