@ministryofjustice/frontend-types 1.0.0-alpha.1
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/CHANGELOG.md +8 -0
- package/LICENSE.md +21 -0
- package/README.md +57 -0
- package/dist/index.d.ts +242 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crown Copyright (Ministry of Justice)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @ministryofjustice/frontend-types
|
|
2
|
+
|
|
3
|
+
Provides typescript definitions as ambient modules for these client-side libraries/components:
|
|
4
|
+
|
|
5
|
+
- [GOV.UK frontend](https://design-system.service.gov.uk)
|
|
6
|
+
- [MoJ frontend](https://design-patterns.service.justice.gov.uk)
|
|
7
|
+
- [Accessible Autocomplete](https://github.com/alphagov/accessible-autocomplete)
|
|
8
|
+
|
|
9
|
+
## Status
|
|
10
|
+
|
|
11
|
+
**This library is currently: ready to trial.**
|
|
12
|
+
Teams are welcome to trial this library. Please provide feedback via slack to the `#typescript` channel.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Usage will be best demonstrated by the [HMPPS typescript template](https://github.com/ministryofjustice/hmpps-template-typescript)
|
|
17
|
+
once this package is published and [incorporated](https://github.com/ministryofjustice/hmpps-template-typescript/pull/681).
|
|
18
|
+
|
|
19
|
+
Note the `tsconfig.json` in the /assets/js folder, particularly the `lib` and `typeRoots` properties.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import * as govukFrontend from 'govuk-frontend'
|
|
23
|
+
import * as mojFrontend from '@ministryofjustice/frontend'
|
|
24
|
+
|
|
25
|
+
govukFrontend.initAll()
|
|
26
|
+
mojFrontend.initAll()
|
|
27
|
+
|
|
28
|
+
class MyPrintButton extends govukFrontend.Component {
|
|
29
|
+
static moduleName = 'my-print-btn'
|
|
30
|
+
|
|
31
|
+
constructor(root: HTMLElement) {
|
|
32
|
+
super(root)
|
|
33
|
+
root.addEventListener('click', event => {
|
|
34
|
+
event.preventDefault()
|
|
35
|
+
window.print()
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
govukFrontend.createAll(MyPrintLink)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<a href="#" data-module="my-print-link">Print</a>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Developing this package
|
|
48
|
+
|
|
49
|
+
Type definitions in the `src/@types` folder must be ambient typescript modules. All of these are concatenated into
|
|
50
|
+
one file during build; sources and tests are not included.
|
|
51
|
+
|
|
52
|
+
When adding or updating type defitions, the target version or version ranges should be updated
|
|
53
|
+
in the `peerDependencies` property in package.json. These peer dependencies should be marked as optional so that
|
|
54
|
+
client projects aren’t required to install them.
|
|
55
|
+
|
|
56
|
+
The `devDependencies` property should contain a precise version
|
|
57
|
+
(which is compatible with the peer dependency version ranges) so that this package can be tested in isolation.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GOV.UK Accessible Autocomplete types based on v3.0.1
|
|
3
|
+
* https://github.com/alphagov/accessible-autocomplete
|
|
4
|
+
*
|
|
5
|
+
* NB: this was recreated manually from javascript sources and may be incomplete!
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module 'accessible-autocomplete' {
|
|
9
|
+
type Source =
|
|
10
|
+
| string[]
|
|
11
|
+
| {
|
|
12
|
+
(query: string, populateResults: (options: string[]) => void): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Options {
|
|
16
|
+
element: HTMLElement
|
|
17
|
+
id: string
|
|
18
|
+
source: Source
|
|
19
|
+
inputClasses?: string | null
|
|
20
|
+
hintClasses?: string | null
|
|
21
|
+
menuAttributes?: DOMStringMap
|
|
22
|
+
menuClasses?: string | null
|
|
23
|
+
autoselect?: boolean
|
|
24
|
+
confirmOnBlur?: boolean
|
|
25
|
+
cssNamespace?: string
|
|
26
|
+
defaultValue?: string
|
|
27
|
+
displayMenu?: 'inline' | 'overlay'
|
|
28
|
+
minLength?: number
|
|
29
|
+
name?: string
|
|
30
|
+
onConfirm?: (confirmed: string) => void
|
|
31
|
+
placeholder?: string
|
|
32
|
+
required?: boolean
|
|
33
|
+
showAllValues?: boolean
|
|
34
|
+
showNoOptionsFound?: boolean
|
|
35
|
+
templates?: {
|
|
36
|
+
inputValue: (input: string) => string
|
|
37
|
+
suggestion: (input: string) => string
|
|
38
|
+
}
|
|
39
|
+
dropdownArrow?: (obj: { className: string }) => string
|
|
40
|
+
tNoResults?: () => string
|
|
41
|
+
tStatusQueryTooShort?: (chars: number) => string
|
|
42
|
+
tStatusNoResults?: () => string
|
|
43
|
+
tStatusSelectedOption?: (selectedOption: string, length: number, index: number) => string
|
|
44
|
+
tStatusResults?: (length: number, contentSelectedOption: string) => string
|
|
45
|
+
tAssistiveHint?: () => string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface EnhanceSelectOptions extends Omit<Partial<Options>, 'element'> {
|
|
49
|
+
selectElement: HTMLElement
|
|
50
|
+
preserveNullOptions?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface AccessibleAutocomplete {
|
|
54
|
+
(options: Options): void
|
|
55
|
+
|
|
56
|
+
enhanceSelectElement(options: EnhanceSelectOptions): void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const accessibleAutocomplete: AccessibleAutocomplete
|
|
60
|
+
|
|
61
|
+
export default accessibleAutocomplete
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* GOV.UK Frontend types based on v5.14.0
|
|
65
|
+
* https://github.com/alphagov/govuk-frontend
|
|
66
|
+
*
|
|
67
|
+
* NB: this was recreated manually from javascript sources and may be incomplete!
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line max-classes-per-file
|
|
71
|
+
declare module 'govuk-frontend' {
|
|
72
|
+
/** @since 5.7.0 */
|
|
73
|
+
export abstract class Component<RootElement extends HTMLElement = HTMLElement> {
|
|
74
|
+
static checkSupport(): void
|
|
75
|
+
|
|
76
|
+
static moduleName: string
|
|
77
|
+
|
|
78
|
+
// technically `typeof RootElement`, but static properties cannot refer to generic parameters
|
|
79
|
+
static elementType: typeof HTMLElement
|
|
80
|
+
|
|
81
|
+
constructor($root: RootElement)
|
|
82
|
+
|
|
83
|
+
/** Returns the root element of the component */
|
|
84
|
+
get $root(): RootElement
|
|
85
|
+
|
|
86
|
+
checkInitialised(): void
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const configOverride: unique symbol
|
|
90
|
+
|
|
91
|
+
interface SchemaProperty {
|
|
92
|
+
type: 'string' | 'boolean' | 'number' | 'object'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface Schema {
|
|
96
|
+
properties: Record<string, SchemaProperty | undefined>
|
|
97
|
+
anyOf?: { required: string[]; errorMessage: string }[]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type ObjectNested = {
|
|
101
|
+
[key: string]: string | boolean | number | ObjectNested | undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @since 5.8.0 */
|
|
105
|
+
export abstract class ConfigurableComponent<
|
|
106
|
+
RootElement extends HTMLElement = HTMLElement,
|
|
107
|
+
Config = Record<string, string | boolean | number>,
|
|
108
|
+
> extends Component<RootElement> {
|
|
109
|
+
// technically types of `schema` and `defaults` should be strongly tied to `Config`,
|
|
110
|
+
// but static properties cannot refer to generic parameters
|
|
111
|
+
static schema: Schema
|
|
112
|
+
|
|
113
|
+
static defaults: ObjectNested
|
|
114
|
+
|
|
115
|
+
constructor($root: RootElement, config: Config)
|
|
116
|
+
|
|
117
|
+
[configOverride](datasetConfig: Partial<Config>): object
|
|
118
|
+
|
|
119
|
+
get config(): Config
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @since 5.0.0 */
|
|
123
|
+
export class Accordion extends ConfigurableComponent {}
|
|
124
|
+
/** @since 5.0.0 */
|
|
125
|
+
export class Button extends ConfigurableComponent {}
|
|
126
|
+
/** @since 5.0.0 */
|
|
127
|
+
export class CharacterCount extends ConfigurableComponent {}
|
|
128
|
+
/** @since 5.0.0 */
|
|
129
|
+
export class Checkboxes extends Component {}
|
|
130
|
+
/** @since 5.0.0 */
|
|
131
|
+
export class ErrorSummary extends ConfigurableComponent {}
|
|
132
|
+
/** @since 5.0.0 */
|
|
133
|
+
export class ExitThisPage extends ConfigurableComponent {}
|
|
134
|
+
/** @since 5.9.0 */
|
|
135
|
+
export class FileUpload extends ConfigurableComponent {}
|
|
136
|
+
/**
|
|
137
|
+
* NB: removed in 6.0.0
|
|
138
|
+
* @since 5.0.0
|
|
139
|
+
*/
|
|
140
|
+
export class Header extends Component {}
|
|
141
|
+
/** @since 5.0.0 */
|
|
142
|
+
export class NotificationBanner extends ConfigurableComponent {}
|
|
143
|
+
/** @since 5.3.0 */
|
|
144
|
+
export class PasswordInput extends ConfigurableComponent {}
|
|
145
|
+
/** @since 5.0.0 */
|
|
146
|
+
export class Radios extends Component {}
|
|
147
|
+
/** @since 5.6.0 */
|
|
148
|
+
export class ServiceNavigation extends Component {}
|
|
149
|
+
/** @since 5.0.0 */
|
|
150
|
+
export class SkipLink extends Component<HTMLAnchorElement> {}
|
|
151
|
+
/** @since 5.0.0 */
|
|
152
|
+
export class Tabs extends Component {}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Checks if GOV.UK Frontend is supported on this page
|
|
156
|
+
*
|
|
157
|
+
* Some browsers will load and run our JavaScript but GOV.UK Frontend
|
|
158
|
+
* won't be supported.
|
|
159
|
+
*
|
|
160
|
+
* @since 5.7.0
|
|
161
|
+
*/
|
|
162
|
+
export function isSupported(scope?: HTMLElement): boolean
|
|
163
|
+
|
|
164
|
+
interface ErrorContext {
|
|
165
|
+
config: Record<string, string | boolean | number>
|
|
166
|
+
component?: Component
|
|
167
|
+
element?: HTMLElement
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface ErrorCallback {
|
|
171
|
+
onError: (error: Error, context: ErrorContext) => void
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface InitAllOptions {
|
|
175
|
+
scope?: HTMLElement | Document
|
|
176
|
+
/** @since 5.7.0 */
|
|
177
|
+
onError?: ErrorCallback
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Initialise all components
|
|
182
|
+
*
|
|
183
|
+
* Use the `data-module` attributes to find, instantiate and init all of the
|
|
184
|
+
* components provided as part of GOV.UK Frontend.
|
|
185
|
+
*
|
|
186
|
+
* @since 5.0.0
|
|
187
|
+
*/
|
|
188
|
+
export function initAll(config?: InitAllOptions): void
|
|
189
|
+
|
|
190
|
+
type CreateAllOptions = InitAllOptions | HTMLElement | Document | ErrorCallback
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Create all instances of a specific component on the page
|
|
194
|
+
*
|
|
195
|
+
* Uses the `data-module` attribute to find all elements matching the specified
|
|
196
|
+
* component on the page, creating instances of the component object for each
|
|
197
|
+
* of them.
|
|
198
|
+
*
|
|
199
|
+
* Any component errors will be caught and logged to the console.
|
|
200
|
+
*
|
|
201
|
+
* @since 5.4.0
|
|
202
|
+
*/
|
|
203
|
+
export function createAll<
|
|
204
|
+
E extends HTMLElement,
|
|
205
|
+
C extends Component<E>,
|
|
206
|
+
Class extends { new (element: never, config: never): C },
|
|
207
|
+
>(component: Class, config?: ConstructorParameters<Class>[1]): void
|
|
208
|
+
|
|
209
|
+
/** @since 5.0.0 */
|
|
210
|
+
export const version: string
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* MoJ Frontend types based on v8.0.1
|
|
214
|
+
* https://github.com/ministryofjustice/moj-frontend
|
|
215
|
+
*
|
|
216
|
+
* NB: this was recreated manually from javascript sources and may be incomplete!
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
// eslint-disable-next-line max-classes-per-file
|
|
220
|
+
declare module '@ministryofjustice/frontend' {
|
|
221
|
+
import type { Component, ConfigurableComponent, CreateAllOptions } from 'govuk-frontend'
|
|
222
|
+
|
|
223
|
+
export function initAll(scopeOrConfig?: CreateAllOptions): void
|
|
224
|
+
|
|
225
|
+
export class AddAnother extends Component {}
|
|
226
|
+
export class Alert extends ConfigurableComponent {}
|
|
227
|
+
export class ButtonMenu extends ConfigurableComponent {}
|
|
228
|
+
export class DatePicker extends ConfigurableComponent {}
|
|
229
|
+
export class MultiSelect extends ConfigurableComponent {}
|
|
230
|
+
export class PasswordReveal extends Component {}
|
|
231
|
+
export class PdsHeader extends Component {}
|
|
232
|
+
export class RichTextEditor extends ConfigurableComponent {}
|
|
233
|
+
export class SearchToggle extends ConfigurableComponent {}
|
|
234
|
+
export class SortableTable extends ConfigurableComponent {}
|
|
235
|
+
|
|
236
|
+
// these components don’t seem to get initialised by initAll
|
|
237
|
+
export class FilterToggleButton extends ConfigurableComponent {}
|
|
238
|
+
export class FormValidator extends ConfigurableComponent {}
|
|
239
|
+
export class MultiFileUpload extends ConfigurableComponent {}
|
|
240
|
+
|
|
241
|
+
export const version: string
|
|
242
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ministryofjustice/frontend-types",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "hmpps-developers",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/ministryofjustice/hmpps-typescript-lib#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ministryofjustice/hmpps-typescript-lib.git"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"tag": "latest"
|
|
15
|
+
},
|
|
16
|
+
"main": "",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"*.md",
|
|
20
|
+
"dist/**/*"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": "20 || 22 || 24"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "mkdir -p ./dist && cat ./src/@types/*.d.ts > ./dist/index.d.ts",
|
|
27
|
+
"clean": "rm -rf ./dist/",
|
|
28
|
+
"test": "tsc",
|
|
29
|
+
"lint": "eslint src --cache --max-warnings 0",
|
|
30
|
+
"lint-fix": "eslint src --cache --max-warnings 0 --fix",
|
|
31
|
+
"check-for-updates": "npx npm-check-updates -u"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@ministryofjustice/frontend": "8.0.1",
|
|
35
|
+
"accessible-autocomplete": "3.0.1",
|
|
36
|
+
"govuk-frontend": "5.14.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@ministryofjustice/frontend": "6 || 7 || 8 || 9",
|
|
40
|
+
"accessible-autocomplete": "3",
|
|
41
|
+
"govuk-frontend": "5 || 6.0.x"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@ministryofjustice/frontend": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"accessible-autocomplete": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"govuk-frontend": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|