@types/govuk-frontend 5.7.0 → 5.9.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 (33) hide show
  1. govuk-frontend/README.md +1 -1
  2. govuk-frontend/dist/govuk/all.bundle.d.mts +3 -1
  3. govuk-frontend/dist/govuk/all.bundle.d.ts +5 -1
  4. govuk-frontend/dist/govuk/common/closest-attribute-value.d.ts +4 -1
  5. govuk-frontend/dist/govuk/common/configuration.d.mts +1 -0
  6. govuk-frontend/dist/govuk/common/configuration.d.ts +207 -0
  7. govuk-frontend/dist/govuk/common/index.d.ts +13 -96
  8. govuk-frontend/dist/govuk/component.d.mts +1 -0
  9. govuk-frontend/dist/govuk/{govuk-frontend-component.d.ts → component.d.ts} +3 -1
  10. govuk-frontend/dist/govuk/components/accordion/accordion.d.ts +8 -3
  11. govuk-frontend/dist/govuk/components/button/button.d.ts +5 -3
  12. govuk-frontend/dist/govuk/components/character-count/character-count.d.ts +31 -7
  13. govuk-frontend/dist/govuk/components/checkboxes/checkboxes.d.ts +2 -2
  14. govuk-frontend/dist/govuk/components/error-summary/error-summary.d.ts +9 -4
  15. govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.d.ts +8 -3
  16. govuk-frontend/dist/govuk/components/file-upload/file-upload.d.mts +1 -0
  17. govuk-frontend/dist/govuk/components/file-upload/file-upload.d.ts +95 -0
  18. govuk-frontend/dist/govuk/components/header/header.d.ts +2 -2
  19. govuk-frontend/dist/govuk/components/notification-banner/notification-banner.d.ts +8 -3
  20. govuk-frontend/dist/govuk/components/password-input/password-input.d.ts +9 -3
  21. govuk-frontend/dist/govuk/components/radios/radios.d.ts +2 -2
  22. govuk-frontend/dist/govuk/components/service-navigation/service-navigation.d.ts +2 -2
  23. govuk-frontend/dist/govuk/components/skip-link/skip-link.d.ts +2 -2
  24. govuk-frontend/dist/govuk/components/tabs/tabs.d.ts +2 -2
  25. govuk-frontend/dist/govuk/errors/index.d.ts +2 -4
  26. govuk-frontend/dist/govuk/i18n.d.ts +6 -3
  27. govuk-frontend/dist/govuk/init.d.ts +31 -17
  28. govuk-frontend/package.json +4 -3
  29. govuk-frontend/dist/govuk/common/normalise-dataset.d.mts +0 -1
  30. govuk-frontend/dist/govuk/common/normalise-dataset.d.ts +0 -16
  31. govuk-frontend/dist/govuk/common/normalise-string.d.mts +0 -1
  32. govuk-frontend/dist/govuk/common/normalise-string.d.ts +0 -22
  33. govuk-frontend/dist/govuk/govuk-frontend-component.d.mts +0 -1
