@types/govuk-frontend 5.9.0 → 5.11.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.
govuk-frontend/README.md
CHANGED
|
@@ -8,8 +8,8 @@ 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:
|
|
11
|
+
* Last updated: Fri, 12 Sep 2025 19:02:26 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
|
|
14
14
|
# Credits
|
|
15
|
-
These definitions were written by [Colin Rotherham](https://github.com/colinrotherham), and [Romaric Pascal](https://github.com/romaricpascal).
|
|
15
|
+
These definitions were written by [Colin Rotherham](https://github.com/colinrotherham), [Paul Robert Lloyd](https://github.com/paulrobertlloyd), and [Romaric Pascal](https://github.com/romaricpascal).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Component } from "../component.js";
|
|
2
|
+
import { type CompatibleClass, type Config, type CreateAllOptions, type OnErrorCallback } from "../init.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Normalise string
|
|
@@ -44,6 +45,25 @@ export function normaliseDataset<
|
|
|
44
45
|
dataset: DOMStringMap,
|
|
45
46
|
): ObjectNested;
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Normalise options passed to `initAll` or `createAll`
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
* @template {CompatibleClass} ComponentClass
|
|
53
|
+
* @param {Config | CreateAllOptions<ComponentClass> | OnErrorCallback<ComponentClass> | Element | Document | null} [scopeOrOptions] - Scope of the document to search within, initialisation options or error callback function
|
|
54
|
+
* @returns {CreateAllOptions<ComponentClass>} Normalised options
|
|
55
|
+
*/
|
|
56
|
+
export function normaliseOptions<
|
|
57
|
+
ComponentClass extends CompatibleClass,
|
|
58
|
+
>(
|
|
59
|
+
scopeOrOptions?:
|
|
60
|
+
| Config
|
|
61
|
+
| CreateAllOptions<ComponentClass>
|
|
62
|
+
| OnErrorCallback<ComponentClass>
|
|
63
|
+
| Element
|
|
64
|
+
| Document
|
|
65
|
+
| null,
|
|
66
|
+
): CreateAllOptions<ComponentClass>;
|
|
47
67
|
/**
|
|
48
68
|
* Config merging function
|
|
49
69
|
*
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type ObjectNested } from "./configuration.js";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Common helpers which do not require polyfill.
|
|
5
3
|
*
|
|
@@ -7,18 +5,6 @@ import { type ObjectNested } from "./configuration.js";
|
|
|
7
5
|
* so that the polyfill can be properly tree-shaken and does not burden
|
|
8
6
|
* the components that do not need that helper
|
|
9
7
|
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get hash fragment from URL
|
|
13
|
-
*
|
|
14
|
-
* Extract the hash fragment (everything after the hash) from a URL,
|
|
15
|
-
* but not including the hash symbol
|
|
16
|
-
*
|
|
17
|
-
* @param {string} url - URL
|
|
18
|
-
* @returns {string | undefined} Fragment from URL, without the hash
|
|
19
|
-
*/
|
|
20
|
-
export function getFragmentFromUrl(url: string): string | undefined;
|
|
21
|
-
|
|
22
8
|
/**
|
|
23
9
|
* Get GOV.UK Frontend breakpoint value from CSS custom property
|
|
24
10
|
*
|
|
@@ -75,14 +61,26 @@ export function isSupported($scope?: HTMLElement | null): boolean;
|
|
|
75
61
|
* Check for an object
|
|
76
62
|
*
|
|
77
63
|
* @internal
|
|
78
|
-
* @template {Partial<Record<keyof ObjectType, unknown>>}
|
|
64
|
+
* @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType
|
|
79
65
|
* @param {unknown | ObjectType} option - Option to check
|
|
80
66
|
* @returns {option is ObjectType} Whether the option is an object
|
|
81
67
|
*/
|
|
82
68
|
export function isObject<
|
|
83
|
-
ObjectType extends Partial<Record<keyof ObjectType, unknown
|
|
69
|
+
ObjectType extends Partial<Record<keyof ObjectType, unknown>>,
|
|
84
70
|
>(option: unknown | ObjectType): option is ObjectType;
|
|
85
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Check for valid scope
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
* @template {Element | Document} ScopeType
|
|
77
|
+
* @param {unknown | ScopeType} $scope - Scope of the document to search within
|
|
78
|
+
* @returns {$scope is ScopeType} Whether the scope can be queried
|
|
79
|
+
*/
|
|
80
|
+
export function isScope<ScopeType extends Element | Document>(
|
|
81
|
+
$scope: unknown | ScopeType,
|
|
82
|
+
): $scope is ScopeType;
|
|
83
|
+
|
|
86
84
|
/**
|
|
87
85
|
* Format error message
|
|
88
86
|
*
|
|
@@ -73,22 +73,22 @@ export class InitError extends GOVUKFrontendError {
|
|
|
73
73
|
*/
|
|
74
74
|
export interface ElementErrorOptions {
|
|
75
75
|
/**
|
|
76
|
-
* -
|
|
76
|
+
* - The element in error (optional)
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
element?: Document | Element | null | undefined;
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* -
|
|
81
|
+
* - Component throwing the error (optional)
|
|
82
82
|
*/
|
|
83
|
-
|
|
83
|
+
component?: ComponentWithModuleName | undefined;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* -
|
|
86
|
+
* - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense
|
|
87
87
|
*/
|
|
88
|
-
|
|
88
|
+
identifier: string;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* -
|
|
91
|
+
* - The type that was expected for the identifier (optional)
|
|
92
92
|
*/
|
|
93
|
-
|
|
93
|
+
expectedType?: string | undefined;
|
|
94
94
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { type AccordionConfig } from "./components/accordion/accordion.js";
|
|
2
|
-
import { type ButtonConfig } from "./components/button/button.js";
|
|
3
|
-
import { type CharacterCountConfig } from "./components/character-count/character-count.js";
|
|
4
|
-
import { type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
|
|
5
|
-
import { type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
|
|
6
|
-
import { type FileUploadConfig } from "./components/file-upload/file-upload.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { Accordion, type AccordionConfig } from "./components/accordion/accordion.js";
|
|
2
|
+
import { Button, type ButtonConfig } from "./components/button/button.js";
|
|
3
|
+
import { CharacterCount, type CharacterCountConfig } from "./components/character-count/character-count.js";
|
|
4
|
+
import { ErrorSummary, type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
|
|
5
|
+
import { ExitThisPage, type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
|
|
6
|
+
import { FileUpload, type FileUploadConfig } from "./components/file-upload/file-upload.js";
|
|
7
|
+
import {
|
|
8
|
+
NotificationBanner,
|
|
9
|
+
type NotificationBannerConfig,
|
|
10
|
+
} from "./components/notification-banner/notification-banner.js";
|
|
11
|
+
import { PasswordInput, type PasswordInputConfig } from "./components/password-input/password-input.js";
|
|
9
12
|
|
|
10
13
|
export interface CompatibleClass {
|
|
11
14
|
new(...args: any[]): any;
|
|
@@ -16,6 +19,28 @@ export interface CompatibleClass {
|
|
|
16
19
|
* Config for all components via `initAll()`
|
|
17
20
|
*/
|
|
18
21
|
export interface Config {
|
|
22
|
+
/**
|
|
23
|
+
* - Scope of the document to search within
|
|
24
|
+
*/
|
|
25
|
+
scope?: Document | Element | null | undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* - Initialisation error callback
|
|
29
|
+
*/
|
|
30
|
+
onError?:
|
|
31
|
+
| OnErrorCallback<
|
|
32
|
+
| typeof Accordion
|
|
33
|
+
| typeof Button
|
|
34
|
+
| typeof CharacterCount
|
|
35
|
+
| typeof ErrorSummary
|
|
36
|
+
| typeof ExitThisPage
|
|
37
|
+
| typeof FileUpload
|
|
38
|
+
| typeof NotificationBanner
|
|
39
|
+
| typeof PasswordInput
|
|
40
|
+
| undefined
|
|
41
|
+
>
|
|
42
|
+
| undefined;
|
|
43
|
+
|
|
19
44
|
/**
|
|
20
45
|
* - Accordion config
|
|
21
46
|
*/
|
|
@@ -60,15 +85,18 @@ export interface Config {
|
|
|
60
85
|
/**
|
|
61
86
|
* Component config keys, e.g. `accordion` and `characterCount`
|
|
62
87
|
*/
|
|
63
|
-
export type ConfigKey = keyof Config
|
|
88
|
+
export type ConfigKey = keyof Omit<Config, "scope" | "onError">;
|
|
64
89
|
|
|
65
90
|
export type ComponentConfig<ComponentClass extends CompatibleClass> = ConstructorParameters<ComponentClass>[1];
|
|
66
91
|
|
|
67
|
-
export interface ErrorContext<
|
|
92
|
+
export interface ErrorContext<
|
|
93
|
+
ComponentClass extends CompatibleClass | undefined = undefined,
|
|
94
|
+
> {
|
|
68
95
|
/**
|
|
69
96
|
* - Element used for component module initialisation
|
|
70
97
|
*/
|
|
71
|
-
element?:
|
|
98
|
+
element?: ComponentClass extends CompatibleClass ? Element
|
|
99
|
+
: undefined;
|
|
72
100
|
|
|
73
101
|
/**
|
|
74
102
|
* - Class of component
|
|
@@ -76,12 +104,15 @@ export interface ErrorContext<ComponentClass extends CompatibleClass> {
|
|
|
76
104
|
component?: ComponentClass | undefined;
|
|
77
105
|
|
|
78
106
|
/**
|
|
79
|
-
* - Config supplied to
|
|
107
|
+
* - Config supplied to components
|
|
80
108
|
*/
|
|
81
|
-
config
|
|
109
|
+
config?: ComponentClass extends CompatibleClass ? ComponentConfig<ComponentClass>
|
|
110
|
+
: Config;
|
|
82
111
|
}
|
|
83
112
|
|
|
84
|
-
export type OnErrorCallback<
|
|
113
|
+
export type OnErrorCallback<
|
|
114
|
+
ComponentClass extends CompatibleClass | undefined = undefined,
|
|
115
|
+
> = (
|
|
85
116
|
error: unknown,
|
|
86
117
|
context: ErrorContext<ComponentClass>,
|
|
87
118
|
) => any;
|
|
@@ -90,7 +121,7 @@ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
|
|
|
90
121
|
/**
|
|
91
122
|
* - scope of the document to search within
|
|
92
123
|
*/
|
|
93
|
-
scope?: Document | Element | undefined;
|
|
124
|
+
scope?: Document | Element | null | undefined;
|
|
94
125
|
|
|
95
126
|
/**
|
|
96
127
|
* - callback function if error throw by component on init
|
|
@@ -104,13 +135,10 @@ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
|
|
|
104
135
|
* Use the `data-module` attributes to find, instantiate and init all of the
|
|
105
136
|
* components provided as part of GOV.UK Frontend.
|
|
106
137
|
*
|
|
107
|
-
* @param {Config
|
|
138
|
+
* @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
|
|
108
139
|
*/
|
|
109
140
|
export function initAll(
|
|
110
|
-
|
|
111
|
-
scope?: Element;
|
|
112
|
-
onError?: OnErrorCallback<CompatibleClass>;
|
|
113
|
-
},
|
|
141
|
+
scopeOrConfig?: Config | Element | Document | null,
|
|
114
142
|
): void;
|
|
115
143
|
|
|
116
144
|
/**
|
|
@@ -125,15 +153,16 @@ export function initAll(
|
|
|
125
153
|
* @template {CompatibleClass} ComponentClass
|
|
126
154
|
* @param {ComponentClass} Component - class of the component to create
|
|
127
155
|
* @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
|
|
128
|
-
* @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass>
|
|
156
|
+
* @param {OnErrorCallback<ComponentClass> | Element | Document | null | CreateAllOptions<ComponentClass>} [scopeOrOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
|
|
129
157
|
* @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
|
|
130
158
|
*/
|
|
131
159
|
export function createAll<ComponentClass extends CompatibleClass>(
|
|
132
160
|
Component: ComponentClass,
|
|
133
161
|
config?: ComponentConfig<ComponentClass>,
|
|
134
|
-
|
|
162
|
+
scopeOrOptions?:
|
|
135
163
|
| OnErrorCallback<ComponentClass>
|
|
136
164
|
| Element
|
|
137
165
|
| Document
|
|
166
|
+
| null
|
|
138
167
|
| CreateAllOptions<ComponentClass>,
|
|
139
168
|
): Array<InstanceType<ComponentClass>>;
|
govuk-frontend/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/govuk-frontend",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.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",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"githubUsername": "colinrotherham",
|
|
11
11
|
"url": "https://github.com/colinrotherham"
|
|
12
12
|
},
|
|
13
|
+
{
|
|
14
|
+
"name": "Paul Robert Lloyd",
|
|
15
|
+
"githubUsername": "paulrobertlloyd",
|
|
16
|
+
"url": "https://github.com/paulrobertlloyd"
|
|
17
|
+
},
|
|
13
18
|
{
|
|
14
19
|
"name": "Romaric Pascal",
|
|
15
20
|
"githubUsername": "romaricpascal",
|
|
@@ -33,6 +38,6 @@
|
|
|
33
38
|
"scripts": {},
|
|
34
39
|
"dependencies": {},
|
|
35
40
|
"peerDependencies": {},
|
|
36
|
-
"typesPublisherContentHash": "
|
|
37
|
-
"typeScriptVersion": "5.
|
|
41
|
+
"typesPublisherContentHash": "33f390f9de3c3dfe7ef78c5fee7171a541a00aeecaedc5460d56c20acb614a45",
|
|
42
|
+
"typeScriptVersion": "5.2"
|
|
38
43
|
}
|