@hmlr/govuk-react-components-library 1.0.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.
Files changed (203) hide show
  1. package/.nvmrc +1 -0
  2. package/.stylelintrc.json +8 -0
  3. package/LICENCE +21 -0
  4. package/README.md +636 -0
  5. package/assets/Advance-submodule-behaviours.png +0 -0
  6. package/assets/logo.png +0 -0
  7. package/assets/uml-diagram.svg +2541 -0
  8. package/bundle-analysis-main.html +4951 -0
  9. package/bundle-analysis-pdfvc.html +4949 -0
  10. package/dist/PDFViewerCanvas.cjs.css +86 -0
  11. package/dist/PDFViewerCanvas.cjs.js +243 -0
  12. package/dist/PDFViewerCanvas.cjs.js.map +1 -0
  13. package/dist/PDFViewerCanvas.d.ts +19 -0
  14. package/dist/PDFViewerCanvas.esm.css +86 -0
  15. package/dist/PDFViewerCanvas.esm.js +241 -0
  16. package/dist/PDFViewerCanvas.esm.js.map +1 -0
  17. package/dist/index.cjs.css +11962 -0
  18. package/dist/index.cjs.js +1362 -0
  19. package/dist/index.cjs.js.map +1 -0
  20. package/dist/index.d.ts +743 -0
  21. package/dist/index.esm.css +11962 -0
  22. package/dist/index.esm.js +1284 -0
  23. package/dist/index.esm.js.map +1 -0
  24. package/dist/types/JestSetup.d.ts +1 -0
  25. package/dist/types/PDFViewerCanvas.d.ts +1 -0
  26. package/dist/types/components/Accordion/Accordion.config.d.ts +5 -0
  27. package/dist/types/components/Accordion/Accordion.d.ts +4 -0
  28. package/dist/types/components/Accordion/Accordion.types.d.ts +20 -0
  29. package/dist/types/components/Accordion/index.d.ts +2 -0
  30. package/dist/types/components/ActionLink/ActionLink.d.ts +4 -0
  31. package/dist/types/components/ActionLink/ActionLink.types.d.ts +13 -0
  32. package/dist/types/components/ActionLink/index.d.ts +1 -0
  33. package/dist/types/components/BackLink/BackLink.d.ts +4 -0
  34. package/dist/types/components/BackLink/BackLink.types.d.ts +9 -0
  35. package/dist/types/components/BackLink/index.d.ts +1 -0
  36. package/dist/types/components/Boolean/Boolean.d.ts +4 -0
  37. package/dist/types/components/Boolean/Boolean.types.d.ts +39 -0
  38. package/dist/types/components/Boolean/OmitKey.d.ts +5 -0
  39. package/dist/types/components/Boolean/index.d.ts +1 -0
  40. package/dist/types/components/Breadcrumbs/Breadcrumbs.d.ts +4 -0
  41. package/dist/types/components/Breadcrumbs/Breadcrumbs.types.d.ts +13 -0
  42. package/dist/types/components/Breadcrumbs/index.d.ts +1 -0
  43. package/dist/types/components/Button/Button.config.d.ts +2 -0
  44. package/dist/types/components/Button/Button.d.ts +4 -0
  45. package/dist/types/components/Button/Button.types.d.ts +13 -0
  46. package/dist/types/components/Button/index.d.ts +2 -0
  47. package/dist/types/components/CardColumn/CardColumn.d.ts +5 -0
  48. package/dist/types/components/CardColumn/CardColumn.types.d.ts +5 -0
  49. package/dist/types/components/CardColumn/index.d.ts +1 -0
  50. package/dist/types/components/CardLayout/CardLayout.d.ts +4 -0
  51. package/dist/types/components/CardLayout/CardLayout.types.d.ts +5 -0
  52. package/dist/types/components/CardLayout/index.d.ts +1 -0
  53. package/dist/types/components/CharacterCount/CharacterCount.config.d.ts +2 -0
  54. package/dist/types/components/CharacterCount/CharacterCount.d.ts +4 -0
  55. package/dist/types/components/CharacterCount/CharacterCount.types.d.ts +12 -0
  56. package/dist/types/components/CharacterCount/index.d.ts +1 -0
  57. package/dist/types/components/Checkboxes/Checkboxes.config.d.ts +1 -0
  58. package/dist/types/components/Checkboxes/Checkboxes.d.ts +4 -0
  59. package/dist/types/components/Checkboxes/Checkboxes.types.d.ts +3 -0
  60. package/dist/types/components/Checkboxes/index.d.ts +2 -0
  61. package/dist/types/components/CookieBanner/CookieBanner.d.ts +4 -0
  62. package/dist/types/components/CookieBanner/CookieBanner.types.d.ts +21 -0
  63. package/dist/types/components/CookieBanner/index.d.ts +1 -0
  64. package/dist/types/components/DataNavigation/DataNavigation.d.ts +4 -0
  65. package/dist/types/components/DataNavigation/DataNavigation.types.d.ts +9 -0
  66. package/dist/types/components/DataNavigation/index.d.ts +1 -0
  67. package/dist/types/components/DateInput/DateInput.d.ts +4 -0
  68. package/dist/types/components/DateInput/DateInput.types.d.ts +29 -0
  69. package/dist/types/components/DateInput/index.d.ts +1 -0
  70. package/dist/types/components/Details/Details.d.ts +4 -0
  71. package/dist/types/components/Details/Details.types.d.ts +5 -0
  72. package/dist/types/components/Details/index.d.ts +1 -0
  73. package/dist/types/components/DifferenceNavigation/DifferenceNavigation.d.ts +4 -0
  74. package/dist/types/components/DifferenceNavigation/DifferenceNavigation.types.d.ts +7 -0
  75. package/dist/types/components/DifferenceNavigation/index.d.ts +1 -0
  76. package/dist/types/components/ErrorBoundary/ErrorBoundary.d.ts +9 -0
  77. package/dist/types/components/ErrorBoundary/ErrorBoundary.types.d.ts +11 -0
  78. package/dist/types/components/ErrorBoundary/index.d.ts +1 -0
  79. package/dist/types/components/ErrorMessage/ErrorMessage.d.ts +4 -0
  80. package/dist/types/components/ErrorMessage/ErrorMessage.types.d.ts +6 -0
  81. package/dist/types/components/ErrorMessage/index.d.ts +1 -0
  82. package/dist/types/components/ErrorSummary/ErrorSummary.config.d.ts +2 -0
  83. package/dist/types/components/ErrorSummary/ErrorSummary.d.ts +4 -0
  84. package/dist/types/components/ErrorSummary/ErrorSummary.types.d.ts +13 -0
  85. package/dist/types/components/ErrorSummary/index.d.ts +2 -0
  86. package/dist/types/components/Fieldset/Fieldset.d.ts +4 -0
  87. package/dist/types/components/Fieldset/Fieldset.types.d.ts +12 -0
  88. package/dist/types/components/Fieldset/index.d.ts +1 -0
  89. package/dist/types/components/FileUpload/FileUpload.d.ts +4 -0
  90. package/dist/types/components/FileUpload/FileUpload.types.d.ts +15 -0
  91. package/dist/types/components/FileUpload/index.d.ts +1 -0
  92. package/dist/types/components/Footer/Footer.d.ts +4 -0
  93. package/dist/types/components/Footer/Footer.types.d.ts +33 -0
  94. package/dist/types/components/Footer/index.d.ts +1 -0
  95. package/dist/types/components/Header/Header.config.d.ts +1 -0
  96. package/dist/types/components/Header/Header.d.ts +4 -0
  97. package/dist/types/components/Header/Header.types.d.ts +28 -0
  98. package/dist/types/components/Header/index.d.ts +2 -0
  99. package/dist/types/components/Hint/Hint.d.ts +4 -0
  100. package/dist/types/components/Hint/Hint.types.d.ts +4 -0
  101. package/dist/types/components/Hint/index.d.ts +1 -0
  102. package/dist/types/components/Input/Input.d.ts +4 -0
  103. package/dist/types/components/Input/Input.types.d.ts +22 -0
  104. package/dist/types/components/Input/index.d.ts +1 -0
  105. package/dist/types/components/InsetText/InsetText.d.ts +4 -0
  106. package/dist/types/components/InsetText/InsetText.types.d.ts +4 -0
  107. package/dist/types/components/InsetText/index.d.ts +1 -0
  108. package/dist/types/components/Label/Label.d.ts +4 -0
  109. package/dist/types/components/Label/Label.types.d.ts +6 -0
  110. package/dist/types/components/Label/index.d.ts +1 -0
  111. package/dist/types/components/Landing/Landing.d.ts +4 -0
  112. package/dist/types/components/Landing/Landing.types.d.ts +4 -0
  113. package/dist/types/components/Landing/index.d.ts +1 -0
  114. package/dist/types/components/LinkWithRef/LinkWithRef.d.ts +4 -0
  115. package/dist/types/components/LinkWithRef/LinkWithRef.types.d.ts +9 -0
  116. package/dist/types/components/LinkWithRef/index.d.ts +1 -0
  117. package/dist/types/components/Loading/Loading.d.ts +5 -0
  118. package/dist/types/components/Loading/Loading.types.d.ts +4 -0
  119. package/dist/types/components/Loading/index.d.ts +1 -0
  120. package/dist/types/components/Main/Main.d.ts +4 -0
  121. package/dist/types/components/Main/Main.types.d.ts +5 -0
  122. package/dist/types/components/Main/index.d.ts +1 -0
  123. package/dist/types/components/NotFoundPage/NotFoundPage.d.ts +3 -0
  124. package/dist/types/components/NotFoundPage/index.d.ts +1 -0
  125. package/dist/types/components/NotificationBanner/NotificationBanner.config.d.ts +2 -0
  126. package/dist/types/components/NotificationBanner/NotificationBanner.d.ts +4 -0
  127. package/dist/types/components/NotificationBanner/NotificationBanner.types.d.ts +12 -0
  128. package/dist/types/components/NotificationBanner/index.d.ts +1 -0
  129. package/dist/types/components/PDFViewer/ObjectToQueryString.d.ts +1 -0
  130. package/dist/types/components/PDFViewer/PDFViewer.d.ts +4 -0
  131. package/dist/types/components/PDFViewer/PDFViewer.types.d.ts +25 -0
  132. package/dist/types/components/PDFViewer/PDFViewerBackend.d.ts +2 -0
  133. package/dist/types/components/PDFViewer/ResolvePDFSource.d.ts +4 -0
  134. package/dist/types/components/PDFViewer/Slugify.d.ts +1 -0
  135. package/dist/types/components/PDFViewer/index.d.ts +2 -0
  136. package/dist/types/components/PDFViewer/testutilities/SampleBase64.d.ts +44 -0
  137. package/dist/types/components/PDFViewerCanvas/PDFViewerCanvas.d.ts +9 -0
  138. package/dist/types/components/PDFViewerCanvas/PDFViewerCanvas.types.d.ts +8 -0
  139. package/dist/types/components/PDFViewerCanvas/index.d.ts +1 -0
  140. package/dist/types/components/Pagination/NavigationButton.d.ts +3 -0
  141. package/dist/types/components/Pagination/Pagination.d.ts +4 -0
  142. package/dist/types/components/Pagination/Pagination.types.d.ts +22 -0
  143. package/dist/types/components/Pagination/SvgIcon.d.ts +3 -0
  144. package/dist/types/components/Pagination/UsePagination.d.ts +9 -0
  145. package/dist/types/components/Pagination/index.d.ts +1 -0
  146. package/dist/types/components/Panel/Panel.d.ts +4 -0
  147. package/dist/types/components/Panel/Panel.types.d.ts +7 -0
  148. package/dist/types/components/Panel/index.d.ts +1 -0
  149. package/dist/types/components/PhaseBanner/PhaseBanner.d.ts +4 -0
  150. package/dist/types/components/PhaseBanner/PhaseBanner.types.d.ts +6 -0
  151. package/dist/types/components/PhaseBanner/index.d.ts +1 -0
  152. package/dist/types/components/ProblemWithService/ProblemWithService.d.ts +4 -0
  153. package/dist/types/components/ProblemWithService/ProblemWithService.types.d.ts +7 -0
  154. package/dist/types/components/ProblemWithService/index.d.ts +1 -0
  155. package/dist/types/components/Radios/Radios.config.d.ts +1 -0
  156. package/dist/types/components/Radios/Radios.d.ts +4 -0
  157. package/dist/types/components/Radios/Radios.types.d.ts +7 -0
  158. package/dist/types/components/Radios/index.d.ts +2 -0
  159. package/dist/types/components/Select/Select.d.ts +4 -0
  160. package/dist/types/components/Select/Select.types.d.ts +21 -0
  161. package/dist/types/components/Select/index.d.ts +1 -0
  162. package/dist/types/components/ServiceNavigation/ServiceNavigation.d.ts +4 -0
  163. package/dist/types/components/ServiceNavigation/ServiceNavigation.types.d.ts +21 -0
  164. package/dist/types/components/ServiceNavigation/index.d.ts +1 -0
  165. package/dist/types/components/SkipLink/SkipLink.config.d.ts +1 -0
  166. package/dist/types/components/SkipLink/SkipLink.d.ts +4 -0
  167. package/dist/types/components/SkipLink/SkipLink.types.d.ts +5 -0
  168. package/dist/types/components/SkipLink/index.d.ts +2 -0
  169. package/dist/types/components/SummaryList/SummaryList.d.ts +4 -0
  170. package/dist/types/components/SummaryList/SummaryList.types.d.ts +22 -0
  171. package/dist/types/components/SummaryList/index.d.ts +1 -0
  172. package/dist/types/components/Table/Table.d.ts +4 -0
  173. package/dist/types/components/Table/Table.types.d.ts +21 -0
  174. package/dist/types/components/Table/index.d.ts +1 -0
  175. package/dist/types/components/Tabs/Tabs.config.d.ts +1 -0
  176. package/dist/types/components/Tabs/Tabs.d.ts +4 -0
  177. package/dist/types/components/Tabs/Tabs.types.d.ts +14 -0
  178. package/dist/types/components/Tabs/index.d.ts +2 -0
  179. package/dist/types/components/Tag/Tag.d.ts +4 -0
  180. package/dist/types/components/Tag/Tag.types.d.ts +4 -0
  181. package/dist/types/components/Tag/index.d.ts +1 -0
  182. package/dist/types/components/TaskList/TaskList.d.ts +4 -0
  183. package/dist/types/components/TaskList/TaskList.types.d.ts +21 -0
  184. package/dist/types/components/TaskList/index.d.ts +1 -0
  185. package/dist/types/components/Textarea/Textarea.d.ts +4 -0
  186. package/dist/types/components/Textarea/Textarea.types.d.ts +14 -0
  187. package/dist/types/components/Textarea/index.d.ts +1 -0
  188. package/dist/types/components/WarningInfo/WarningInfo.d.ts +4 -0
  189. package/dist/types/components/WarningInfo/WarningInfo.types.d.ts +8 -0
  190. package/dist/types/components/WarningInfo/index.d.ts +1 -0
  191. package/dist/types/components/WarningText/WarningText.d.ts +4 -0
  192. package/dist/types/components/WarningText/WarningText.types.d.ts +4 -0
  193. package/dist/types/components/WarningText/index.d.ts +1 -0
  194. package/dist/types/components/index.d.ts +49 -0
  195. package/dist/types/dynamics/index.d.ts +3 -0
  196. package/dist/types/dynamics/types.d.ts +37 -0
  197. package/dist/types/index.d.ts +1 -0
  198. package/dist/types/utils/ProcessExampleData.d.ts +3 -0
  199. package/dist/types/utils/StoriesFromFixtures.d.ts +5 -0
  200. package/dist/types/utils/TitleCase.d.ts +2 -0
  201. package/dist/types/utils/WithReference.d.ts +5 -0
  202. package/dist/types/utils/WithReference.types.d.ts +10 -0
  203. package/package.json +180 -0
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ lts/jod
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": [
3
+ "stylelint-config-standard",
4
+ "stylelint-config-standard-scss",
5
+ "stylelint-config-idiomatic-order"
6
+ ],
7
+ "plugins": ["stylelint-order"]
8
+ }
package/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Crown Copyright (HM Land Registry)
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,636 @@
1
+ # GOVUK React Components Library
2
+
3
+ [![Latest release](https://img.shields.io/github/v/release/LandRegistry/govuk-react-components-library?style=flat-square&logo=github&logoColor=white&sort=semver)](https://github.com/LandRegistry/govuk-react-components-library/releases)
4
+ [![NPM version](https://img.shields.io/npm/v/@hmlr/govuk-react-components-library?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@hmlr/govuk-react-components-library)
5
+ [![GOV.UK Frontend version](https://img.shields.io/npm/dependency-version/@hmlr/govuk-react-components-library/govuk-frontend?style=flat-square)](https://www.npmjs.com/package/govuk-frontend)
6
+ [![Node version](https://img.shields.io/node/v-lts/@hmlr/govuk-react-components-library?style=flat-square&logo=nodedotjs&logoColor=white)](https://github.com/LandRegistry/govuk-react-components-library/blob/main/.nvmrc)
7
+ [![Licence](https://img.shields.io/github/license/LandRegistry/govuk-react-components-library?style=flat-square)](https://github.com/LandRegistry/govuk-react-components-library/blob/main/LICENCE)
8
+
9
+ This project is a collection of React components built based on [GDS Specifications](https://design-system.service.gov.uk/get-started/production/). The components are designed to be reused by applications, with a focus on providing consistent and accessible user experiences. The components are based on the [govuk-frontend](https://frontend.design-system.service.gov.uk/) library, ensuring compatibility and adherence to the UK Government's digital design standards.
10
+
11
+ **Disclaimer**
12
+
13
+ :warning: **This project is not officially supported by the Government Digital Service (GDS). It is maintained on a best-efforts basis by the HM Land Registry (HMLR) only. While we strive to ensure the accuracy and reliability of the code, we cannot guarantee its full compliance with GDS standards or the availability of ongoing support.**
14
+
15
+ ## Installation
16
+
17
+ Then install this component library:
18
+
19
+ ```bash
20
+ npm install @hmlr/govuk-react-components-library
21
+ ```
22
+
23
+ ## Components
24
+
25
+ Note that any component with a `- ***` below means that - This component may javascript to be enabled because of the transitions present in the components using `createAll` or `initAll` recommended by [`govuk-frontend` documentation](https://frontend.design-system.service.gov.uk/configure-components/)
26
+
27
+ The Components includes:
28
+
29
+ - [Accordion](./src/components/Accordion/Accordion.tsx) `- ***`
30
+ - [Boolean](./src/components/Boolean/Boolean.tsx)
31
+ - [Breadcrumbs](./src/components/Breadcrumbs/Breadcrumbs.tsx)
32
+ - [Button](./src/components/Button/Button.tsx) `- ***`
33
+ - [CharacterCount](./src/components/CharacterCount/CharacterCount.tsx)
34
+ - [CheckBoxes](./src/components/Checkboxes/Checkboxes.tsx) `- ***`
35
+ - [CookieBanner](./src/components/CookieBanner/CookieBanner.tsx)
36
+ - [DateInput](./src/components/DateInput/DateInput.tsx)
37
+ - [Details](./src/components/Details/Details.tsx)
38
+ - [ErrorMessage](./src/components/ErrorMessage/ErrorMessage.tsx)
39
+ - [ErrorSummary](./src/components/ErrorSummary/ErrorSummary.tsx) `- ***`
40
+ - [Fieldset](./src/components/Fieldset/Fieldset.tsx)
41
+ - [FileUpload](./src/components/FileUpload/FileUpload.tsx)
42
+ - [Footer](./src/components/Footer/Footer.tsx)
43
+ - [Header](./src/components/Header/Header.tsx) `- ***`
44
+ - [Hint](./src/components/Hint/Hint.tsx)
45
+ - [Input](./src/components/Input/Input.tsx)
46
+ - [InsetText](./src/components/InsetText/InsetText.tsx)
47
+ - [Label](./src/components/Label/Label.tsx)
48
+ - [NotificationBanner](./src/components/NotificationBanner/NotificationBanner.tsx)
49
+ - [Pagination](./src/components/Pagination/Pagination.tsx)
50
+ - [Panel](./src/components/Panel/Panel.tsx)
51
+ - [PhaseBanner](./src/components/PhaseBanner/PhaseBanner.tsx)
52
+ - [Radios](./src/components/Radios/Radios.tsx) `- ***`
53
+ - [Select](./src/components/Select/Select.tsx)
54
+ - [ServiceNavigation](./src/components/ServiceNavigation/ServiceNavigation.tsx)
55
+ - [SkipLink](./src/components/SkipLink/SkipLink.tsx) `- ***`
56
+ - [SummaryList](./src/components/SummaryList/SummaryList.tsx)
57
+ - [Table](./src/components/Table/Table.tsx)
58
+ - [Tabs](./src/components/Tabs/Tabs.tsx) `- ***`
59
+ - [Tag](./src/components/Tag/Tag.tsx)
60
+ - [TaskList](./src/components/TaskList/TaskList.tsx)
61
+ - [Textarea](./src/components/Textarea/Textarea.tsx)
62
+ - [WarningText](./src/components/WarningText/WarningText.tsx)
63
+
64
+ There are Also Several components that can be used for error processing and other functionality like dashboard display:
65
+ Note that some of the components below with `- ***` - Means like the above components, javascript needs to be enabled.
66
+
67
+ - [CardColumn](./src/components/CardColumn/CardColumn.tsx)
68
+ - [CardLayout](./src/components/CardLayout/CardLayout.tsx)
69
+ - [DataNavigation](./src/components/DataNavigation/DataNavigation.tsx)
70
+ - [DifferenceNavigation](./src/components/DifferenceNavigation/DifferenceNavigation.tsx) - Read [Documentation](./src/components/DifferenceNavigation/README.md) to see usage
71
+ - [ErrorBoundary](./src/components/ErrorBoundary/ErrorBoundary.tsx)
72
+ - [Landing](./src/components/Landing/Landing.tsx)
73
+ - [Loading](./src/components/Loading/Loading.tsx)
74
+ - [Main](./src/components/Main/Main.tsx)
75
+ - [NotFoundPage](./src/components/NotFoundPage/NotFoundPage.tsx)
76
+ - [PDFViewer](./src/components/PDFViewer/PDFViewer.tsx)
77
+ - [PDFViewerCanvas](./src/components/PDFViewerCanvas/PDFViewerCanvas.tsx) - Read [Documentation](./src/components/PDFViewerCanvas/README.md) to see usage
78
+ - [ProblemWithService](./src/components/ProblemWithService/ProblemWithService.tsx) `- ***` - `createAll(ErrorSummary..)` or `ConfigureOverallErrorSummary()`
79
+ - [WarningInfo](./src/components/WarningInfo//WarningInfo.tsx)
80
+
81
+ There are also some useful components :
82
+
83
+ - [ActionLink](./src/components/ActionLink/ActionLink.tsx)
84
+ - [BackLink](./src/components/BackLink/BackLink.tsx)
85
+ - [LinkWithRef](./src/components/LinkWithRef/LinkWithRef.tsx)
86
+ - [Loading](./src/components/Loading/Loading.tsx)
87
+ - [Main](./src/components/Main/Main.tsx)
88
+
89
+ There are some convenience functions that can be used to configure components with `- ***` mentioned above.
90
+
91
+ - [ExtractAccordionConfigFromAttributes](./src/components/Accordion/Accordion.config.tsx) - Extracts Accordion configurations from fixtures attributes e.g. `showAllSectionsText` translates to `showAllSections` in `AccordionConfig`.
92
+ - [ConfigureOverallAccordion](./src/components/Accordion/Accordion.config.tsx) - Sets overall behavior and configurations for all accordions or in a scope (document or specified element) as per [govuk-frontend accordion api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#accordion).
93
+ - [ConfigureOverallButton](./src/components/Button/Button.config.tsx) - Sets overall behavior and configurations for all button or in a scope (document or specified element) as per [govuk-frontend button api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#button).
94
+ - [ConfigureOverallCheckboxes](./src/components/Checkboxes/Checkboxes.config.tsx) - Sets overall behavior and configurations for all checkboxes or in a scope.
95
+ - [ConfigureOverallErrorSummary](./src/components/ErrorSummary/ErrorSummary.config.tsx) - Sets overall behavior and configurations for all error summary or in a scope (document or specified element) as per [govuk-frontend error-summary api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#errorsummary).
96
+ - [ConfigureOverallHeader](./src/components/Header/Header.config.tsx) - Sets overall behavior and configurations for all Header or in a scope.
97
+ - [ConfigureOverallRadios](./src/components/Radios/Radios.config.tsx) - Sets overall behavior and configurations for all Radios or in a scope.
98
+ - [ConfigureOverallSkipLink](./src/components/SkipLink/SkipLink.config.tsx) - Sets overall behavior and configurations for all SkipLink or in a scope.
99
+ - [ConfigureOverallTabs](./src/components/Tabs/Tabs.config.tsx) - Sets overall behavior and configurations for all Tabs or in a scope.
100
+
101
+ Here are some examples of the above convenient configurations functions:
102
+
103
+ <details>
104
+ <summary>Scoped Accordion Configuration Example</summary>
105
+
106
+ ```javascript
107
+ // in scope accordion configuration
108
+ import React, { useEffect } from "react";
109
+ import {
110
+ ConfigureOverallAccordion,
111
+ ExtractAccordionConfigFromAttributes,
112
+ } from "@hmlr/govuk-react-components-library";
113
+
114
+ function App() {
115
+ useEffect(() => {
116
+ const attributes = {
117
+ hideAllSectionsText: "Collapse all sections",
118
+ showAllSectionsText: "Expand all sections",
119
+ hideSectionText: "Collapse",
120
+ hideSectionAriaLabelText: "Collapse this section",
121
+ showSectionText: "Expand",
122
+ showSectionAriaLabelText: "Expand this section",
123
+ };
124
+ const accordionConfig = ExtractAccordionConfigFromAttributes(attributes);
125
+ const $element = document.querySelector(".govuk-accordion");
126
+ ConfigureOverallAccordion($element, accordionConfig);
127
+ }, []);
128
+
129
+ return (
130
+ <Accordion
131
+ id="default-example"
132
+ items={[
133
+ {
134
+ content: {
135
+ children:
136
+ "We need to know your nationality so we can work out which elections you’re entitled to vote in. If you cannot provide your nationality, you’ll have to send copies of identity documents through the post.",
137
+ },
138
+ heading: {
139
+ children: "Section A",
140
+ },
141
+ },
142
+ {
143
+ content: {
144
+ children: [
145
+ <ul key="0" className="govuk-list govuk-list--bullet">
146
+ {""}
147
+ <li>Example item 2</li>
148
+ </ul>,
149
+ "\n",
150
+ ],
151
+ },
152
+ heading: {
153
+ children: "Section B",
154
+ },
155
+ },
156
+ ]}
157
+ />
158
+ );
159
+ }
160
+ ```
161
+
162
+ or
163
+
164
+ ```javascript
165
+ // in scope accordion configuration
166
+ import React, { useEffect } from "react";
167
+ import {
168
+ Accordion,
169
+ ConfigureOverallAccordion,
170
+ } from "@hmlr/govuk-react-components-library";
171
+
172
+ function App() {
173
+ useEffect(() => {
174
+ const accordionConfig = {
175
+ i18n: {
176
+ hideAllSections: "Collapse all sections",
177
+ showAllSections: "Expand all sections",
178
+ hideSection: "Collapse",
179
+ hideSectionAriaLabel: "Collapse this section",
180
+ showSection: "Expand",
181
+ showSectionAriaLabel: "Expand this section",
182
+ },
183
+ };
184
+ const $element = document.querySelector(".govuk-accordion");
185
+ ConfigureOverallAccordion($element, accordionConfig);
186
+ }, []);
187
+
188
+ return (
189
+ <Accordion
190
+ id="default-example"
191
+ items={[
192
+ {
193
+ content: {
194
+ children:
195
+ "We need to know your nationality so we can work out which elections you’re entitled to vote in. If you cannot provide your nationality, you’ll have to send copies of identity documents through the post.",
196
+ },
197
+ heading: {
198
+ children: "Section A",
199
+ },
200
+ },
201
+ {
202
+ content: {
203
+ children: [
204
+ <ul key="0" className="govuk-list govuk-list--bullet">
205
+ {""}
206
+ <li>Example item 2</li>
207
+ </ul>,
208
+ "\n",
209
+ ],
210
+ },
211
+ heading: {
212
+ children: "Section B",
213
+ },
214
+ },
215
+ ]}
216
+ />
217
+ );
218
+ }
219
+ ```
220
+
221
+ </details>
222
+
223
+ <details>
224
+ <summary>Scoped Accordion Configuration Example in HTML</summary>
225
+
226
+ ```html
227
+ <!-- in scope accordion configuration -->
228
+ <script type="module" src="./govuk-frontend.min.js"></script>
229
+ <script type="module">
230
+ import { Accordion, createAll } from "./govuk-frontend.min.js";
231
+ const $accordion = document.querySelector(".govuk-accordion");
232
+ createAll(
233
+ Accordion,
234
+ {
235
+ i18n: {
236
+ hideAllSections: "Collapse all sections",
237
+ showAllSections: "Expand all sections",
238
+ hideSection: "Collapse",
239
+ hideSectionAriaLabel: "Collapse this section",
240
+ showSection: "Expand",
241
+ showSectionAriaLabel: "Expand this section",
242
+ },
243
+ },
244
+ $accordion,
245
+ );
246
+ </script>
247
+ ```
248
+
249
+ or
250
+
251
+ ```html
252
+ <!-- in scope accordion configuration -->
253
+ <script type="module" src="./govuk-frontend.min.js"></script>
254
+ <script type="module">
255
+ import { Accordion } from "./govuk-frontend.min.js";
256
+ const $accordions = document.querySelectorAll(
257
+ '[data-module="govuk-accordion"]',
258
+ );
259
+ $accordions.forEach(($accordion) => {
260
+ new Accordion($accordion, {
261
+ i18n: {
262
+ hideAllSections: "Collapse all sections",
263
+ showAllSections: "Expand all sections",
264
+ hideSection: "Collapse",
265
+ hideSectionAriaLabel: "Collapse this section",
266
+ showSection: "Expand",
267
+ showSectionAriaLabel: "Expand this section",
268
+ },
269
+ });
270
+ });
271
+ </script>
272
+ ```
273
+
274
+ </details>
275
+
276
+ <details>
277
+ <summary>Use default Accordion Configurations</summary>
278
+
279
+ ```javascript
280
+ // use default configuration
281
+ import React, { useEffect } from "react";
282
+ import {
283
+ Accordion,
284
+ ConfigureOverallAccordion,
285
+ } from "@hmlr/govuk-react-components-library";
286
+
287
+ function App() {
288
+ useEffect(() => {
289
+ ConfigureOverallAccordion();
290
+ }, []);
291
+
292
+ return (
293
+ <Accordion
294
+ id="default-example"
295
+ items={[
296
+ {
297
+ content: {
298
+ children:
299
+ "We need to know your nationality so we can work out which elections you’re entitled to vote in. If you cannot provide your nationality, you’ll have to send copies of identity documents through the post.",
300
+ },
301
+ heading: {
302
+ children: "Section A",
303
+ },
304
+ },
305
+ {
306
+ content: {
307
+ children: [
308
+ <ul key="0" className="govuk-list govuk-list--bullet">
309
+ {""}
310
+ <li>Example item 2</li>
311
+ </ul>,
312
+ "\n",
313
+ ],
314
+ },
315
+ heading: {
316
+ children: "Section B",
317
+ },
318
+ },
319
+ ]}
320
+ />
321
+ );
322
+ }
323
+ ```
324
+
325
+ or in html
326
+
327
+ ```html
328
+ <!-- use default configuration -->
329
+ <script type="module" src="./govuk-frontend.min.js"></script>
330
+ <script type="module">
331
+ import { Accordion, createAll } from "./govuk-frontend.min.js";
332
+ createAll(Accordion);
333
+ </script>
334
+ ```
335
+
336
+ </details>
337
+
338
+ <details>
339
+ <summary>Use default All Configurations</summary>
340
+
341
+ ```javascript
342
+ // use default configuration
343
+ import React, { useEffect } from "react";
344
+ import { initAll } from "govuk-frontend";
345
+ import { Accordion } from "@hmlr/govuk-react-components-library";
346
+
347
+ function App() {
348
+ useEffect(() => {
349
+ initAll();
350
+ }, []);
351
+
352
+ return (
353
+ <Accordion
354
+ id="default-example"
355
+ items={[
356
+ {
357
+ content: {
358
+ children:
359
+ "We need to know your nationality so we can work out which elections you’re entitled to vote in. If you cannot provide your nationality, you’ll have to send copies of identity documents through the post.",
360
+ },
361
+ heading: {
362
+ children: "Section A",
363
+ },
364
+ },
365
+ {
366
+ content: {
367
+ children: [
368
+ <ul key="0" className="govuk-list govuk-list--bullet">
369
+ {""}
370
+ <li>Example item 2</li>
371
+ </ul>,
372
+ "\n",
373
+ ],
374
+ },
375
+ heading: {
376
+ children: "Section B",
377
+ },
378
+ },
379
+ ]}
380
+ />
381
+ );
382
+ }
383
+ ```
384
+
385
+ or in html
386
+
387
+ ```html
388
+ <!-- use default configuration -->
389
+ <script type="module" src="./govuk-frontend.min.js"></script>
390
+ <script type="module">
391
+ import { initAll } from "./govuk-frontend.min.js";
392
+ initAll();
393
+ </script>
394
+ ```
395
+
396
+ </details>
397
+
398
+ ## Usage
399
+
400
+ Use the above components like the Panel component:
401
+
402
+ ```javascript
403
+ import { Panel } from "@hmlr/govuk-react-component-library";
404
+
405
+ export default function SuccessPanel() {
406
+ return (
407
+ <Panel titleChildren="Application complete">
408
+ Your reference number: HDJ2123F
409
+ </Panel>
410
+ );
411
+ }
412
+ ```
413
+
414
+ Note: For the `PDFViewer` above you must provide a [PDFJS Distribution version](https://mozilla.github.io/pdf.js/) to be used along with the `PDFViewer` component. follow the steps to use `PDFViewer` component:
415
+
416
+ - Download any version of the [PDFJS Distribution version](https://mozilla.github.io/pdf.js/) suitable for your application
417
+ - Unzip the distribution and add it into you project's static directory i.e. `public` directory. Meaning in the root of your project you will have the distribution in `public/pdfjs-4.4.168-dist`
418
+ - Use the viewer located in `public/pdfjs-4.4.168-dist/web/viewer.html` as `viewerLocation` value in the `PDFViewer` component. Meaning since `public` is the static directory the viewer is located in `/pdfjs-4.4.168-dist/web/viewer.html`.
419
+
420
+ An example of the `PDFViewer` component usage based on the 3 steps above will be:
421
+
422
+ ```jsx
423
+ import {
424
+ PDFViewer,
425
+ PDFViewerBackend,
426
+ } from "@hmlr/govuk-react-component-library";
427
+
428
+ export default function ViewDocument() {
429
+ return (
430
+ <PDFViewer
431
+ backend={PDFViewerBackend}
432
+ documentName="LCOP 2020-0035"
433
+ iframeId="document_iframe"
434
+ src="/document.pdf"
435
+ toolbar="fullHidePrint"
436
+ viewerLocation="/pdfjs-4.4.168-dist/web/viewer.html"
437
+ />
438
+ );
439
+ }
440
+ ```
441
+
442
+ or base64 encoded pdf data
443
+
444
+ ```jsx
445
+ import {
446
+ PDFViewer,
447
+ PDFViewerBackend,
448
+ } from "@hmlr/govuk-react-component-library";
449
+ import { base64EncodedPDFDocument } from "./testutilities/SampleBase64";
450
+
451
+ export default function ViewDocument() {
452
+ return (
453
+ <PDFViewer
454
+ backend={PDFViewerBackend}
455
+ documentName="LCOP 2020-0035"
456
+ iframeId="document_iframe"
457
+ src={base64EncodedPDFDocument}
458
+ toolbar="fullHidePrint"
459
+ viewerLocation="/pdfjs-4.4.168-dist/web/viewer.html"
460
+ />
461
+ );
462
+ }
463
+ ```
464
+
465
+ Also one can add custom javascript to viewer to hide or show certain parts of the PDF Viewer or any custom functionality. An example is in the [Custom Toolbar](./.storybook/public/customToolbar.js) in this project. Which then means that in the [`PDF Viewer`](./.storybook/public/pdfjs-4.4.168-dist/web/viewer.html#L40). one will add
466
+
467
+ ```html
468
+ <script src="../../customToolbar.js"></script>
469
+ ```
470
+
471
+ to the head tag of the `./.storybook/public/pdfjs-4.4.168-dist/web/viewer.html` file.
472
+
473
+ But for the example above we recommend to use the [Custom Toolbar](./.storybook/public/customToolbar.js) in this project. This is tested against `/pdfjs-4.4.168-dist` only. Copy [Custom Toolbar](./.storybook/public/customToolbar.js) into your project static folder where it is called `public` and the use it in the `public/pdfjs-4.4.168-dist/web/viewer.html` thus:
474
+
475
+ ```html
476
+ <head>
477
+ .....
478
+ <script src="../../customToolbar.js"></script>
479
+ </head>
480
+ ```
481
+
482
+ ## Using this library
483
+
484
+ In order to use this library, you will need to install the peer dependencies of this application as show in the [package.json.peerDependencies](./package.json#139). Which includes the following dependencies:
485
+
486
+ - [govuk-frontend](https://www.npmjs.com/package/govuk-frontend) - any version >=5.6.0
487
+ - [react](https://www.npmjs.com/package/react) - any version >=18.3.1
488
+ - [react-dom](https://www.npmjs.com/package/react-dom) - any version >=18.3.1
489
+ - [react-router-dom](https://www.npmjs.com/package/react-router-dom) - any version >=6.26.1
490
+
491
+ The source of truth can be found the [package.json.peerDependencies](./package.json#139).
492
+
493
+ ### Using the PDFViewerCanvas Component
494
+
495
+ The PDFViewerCanvas component is optional and requires the `pdfjs-dist` package. To use it:
496
+
497
+ 1. Install the optional dependency:
498
+
499
+ ```bash
500
+ npm install pdfjs-dist
501
+ ```
502
+
503
+ - [pdfjs-dist](https://www.npmjs.com/package/pdfjs-dist) - any version >=4.6.82 and only if you are using `PDFViewerCanvas` component. This is an optional dependency.
504
+
505
+ 2. Import the PDFViewerCanvas component from the separate entry point:
506
+
507
+ ```jsx
508
+ import { PDFViewerCanvas } from "@hmlr/govuk-react-components-library/pdfViewer";
509
+ ```
510
+
511
+ 3. Use the component in your React application:
512
+
513
+ ```jsx
514
+ <PDFViewerCanvas src="path/to/your/pdf" />
515
+ ```
516
+
517
+ ## Development
518
+
519
+ ### Prerequisites
520
+
521
+ - Node.js ( v20.19.0 or higher)
522
+ - npm ( v10.8.2 or higher)
523
+ - govuk-frontend (v5.8.0 or higher)
524
+ - react (v18.2.0 or higher)
525
+ - react-dom (v18.2.0 or higher)
526
+ - react-router-dom (v18.2.0 or higher)
527
+
528
+ ### Setup
529
+
530
+ 1. Clone the repository:
531
+
532
+ ```bash
533
+ git clone https://github.com/LandRegistry/govuk-react-component-library.git
534
+ cd govuk-react-component-library
535
+ ```
536
+
537
+ 2. Install dependencies:
538
+
539
+ ```bash
540
+ npm install
541
+ npm install pdfjs-dist@4.10.38 --save-dev # for PDFCanvas
542
+ ```
543
+
544
+ 3. Start the development server:
545
+
546
+ ```bash
547
+ npm run dev
548
+ ```
549
+
550
+ 4. Run Storybook:
551
+
552
+ ```bash
553
+ npm run storybook
554
+ ```
555
+
556
+ ### Running Builds
557
+
558
+ To run the build in this project use the following command:
559
+
560
+ ```bash
561
+ npm run build
562
+ ```
563
+
564
+ ### Running Linting and formatting
565
+
566
+ To run the linting and formating in this project use the following command:
567
+
568
+ ```bash
569
+ npm run lint
570
+ ```
571
+
572
+ or
573
+
574
+ ```bash
575
+ npm run lint-fix
576
+ ```
577
+
578
+ and for prettifying
579
+
580
+ ```bash
581
+ npm run format
582
+ ```
583
+
584
+ ## Testing
585
+
586
+ To run the test in this project use the following command:
587
+
588
+ ```bash
589
+ npm run test
590
+ ```
591
+
592
+ ## Contributing
593
+
594
+ Contributions are welcome! Please feel free to submit a Pull Request.
595
+
596
+ ## UML Diagram
597
+
598
+ The UML diagram for all components in this library can be found here:
599
+
600
+ ![HMLR react common library UML](assets/uml-diagram.svg)
601
+
602
+ ## Release New version of this package
603
+
604
+ Use the floowing command to release a new version of the application
605
+
606
+ ```bash
607
+ npm run release
608
+ ```
609
+
610
+ or
611
+
612
+ ```bash
613
+ npm run release -- --release-as minor
614
+ ```
615
+
616
+ or for specific versions
617
+
618
+ ```bash
619
+ npm run release -- --release-as 1.9.1
620
+ ```
621
+
622
+ Then publish the version with the following command
623
+
624
+ ```bash
625
+ git push --follow-tags origin main
626
+ ```
627
+
628
+ and publish as an npm package run
629
+
630
+ ```bash
631
+ npm publish
632
+ ```
633
+
634
+ ## License
635
+
636
+ This project is licensed under the MIT License - see the LICENSE file for details.
Binary file