govuk-frontend/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for govuk-frontend (https://github.com/al
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Mon, 14 Oct 2024 16:41:00 GMT
11
+ * Last updated: Thu, 03 Apr 2025 22:35:25 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
@@ -1,11 +1,14 @@
1
+ export { ConfigurableComponent } from "./common/configuration.mjs";
1
2
  export { version } from "./common/govuk-frontend-version.mjs";
2
3
  export { isSupported } from "./common/index.mjs";
4
+ export { Component } from "./component.mjs";
3
5
  export { Accordion } from "./components/accordion/accordion.mjs";
4
6
  export { Button } from "./components/button/button.mjs";
5
7
  export { CharacterCount } from "./components/character-count/character-count.mjs";
6
8
  export { Checkboxes } from "./components/checkboxes/checkboxes.mjs";
7
9
  export { ErrorSummary } from "./components/error-summary/error-summary.mjs";
8
10
  export { ExitThisPage } from "./components/exit-this-page/exit-this-page.mjs";
11
+ export { FileUpload } from "./components/file-upload/file-upload.mjs";
9
12
  export { Header } from "./components/header/header.mjs";
10
13
  export { NotificationBanner } from "./components/notification-banner/notification-banner.mjs";
11
14
  export { PasswordInput } from "./components/password-input/password-input.mjs";
@@ -13,5 +16,4 @@ export { Radios } from "./components/radios/radios.mjs";
13
16
  export { ServiceNavigation } from "./components/service-navigation/service-navigation.mjs";
14
17
  export { SkipLink } from "./components/skip-link/skip-link.mjs";
15
18
  export { Tabs } from "./components/tabs/tabs.mjs";
16
- export { GOVUKFrontendComponent as Component } from "./govuk-frontend-component.mjs";
17
19
  export { type Config, type ConfigKey, createAll, initAll } from "./init.mjs";
@@ -1,11 +1,14 @@
1
+ import { ConfigurableComponent } from "./common/configuration.js";
1
2
  import { version } from "./common/govuk-frontend-version.js";
2
3
  import { isSupported } from "./common/index.js";
4
+ import { Component } from "./component.js";
3
5
  import { Accordion } from "./components/accordion/accordion.js";
4
6
  import { Button } from "./components/button/button.js";
5
7
  import { CharacterCount } from "./components/character-count/character-count.js";
6
8
  import { Checkboxes } from "./components/checkboxes/checkboxes.js";
7
9
  import { ErrorSummary } from "./components/error-summary/error-summary.js";
8
10
  import { ExitThisPage } from "./components/exit-this-page/exit-this-page.js";
11
+ import { FileUpload } from "./components/file-upload/file-upload.js";
9
12
  import { Header } from "./components/header/header.js";
10
13
  import { NotificationBanner } from "./components/notification-banner/notification-banner.js";
11
14
  import { PasswordInput } from "./components/password-input/password-input.js";
@@ -13,7 +16,6 @@ import { Radios } from "./components/radios/radios.js";
13
16
  import { ServiceNavigation } from "./components/service-navigation/service-navigation.js";
14
17
  import { SkipLink } from "./components/skip-link/skip-link.js";
15
18
  import { Tabs } from "./components/tabs/tabs.js";
16
- import { GOVUKFrontendComponent as Component } from "./govuk-frontend-component.js";
17
19
  import { type Config as ConfigImport, type ConfigKey as ConfigKeyImport, createAll, initAll } from "./init.js";
18
20
 
19
21
  declare namespace GOVUKFrontend {
@@ -30,6 +32,7 @@ declare const GOVUKFrontend: {
30
32
  Checkboxes: typeof Checkboxes;
31
33
  ErrorSummary: typeof ErrorSummary;
32
34
  ExitThisPage: typeof ExitThisPage;
35
+ FileUpload: typeof FileUpload;
33
36
  Header: typeof Header;
34
37
  NotificationBanner: typeof NotificationBanner;
35
38
  PasswordInput: typeof PasswordInput;
@@ -38,6 +41,7 @@ declare const GOVUKFrontend: {
38
41
  SkipLink: typeof SkipLink;
39
42
  Tabs: typeof Tabs;
40
43
  Component: typeof Component;
44
+ ConfigurableComponent: typeof ConfigurableComponent;
41
45
  createAll: typeof createAll;
42
46
  initAll: typeof initAll;
43
47
  };
@@ -6,4 +6,7 @@
6
6
  * @param {string} attributeName - The name of the attribute
7
7
  * @returns {string | null} Attribute value
8
8
  */
9
- export function closestAttributeValue($element: Element, attributeName: string): string | null;
9
+ export function closestAttributeValue(
10
+ $element: Element,
11
+ attributeName: string,
12
+ ): string | null;
@@ -0,0 +1 @@
1
+ export * from "./configuration.js";
@@ -0,0 +1,207 @@
1
+ import { Component } from "../component.js";
2
+
3
+ /**
4
+ * Normalise string
5
+ *
6
+ * 'If it looks like a duck, and it quacks like a duck…' 🦆
7
+ *
8
+ * If the passed value looks like a boolean or a number, convert it to a boolean
9
+ * or number.
10
+ *
11
+ * Designed to be used to convert config passed via data attributes (which are
12
+ * always strings) into something sensible.
13
+ *
14
+ * @internal
15
+ * @param {DOMStringMap[string]} value - The value to normalise
16
+ * @param {SchemaProperty} [property] - Component schema property
17
+ * @returns {string | boolean | number | undefined} Normalised data
18
+ */
19
+ export function normaliseString(
20
+ value: DOMStringMap[string],
21
+ property?: SchemaProperty,
22
+ ): string | boolean | number | undefined;
23
+
24
+ /**
25
+ * Normalise dataset
26
+ *
27
+ * Loop over an object and normalise each value using {@link normaliseString},
28
+ * optionally expanding nested `i18n.field`
29
+ *
30
+ * @internal
31
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
32
+ * @template {[keyof ConfigurationType, SchemaProperty | undefined][]} SchemaEntryType
33
+ * @param {{ schema?: Schema<ConfigurationType>, moduleName: string }} Component - Component class
34
+ * @param {DOMStringMap} dataset - HTML element dataset
35
+ * @returns {ObjectNested} Normalised dataset
36
+ */
37
+ export function normaliseDataset<
38
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
39
+ >(
40
+ Component: {
41
+ schema?: Schema<ConfigurationType>;
42
+ moduleName: string;
43
+ },
44
+ dataset: DOMStringMap,
45
+ ): ObjectNested;
46
+
47
+ /**
48
+ * Config merging function
49
+ *
50
+ * Takes any number of objects and combines them together, with
51
+ * greatest priority on the LAST item passed in.
52
+ *
53
+ * @internal
54
+ * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
55
+ * @returns {{ [key: string]: unknown }} A merged config object
56
+ */
57
+ export function mergeConfigs(
58
+ ...configObjects: {
59
+ [key: string]: unknown;
60
+ }[]
61
+ ): {
62
+ [key: string]: unknown;
63
+ };
64
+
65
+ /**
66
+ * Validate component config by schema
67
+ *
68
+ * Follows limited examples in JSON schema for wider support in future
69
+ *
70
+ * {@link https://ajv.js.org/json-schema.html#compound-keywords}
71
+ * {@link https://ajv.js.org/packages/ajv-errors.html#single-message}
72
+ *
73
+ * @internal
74
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
75
+ * @param {Schema<ConfigurationType>} schema - The schema of a component
76
+ * @param {ConfigurationType} config - Component config
77
+ * @returns {string[]} List of validation errors
78
+ */
79
+ export function validateConfig<
80
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
81
+ >(schema: Schema<ConfigurationType>, config: ConfigurationType): string[];
82
+
83
+ /**
84
+ * Extracts keys starting with a particular namespace from dataset ('data-*')
85
+ * object, removing the namespace in the process, normalising all values
86
+ *
87
+ * @internal
88
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
89
+ * @param {Schema<ConfigurationType>} schema - The schema of a component
90
+ * @param {DOMStringMap} dataset - The object to extract key-value pairs from
91
+ * @param {keyof ConfigurationType} namespace - The namespace to filter keys with
92
+ * @returns {ObjectNested | undefined} Nested object with dot-separated key namespace removed
93
+ */
94
+ export function extractConfigByNamespace<
95
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
96
+ >(
97
+ schema: Schema<ConfigurationType>,
98
+ dataset: DOMStringMap,
99
+ namespace: keyof ConfigurationType,
100
+ ): ObjectNested | undefined;
101
+
102
+ export const configOverride: unique symbol;
103
+
104
+ /**
105
+ * Base Component class
106
+ *
107
+ * Centralises the behaviours shared by our components
108
+ *
109
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
110
+ * @template {Element & { dataset: DOMStringMap }} RootElementType
111
+ */
112
+ export abstract class ConfigurableComponent<
113
+ ConfigurationType extends Partial<
114
+ Record<keyof ConfigurationType, unknown>
115
+ > = ObjectNested,
116
+ RootElementType extends Element & {
117
+ dataset: DOMStringMap;
118
+ } = HTMLElement,
119
+ > extends Component<RootElementType> {
120
+ /**
121
+ * Constructs a new component, validating that GOV.UK Frontend is supported
122
+ *
123
+ * @internal
124
+ * @param {Element | null} [$root] - HTML element to use for component
125
+ * @param {ConfigurationType} [config] - HTML element to use for component
126
+ */
127
+ constructor($root?: Element | null, config?: ConfigurationType);
128
+
129
+ /**
130
+ * Returns the root element of the component
131
+ *
132
+ * @returns {ConfigurationType} - the root element of component
133
+ */
134
+ protected get config(): ConfigurationType;
135
+
136
+ /** */
137
+ _config: ConfigurationType;
138
+
139
+ /**
140
+ * configOverride
141
+ *
142
+ * Function which defines configuration overrides to prioritize
143
+ * properties from the root element's dataset.
144
+ *
145
+ * It should take a subset of configuration as input and return
146
+ * a new configuration object with properties that should be
147
+ * overridden based on the root element's dataset. A Symbol
148
+ * is used for indexing to prevent conflicts.
149
+ *
150
+ * @internal
151
+ * @param {Partial<ConfigurationType>} [param] - Configuration object
152
+ * @returns {Partial<ConfigurationType>} return - Configuration object
153
+ */
154
+ [configOverride](
155
+ param?: Partial<ConfigurationType>,
156
+ ): Partial<ConfigurationType>;
157
+ }
158
+
159
+ export type NestedKey = keyof ObjectNested;
160
+
161
+ export interface ObjectNested {
162
+ [key: string]: string | boolean | number | ObjectNested | undefined;
163
+ }
164
+
165
+ /**
166
+ * Schema for component config
167
+ */
168
+ export interface Schema<
169
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
170
+ > {
171
+ /**
172
+ * - Schema properties
173
+ */
174
+ properties: Record<keyof ConfigurationType, SchemaProperty | undefined>;
175
+
176
+ /**
177
+ * - List of schema conditions
178
+ */
179
+ anyOf?: SchemaCondition<ConfigurationType>[] | undefined;
180
+ }
181
+
182
+ /**
183
+ * Schema property for component config
184
+ */
185
+ export interface SchemaProperty {
186
+ /**
187
+ * - Property type
188
+ */
189
+ type: "string" | "boolean" | "number" | "object";
190
+ }
191
+
192
+ /**
193
+ * Schema condition for component config
194
+ */
195
+ export interface SchemaCondition<
196
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
197
+ > {
198
+ /**
199
+ * - List of required config fields
200
+ */
201
+ required: (keyof ConfigurationType)[];
202
+
203
+ /**
204
+ * - Error message when required config fields not provided
205
+ */
206
+ errorMessage: string;
207
+ }
@@ -1,3 +1,5 @@
1
+ import { type ObjectNested } from "./configuration.js";
2
+
1
3
  /**
2
4
  * Common helpers which do not require polyfill.
3
5
  *
@@ -5,41 +7,6 @@
5
7
  * so that the polyfill can be properly tree-shaken and does not burden
6
8
  * the components that do not need that helper
7
9
  */
8
- /**
9
- * Config merging function
10
- *
11
- * Takes any number of objects and combines them together, with
12
- * greatest priority on the LAST item passed in.
13
- *
14
- * @internal
15
- * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
16
- * @returns {{ [key: string]: unknown }} A merged config object
17
- */
18
- export function mergeConfigs(
19
- ...configObjects: Array<{
20
- [key: string]: unknown;
21
- }>
22
- ): {
23
- [key: string]: unknown;
24
- };
25
-
26
- /**
27
- * Extracts keys starting with a particular namespace from dataset ('data-*')
28
- * object, removing the namespace in the process, normalising all values
29
- *
30
- * @internal
31
- * @param {{ schema: Schema }} Component - Component class
32
- * @param {DOMStringMap} dataset - The object to extract key-value pairs from
33
- * @param {string} namespace - The namespace to filter keys with
34
- * @returns {ObjectNested | undefined} Nested object with dot-separated key namespace removed
35
- */
36
- export function extractConfigByNamespace(
37
- Component: {
38
- schema: Schema;
39
- },
40
- dataset: DOMStringMap,
41
- namespace: string,
42
- ): ObjectNested | undefined;
43
10
 
44
11
  /**
45
12
  * Get hash fragment from URL
@@ -105,21 +72,16 @@ export function isInitialised($root: Element, moduleName: string): boolean;
105
72
  export function isSupported($scope?: HTMLElement | null): boolean;
106
73
 
107
74
  /**
108
- * Validate component config by schema
109
- *
110
- * Follows limited examples in JSON schema for wider support in future
111
- *
112
- * {@link https://ajv.js.org/json-schema.html#compound-keywords}
113
- * {@link https://ajv.js.org/packages/ajv-errors.html#single-message}
75
+ * Check for an object
114
76
  *
115
77
  * @internal
116
- * @param {Schema} schema - Config schema
117
- * @param {{ [key: string]: unknown }} config - Component config
118
- * @returns {string[]} List of validation errors
78
+ * @template {Partial<Record<keyof ObjectType, unknown>>} [ObjectType=ObjectNested]
79
+ * @param {unknown | ObjectType} option - Option to check
80
+ * @returns {option is ObjectType} Whether the option is an object
119
81
  */
120
- export function validateConfig(schema: Schema, config: {
121
- [key: string]: unknown;
122
- }): string[];
82
+ export function isObject<
83
+ ObjectType extends Partial<Record<keyof ObjectType, unknown>> = ObjectNested,
84
+ >(option: unknown | ObjectType): option is ObjectType;
123
85
 
124
86
  /**
125
87
  * Format error message
@@ -129,55 +91,10 @@ export function validateConfig(schema: Schema, config: {
129
91
  * @param {string} message - Error message
130
92
  * @returns {string} - Formatted error message
131
93
  */
132
- export function formatErrorMessage(Component: ComponentWithModuleName, message: string): string;
133
-
134
- /**
135
- * Schema for component config
136
- */
137
- export interface Schema {
138
- /**
139
- * - Schema properties
140
- */
141
- properties: {
142
- [field: string]: SchemaProperty | undefined;
143
- };
144
-
145
- /**
146
- * - List of schema conditions
147
- */
148
- anyOf?: SchemaCondition[] | undefined;
149
- }
150
-
151
- /**
152
- * Schema property for component config
153
- */
154
- export interface SchemaProperty {
155
- /**
156
- * - Property type
157
- */
158
- type: "string" | "boolean" | "number" | "object";
159
- }
160
-
161
- /**
162
- * Schema condition for component config
163
- */
164
- export interface SchemaCondition {
165
- /**
166
- * - List of required config fields
167
- */
168
- required: string[];
169
-
170
- /**
171
- * - Error message when required config fields not provided
172
- */
173
- errorMessage: string;
174
- }
175
-
176
- export type NestedKey = keyof ObjectNested;
177
-
178
- export interface ObjectNested {
179
- [key: string]: string | boolean | number | ObjectNested | undefined;
180
- }
94
+ export function formatErrorMessage(
95
+ Component: ComponentWithModuleName,
96
+ message: string,
97
+ ): string;
181
98
 
182
99
  export interface ComponentWithModuleName {
183
100
  /**
@@ -0,0 +1 @@
1
+ export * from "./component.js";
@@ -2,8 +2,10 @@
2
2
  * Base Component class
3
3
  *
4
4
  * Centralises the behaviours shared by our components
5
+ *
6
+ * @template {Element} [RootElementType=HTMLElement]
5
7
  */
6
- export abstract class GOVUKFrontendComponent<RootElementType extends Element = HTMLElement> {
8
+ export abstract class Component<RootElementType extends Element = HTMLElement> {
7
9
  static elementType: typeof Element;
8
10
 
9
11
  /**
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Accordion component
@@ -12,7 +12,10 @@ import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
12
12
  * The state of each section is saved to the DOM via the `aria-expanded`
13
13
  * attribute, which also provides accessibility.
14
14
  */
15
- export class Accordion extends GOVUKFrontendComponent<HTMLElement> {
15
+ export class Accordion extends ConfigurableComponent<
16
+ AccordionConfig,
17
+ HTMLElement
18
+ > {
16
19
  /**
17
20
  * Name for the component used when initialising using data-module attributes.
18
21
  */
@@ -22,13 +25,15 @@ export class Accordion extends GOVUKFrontendComponent<HTMLElement> {
22
25
  * Accordion default config
23
26
  *
24
27
  * @see {@link AccordionConfig}
28
+ * @constant
25
29
  */
26
30
  static defaults: AccordionConfig;
27
31
 
28
32
  /**
29
33
  * Accordion config schema
30
34
  *
31
- * @satisfies {Schema}
35
+ * @constant
36
+ * @satisfies {Schema<AccordionConfig>}
32
37
  */
33
38
  static schema: Readonly<{
34
39
  properties: {
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * JavaScript enhancements for the Button component
5
5
  */
6
- export class Button extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Button extends ConfigurableComponent<ButtonConfig, HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -13,13 +13,15 @@ export class Button extends GOVUKFrontendComponent<HTMLElement> {
13
13
  * Button default config
14
14
  *
15
15
  * @see {@link ButtonConfig}
16
+ * @constant
16
17
  */
17
18
  static defaults: ButtonConfig;
18
19
 
19
20
  /**
20
21
  * Button config schema
21
22
  *
22
- * @satisfies {Schema}
23
+ * @constant
24
+ * @satisfies {Schema<ButtonConfig>}
23
25
  */
24
26
  static schema: Readonly<{
25
27
  properties: {
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { configOverride, ConfigurableComponent } from "../../common/configuration.js";
2
2
  import { type TranslationPluralForms } from "../../i18n.js";
3
3
 
4
4
  /**
@@ -11,7 +11,10 @@ import { type TranslationPluralForms } from "../../i18n.js";
11
11
  * You can configure the message to only appear after a certain percentage
12
12
  * of the available characters/words has been entered.
13
13
  */
14
- export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
14
+ export class CharacterCount extends ConfigurableComponent<
15
+ CharacterCountConfig,
16
+ HTMLElement
17
+ > {
15
18
  /**
16
19
  * Name for the component used when initialising using data-module attributes.
17
20
  */
@@ -21,13 +24,15 @@ export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
21
24
  * Character count default config
22
25
  *
23
26
  * @see {@link CharacterCountConfig}
27
+ * @constant
24
28
  */
25
29
  static defaults: CharacterCountConfig;
26
30
 
27
31
  /**
28
32
  * Character count config schema
29
33
  *
30
- * @satisfies {Schema}
34
+ * @constant
35
+ * @satisfies {Schema<CharacterCountConfig>}
31
36
  */
32
37
  static schema: Readonly<{
33
38
  properties: {
@@ -44,10 +49,16 @@ export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
44
49
  type: "number";
45
50
  };
46
51
  };
47
- anyOf: Array<{
48
- required: string[];
49
- errorMessage: string;
50
- }>;
52
+ anyOf: (
53
+ | {
54
+ required: "maxwords"[];
55
+ errorMessage: string;
56
+ }
57
+ | {
58
+ required: "maxlength"[];
59
+ errorMessage: string;
60
+ }
61
+ )[];
51
62
  }>;
52
63
 
53
64
  /**
@@ -55,6 +66,19 @@ export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
55
66
  * @param {CharacterCountConfig} [config] - Character count config
56
67
  */
57
68
  constructor($root: Element | null, config?: CharacterCountConfig);
69
+
70
+ /**
71
+ * Character count config override
72
+ *
73
+ * To ensure data-attributes take complete precedence, even if they change
74
+ * the type of count, we need to reset the `maxlength` and `maxwords` from
75
+ * the JavaScript config.
76
+ *
77
+ * @internal
78
+ * @param {CharacterCountConfig} datasetConfig - configuration specified by dataset
79
+ * @returns {CharacterCountConfig} - configuration to override by dataset
80
+ */
81
+ [configOverride](datasetConfig: CharacterCountConfig): CharacterCountConfig;
58
82
  }
59
83
 
60
84
  /**
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Checkboxes component
5
5
  */
6
- export class Checkboxes extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Checkboxes extends Component<HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Error summary component
@@ -6,7 +6,10 @@ import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
6
6
  * Takes focus on initialisation for accessible announcement, unless disabled in
7
7
  * configuration.
8
8
  */
9
- export class ErrorSummary extends GOVUKFrontendComponent<HTMLElement> {
9
+ export class ErrorSummary extends ConfigurableComponent<
10
+ ErrorSummaryConfig,
11
+ HTMLElement
12
+ > {
10
13
  /**
11
14
  * Name for the component used when initialising using data-module attributes.
12
15
  */
@@ -16,13 +19,15 @@ export class ErrorSummary extends GOVUKFrontendComponent<HTMLElement> {
16
19
  * Error summary default config
17
20
  *
18
21
  * @see {@link ErrorSummaryConfig}
22
+ * @constant
19
23
  */
20
24
  static defaults: ErrorSummaryConfig;
21
25
 
22
26
  /**
23
27
  * Error summary config schema
24
28
  *
25
- * @satisfies {Schema}
29
+ * @constant
30
+ * @satisfies {Schema<ErrorSummaryConfig>}
26
31
  */
27
32
  static schema: Readonly<{
28
33
  properties: {
@@ -47,5 +52,5 @@ export interface ErrorSummaryConfig {
47
52
  * - If set to `true` the error
48
53
  * summary will not be focussed when the page loads.
49
54
  */
50
- disableAutoFocus?: boolean;
55
+ disableAutoFocus?: boolean | undefined;
51
56
  }
@@ -1,9 +1,12 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Exit this page component
5
5
  */
6
- export class ExitThisPage extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class ExitThisPage extends ConfigurableComponent<
7
+ ExitThisPageConfig,
8
+ HTMLElement
9
+ > {
7
10
  /**
8
11
  * Name for the component used when initialising using data-module attributes.
9
12
  */
@@ -13,13 +16,15 @@ export class ExitThisPage extends GOVUKFrontendComponent<HTMLElement> {
13
16
  * Exit this page default config
14
17
  *
15
18
  * @see {@link ExitThisPageConfig}
19
+ * @constant
16
20
  */
17
21
  static defaults: ExitThisPageConfig;
18
22
 
19
23
  /**
20
24
  * Exit this page config schema
21
25
  *
22
- * @satisfies {Schema}
26
+ * @constant
27
+ * @satisfies {Schema<ExitThisPageConfig>}
23
28
  */
24
29
  static schema: Readonly<{
25
30
  properties: {
@@ -0,0 +1 @@
1
+ export * from "./file-upload.js";
@@ -0,0 +1,95 @@
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
+ import { type TranslationPluralForms } from "../../i18n.js";
3
+
4
+ /**
5
+ * File upload component
6
+ */
7
+ export class FileUpload extends ConfigurableComponent<
8
+ FileUploadConfig,
9
+ HTMLElement
10
+ > {
11
+ /**
12
+ * Name for the component used when initialising using data-module attributes.
13
+ */
14
+ static moduleName: string;
15
+
16
+ /**
17
+ * File upload default config
18
+ *
19
+ * @see {@link FileUploadConfig}
20
+ * @constant
21
+ */
22
+ static defaults: FileUploadConfig;
23
+
24
+ /**
25
+ * File upload config schema
26
+ *
27
+ * @constant
28
+ * @satisfies {Schema<FileUploadConfig>}
29
+ */
30
+ static schema: Readonly<{
31
+ properties: {
32
+ i18n: {
33
+ type: "object";
34
+ };
35
+ };
36
+ }>;
37
+
38
+ /**
39
+ * @param {Element | null} $root - File input element
40
+ * @param {FileUploadConfig} [config] - File Upload config
41
+ */
42
+ constructor($root: Element | null, config?: FileUploadConfig);
43
+ }
44
+
45
+ export type HTMLFileInputElement = HTMLInputElement & {
46
+ files: FileList;
47
+ };
48
+
49
+ /**
50
+ * File upload config
51
+ */
52
+ export interface FileUploadConfig {
53
+ /**
54
+ * - File upload translations
55
+ */
56
+ i18n?: FileUploadTranslations | undefined;
57
+ }
58
+
59
+ /**
60
+ * Messages used by the component
61
+ */
62
+ export interface FileUploadTranslations {
63
+ /**
64
+ * - The text of the button that opens the file picker
65
+ */
66
+ chooseFile?: string | undefined;
67
+
68
+ /**
69
+ * - The text informing users they can drop files
70
+ */
71
+ dropInstruction?: string | undefined;
72
+
73
+ /**
74
+ * - The text displayed when multiple files
75
+ * have been chosen by the user
76
+ */
77
+ multipleFilesChosen?: TranslationPluralForms | undefined;
78
+
79
+ /**
80
+ * - The text to displayed when no file has been chosen by the user
81
+ */
82
+ noFileChosen?: string | undefined;
83
+
84
+ /**
85
+ * - The text announced by assistive technology
86
+ * when user drags files and enters the drop zone
87
+ */
88
+ enteredDropZone?: string | undefined;
89
+
90
+ /**
91
+ * - The text announced by assistive technology
92
+ * when user drags files and leaves the drop zone without dropping
93
+ */
94
+ leftDropZone?: string | undefined;
95
+ }
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Header component
5
5
  */
6
- export class Header extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Header extends Component<HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,9 +1,12 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Notification Banner component
5
5
  */
6
- export class NotificationBanner extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class NotificationBanner extends ConfigurableComponent<
7
+ NotificationBannerConfig,
8
+ HTMLElement
9
+ > {
7
10
  /**
8
11
  * Name for the component used when initialising using data-module attributes.
9
12
  */
@@ -13,13 +16,15 @@ export class NotificationBanner extends GOVUKFrontendComponent<HTMLElement> {
13
16
  * Notification banner default config
14
17
  *
15
18
  * @see {@link NotificationBannerConfig}
19
+ * @constant
16
20
  */
17
21
  static defaults: NotificationBannerConfig;
18
22
 
19
23
  /**
20
24
  * Notification banner config schema
21
25
  *
22
- * @satisfies {Schema}
26
+ * @constant
27
+ * @satisfies {Schema<NotificationBannerConfig>}
23
28
  */
24
29
  static schema: Readonly<{
25
30
  properties: {
@@ -1,9 +1,12 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Password input component
5
5
  */
6
- export class PasswordInput extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class PasswordInput extends ConfigurableComponent<
7
+ PasswordInputConfig,
8
+ HTMLElement
9
+ > {
7
10
  /**
8
11
  * Name for the component used when initialising using data-module attributes.
9
12
  */
@@ -13,13 +16,16 @@ export class PasswordInput extends GOVUKFrontendComponent<HTMLElement> {
13
16
  * Password input default config
14
17
  *
15
18
  * @see {@link PasswordInputConfig}
19
+ * @constant
20
+ * @default
16
21
  */
17
22
  static defaults: PasswordInputConfig;
18
23
 
19
24
  /**
20
25
  * Password input config schema
21
26
  *
22
- * @satisfies {Schema}
27
+ * @constant
28
+ * @satisfies {Schema<PasswordInputConfig>}
23
29
  */
24
30
  static schema: Readonly<{
25
31
  properties: {
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Radios component
5
5
  */
6
- export class Radios extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Radios extends Component<HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Service Navigation component
5
5
  */
6
- export class ServiceNavigation extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class ServiceNavigation extends Component<HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Skip link component
5
5
  */
6
- export class SkipLink extends GOVUKFrontendComponent<HTMLAnchorElement> {
6
+ export class SkipLink extends Component<HTMLAnchorElement> {
7
7
  static elementType: {
8
8
  new(): HTMLAnchorElement;
9
9
  prototype: HTMLAnchorElement;
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { Component } from "../../component.js";
2
2
 
3
3
  /**
4
4
  * Tabs component
5
5
  */
6
- export class Tabs extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Tabs extends Component<HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -19,8 +19,7 @@ import { type ComponentWithModuleName } from "../common/index.js";
19
19
  * }
20
20
  * ```
21
21
  */
22
- export abstract class GOVUKFrontendError extends Error {
23
- }
22
+ export abstract class GOVUKFrontendError extends Error {}
24
23
 
25
24
  /**
26
25
  * Indicates that GOV.UK Frontend is not supported
@@ -37,8 +36,7 @@ export class SupportError extends GOVUKFrontendError {
37
36
  /**
38
37
  * Indicates that a component has received an illegal configuration
39
38
  */
40
- export class ConfigError extends GOVUKFrontendError {
41
- }
39
+ export class ConfigError extends GOVUKFrontendError {}
42
40
 
43
41
  /**
44
42
  * Indicates an issue with an element (possibly `null` or `undefined`)
@@ -104,9 +104,12 @@ export class I18n {
104
104
  * @param {{ [key: string]: unknown }} options - Any options passed with the translation string, e.g: for string interpolation.
105
105
  * @returns {string} The translation string to output, with $\{\} placeholders replaced
106
106
  */
107
- replacePlaceholders(translationString: string, options: {
108
- [key: string]: unknown;
109
- }): string;
107
+ replacePlaceholders(
108
+ translationString: string,
109
+ options: {
110
+ [key: string]: unknown;
111
+ },
112
+ ): string;
110
113
 
111
114
  /**
112
115
  * Check to see if the browser supports Intl.PluralRules
@@ -3,12 +3,12 @@ import { type ButtonConfig } from "./components/button/button.js";
3
3
  import { type CharacterCountConfig } from "./components/character-count/character-count.js";
4
4
  import { type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
5
5
  import { type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
6
+ import { type FileUploadConfig } from "./components/file-upload/file-upload.js";
6
7
  import { type NotificationBannerConfig } from "./components/notification-banner/notification-banner.js";
7
8
  import { type PasswordInputConfig } from "./components/password-input/password-input.js";
8
9
 
9
10
  export interface CompatibleClass {
10
11
  new(...args: any[]): any;
11
- defaults?: object;
12
12
  moduleName: string;
13
13
  }
14
14
 
@@ -41,6 +41,11 @@ export interface Config {
41
41
  */
42
42
  exitThisPage?: ExitThisPageConfig | undefined;
43
43
 
44
+ /**
45
+ * - File Upload config
46
+ */
47
+ fileUpload?: FileUploadConfig | undefined;
48
+
44
49
  /**
45
50
  * - Notification Banner config
46
51
  */
@@ -57,7 +62,9 @@ export interface Config {
57
62
  */
58
63
  export type ConfigKey = keyof Config;
59
64
 
60
- export interface ErrorContext<T extends CompatibleClass> {
65
+ export type ComponentConfig<ComponentClass extends CompatibleClass> = ConstructorParameters<ComponentClass>[1];
66
+
67
+ export interface ErrorContext<ComponentClass extends CompatibleClass> {
61
68
  /**
62
69
  * - Element used for component module initialisation
63
70
  */
@@ -66,17 +73,20 @@ export interface ErrorContext<T extends CompatibleClass> {
66
73
  /**
67
74
  * - Class of component
68
75
  */
69
- component?: T | undefined;
76
+ component?: ComponentClass | undefined;
70
77
 
71
78
  /**
72
79
  * - Config supplied to component
73
80
  */
74
- config: T["defaults"];
81
+ config: ComponentConfig<ComponentClass>;
75
82
  }
76
83
 
77
- export type OnErrorCallback<T extends CompatibleClass> = (error: unknown, context: ErrorContext<T>) => any;
84
+ export type OnErrorCallback<ComponentClass extends CompatibleClass> = (
85
+ error: unknown,
86
+ context: ErrorContext<ComponentClass>,
87
+ ) => any;
78
88
 
79
- export interface CreateAllOptions<T extends CompatibleClass> {
89
+ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
80
90
  /**
81
91
  * - scope of the document to search within
82
92
  */
@@ -85,7 +95,7 @@ export interface CreateAllOptions<T extends CompatibleClass> {
85
95
  /**
86
96
  * - callback function if error throw by component on init
87
97
  */
88
- onError?: OnErrorCallback<T> | undefined;
98
+ onError?: OnErrorCallback<ComponentClass> | undefined;
89
99
  }
90
100
 
91
101
  /**
@@ -112,14 +122,18 @@ export function initAll(
112
122
  *
113
123
  * Any component errors will be caught and logged to the console.
114
124
  *
115
- * @template {CompatibleClass} T
116
- * @param {T} Component - class of the component to create
117
- * @param {T["defaults"]} [config] - Config supplied to component
118
- * @param {OnErrorCallback<T> | Element | Document | CreateAllOptions<T> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
119
- * @returns {Array<InstanceType<T>>} - array of instantiated components
125
+ * @template {CompatibleClass} ComponentClass
126
+ * @param {ComponentClass} Component - class of the component to create
127
+ * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
128
+ * @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
129
+ * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
120
130
  */
121
- export function createAll<T extends CompatibleClass>(
122
- Component: T,
123
- config?: T["defaults"],
124
- createAllOptions?: Document | Element | OnErrorCallback<T> | CreateAllOptions<T>,
125
- ): Array<InstanceType<T>>;
131
+ export function createAll<ComponentClass extends CompatibleClass>(
132
+ Component: ComponentClass,
133
+ config?: ComponentConfig<ComponentClass>,
134
+ createAllOptions?:
135
+ | OnErrorCallback<ComponentClass>
136
+ | Element
137
+ | Document
138
+ | CreateAllOptions<ComponentClass>,
139
+ ): Array<InstanceType<ComponentClass>>;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/govuk-frontend",
3
- "version": "5.7.0",
3
+ "version": "5.9.0",
4
4
  "description": "TypeScript definitions for govuk-frontend",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend",
6
6
  "license": "MIT",
@@ -32,6 +32,7 @@
32
32
  },
33
33
  "scripts": {},
34
34
  "dependencies": {},
35
- "typesPublisherContentHash": "08d1cc6a671dadd0e0e9c1113ea085b28a6b2510f52991c817bfb8d71bc308ae",
36
- "typeScriptVersion": "4.8"
35
+ "peerDependencies": {},
36
+ "typesPublisherContentHash": "0c6bf1e47e944f9d230c1eed825ea255eb3d43f5684e51a3c8c070c2a8ec9177",
37
+ "typeScriptVersion": "5.1"
37
38
  }
@@ -1 +0,0 @@
1
- export * from "./normalise-dataset.js";
@@ -1,16 +0,0 @@
1
- import { type ObjectNested, type Schema } from "./index.js";
2
-
3
- /**
4
- * Normalise dataset
5
- *
6
- * Loop over an object and normalise each value using {@link normaliseString},
7
- * optionally expanding nested `i18n.field`
8
- *
9
- * @internal
10
- * @param {{ schema: Schema }} Component - Component class
11
- * @param {DOMStringMap} dataset - HTML element dataset
12
- * @returns {ObjectNested} Normalised dataset
13
- */
14
- export function normaliseDataset(Component: {
15
- schema: Schema;
16
- }, dataset: DOMStringMap): ObjectNested;
@@ -1 +0,0 @@
1
- export * from "./normalise-string.js";
@@ -1,22 +0,0 @@
1
- import { type SchemaProperty } from "./index.js";
2
-
3
- /**
4
- * Normalise string
5
- *
6
- * 'If it looks like a duck, and it quacks like a duck…' 🦆
7
- *
8
- * If the passed value looks like a boolean or a number, convert it to a boolean
9
- * or number.
10
- *
11
- * Designed to be used to convert config passed via data attributes (which are
12
- * always strings) into something sensible.
13
- *
14
- * @internal
15
- * @param {DOMStringMap[string]} value - The value to normalise
16
- * @param {SchemaProperty} [property] - Component schema property
17
- * @returns {string | boolean | number | undefined} Normalised data
18
- */
19
- export function normaliseString(
20
- value: DOMStringMap[string],
21
- property?: SchemaProperty,
22
- ): string | boolean | number | undefined;
@@ -1 +0,0 @@
1
- export * from "./govuk-frontend-component.js";