@govuk-react/primitives 0.2.0 → 0.2.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 (258) hide show
  1. package/dist/{accordion-element.d.ts → accordion/element.d.ts} +2 -5
  2. package/dist/accordion/element.js +302 -0
  3. package/dist/accordion/element.js.map +1 -0
  4. package/dist/accordion/index.d.ts +74 -0
  5. package/dist/accordion/index.js +138 -0
  6. package/dist/accordion/index.js.map +1 -0
  7. package/dist/auto-focus/element.d.ts +1 -0
  8. package/dist/auto-focus/element.js +75 -0
  9. package/dist/auto-focus/element.js.map +1 -0
  10. package/dist/{index-Bul0NJh_.d.ts → auto-focus/index.d.ts} +27 -40
  11. package/dist/auto-focus/index.js +29 -0
  12. package/dist/{chunk-6ZFU4VYW.js.map → auto-focus/index.js.map} +1 -1
  13. package/dist/{autocomplete-element.d.ts → autocomplete/element.d.ts} +4 -7
  14. package/dist/autocomplete/element.js +597 -0
  15. package/dist/autocomplete/element.js.map +1 -0
  16. package/dist/{index-D7lMYMUR.d.ts → autocomplete/index.d.ts} +34 -57
  17. package/dist/autocomplete/index.js +108 -0
  18. package/dist/autocomplete/index.js.map +1 -0
  19. package/dist/button/element.d.ts +1 -0
  20. package/dist/button/element.js +59 -0
  21. package/dist/button/element.js.map +1 -0
  22. package/dist/button/index.d.ts +10 -0
  23. package/dist/button/index.js +9 -0
  24. package/dist/button/index.js.map +1 -0
  25. package/dist/{character-count-element.d.ts → character-count/element.d.ts} +2 -5
  26. package/dist/character-count/element.js +287 -0
  27. package/dist/character-count/element.js.map +1 -0
  28. package/dist/character-count/index.d.ts +57 -0
  29. package/dist/character-count/index.js +79 -0
  30. package/dist/character-count/index.js.map +1 -0
  31. package/dist/character-count/messages.d.ts +20 -0
  32. package/dist/character-count/messages.js +54 -0
  33. package/dist/character-count/messages.js.map +1 -0
  34. package/dist/choices/element.d.ts +5 -0
  35. package/dist/choices/element.js +202 -0
  36. package/dist/choices/element.js.map +1 -0
  37. package/dist/{index-WuGvkTxu.d.ts → choices/index.d.ts} +30 -44
  38. package/dist/choices/index.js +37 -0
  39. package/dist/choices/index.js.map +1 -0
  40. package/dist/{disclosure-element.d.ts → disclosure/element.d.ts} +2 -5
  41. package/dist/disclosure/element.js +123 -0
  42. package/dist/disclosure/element.js.map +1 -0
  43. package/dist/{index-D4Gzyvfu.d.ts → disclosure/index.d.ts} +40 -54
  44. package/dist/disclosure/index.js +66 -0
  45. package/dist/disclosure/index.js.map +1 -0
  46. package/dist/exit-this-page/element.d.ts +19 -0
  47. package/dist/exit-this-page/element.js +201 -0
  48. package/dist/exit-this-page/element.js.map +1 -0
  49. package/dist/{index-qF0jIQCW.d.ts → exit-this-page/index.d.ts} +36 -60
  50. package/dist/exit-this-page/index.js +54 -0
  51. package/dist/exit-this-page/index.js.map +1 -0
  52. package/dist/{file-upload-element.d.ts → file-upload/element.d.ts} +5 -9
  53. package/dist/file-upload/element.js +270 -0
  54. package/dist/file-upload/element.js.map +1 -0
  55. package/dist/file-upload/index.d.ts +46 -0
  56. package/dist/file-upload/index.js +65 -0
  57. package/dist/file-upload/index.js.map +1 -0
  58. package/dist/focus-links/element.d.ts +1 -0
  59. package/dist/focus-links/element.js +90 -0
  60. package/dist/focus-links/element.js.map +1 -0
  61. package/dist/{index-BR3MAGF8.d.ts → focus-links/index.d.ts} +24 -35
  62. package/dist/focus-links/index.js +7 -0
  63. package/dist/focus-links/index.js.map +1 -0
  64. package/dist/index.d.ts +13 -17
  65. package/dist/index.js +13 -72
  66. package/dist/index.js.map +1 -1
  67. package/dist/inline/accordion-element.js +1 -1
  68. package/dist/inline/auto-focus-element.js +1 -1
  69. package/dist/inline/autocomplete-element.js +1 -1
  70. package/dist/inline/character-count-element.js +1 -1
  71. package/dist/inline/choices-element.js +1 -1
  72. package/dist/inline/disclosure-element.js +1 -1
  73. package/dist/inline/exit-this-page-element.js +1 -1
  74. package/dist/inline/file-upload-element.js +1 -1
  75. package/dist/inline/focus-links-element.js +1 -1
  76. package/dist/inline/modal-element.js +1 -1
  77. package/dist/inline/password-input-element.js +1 -1
  78. package/dist/inline/tabs-element.js +1 -1
  79. package/dist/inline-script/index.d.ts +26 -0
  80. package/dist/inline-script/index.js +31 -0
  81. package/dist/inline-script/index.js.map +1 -0
  82. package/dist/{modal-element.d.ts → modal/element.d.ts} +2 -4
  83. package/dist/modal/element.js +114 -0
  84. package/dist/modal/element.js.map +1 -0
  85. package/dist/modal/index.d.ts +36 -0
  86. package/dist/modal/index.js +109 -0
  87. package/dist/modal/index.js.map +1 -0
  88. package/dist/password-input/element.d.ts +1 -0
  89. package/dist/password-input/element.js +134 -0
  90. package/dist/password-input/element.js.map +1 -0
  91. package/dist/{index-sEHnx4-M.d.ts → password-input/index.d.ts} +32 -48
  92. package/dist/password-input/index.js +35 -0
  93. package/dist/password-input/index.js.map +1 -0
  94. package/dist/{tabs-element.d.ts → tabs/element.d.ts} +2 -5
  95. package/dist/tabs/element.js +416 -0
  96. package/dist/tabs/element.js.map +1 -0
  97. package/dist/tabs/index.d.ts +83 -0
  98. package/dist/tabs/index.js +138 -0
  99. package/dist/tabs/index.js.map +1 -0
  100. package/dist/utils/dom.d.ts +9 -0
  101. package/dist/utils/dom.js +27 -0
  102. package/dist/utils/dom.js.map +1 -0
  103. package/dist/utils/on-property-set.d.ts +9 -0
  104. package/dist/utils/on-property-set.js +38 -0
  105. package/dist/utils/on-property-set.js.map +1 -0
  106. package/dist/utils/set-focus.d.ts +11 -0
  107. package/dist/utils/set-focus.js +38 -0
  108. package/dist/utils/set-focus.js.map +1 -0
  109. package/dist/utils/set-up-when-ready.d.ts +6 -0
  110. package/dist/utils/set-up-when-ready.js +16 -0
  111. package/dist/utils/set-up-when-ready.js.map +1 -0
  112. package/dist/utils/slot.d.ts +13 -0
  113. package/dist/utils/slot.js +40 -0
  114. package/dist/utils/slot.js.map +1 -0
  115. package/dist/utils/translation.d.ts +13 -0
  116. package/dist/utils/translation.js +57 -0
  117. package/dist/utils/translation.js.map +1 -0
  118. package/package.json +11 -4
  119. package/dist/accordion-element.js +0 -9
  120. package/dist/accordion-element.js.map +0 -1
  121. package/dist/accordion.d.ts +0 -2
  122. package/dist/accordion.js +0 -34
  123. package/dist/accordion.js.map +0 -1
  124. package/dist/auto-focus-element.d.ts +0 -3
  125. package/dist/auto-focus-element.js +0 -10
  126. package/dist/auto-focus-element.js.map +0 -1
  127. package/dist/auto-focus.d.ts +0 -2
  128. package/dist/auto-focus.js +0 -15
  129. package/dist/auto-focus.js.map +0 -1
  130. package/dist/autocomplete-element.js +0 -12
  131. package/dist/autocomplete-element.js.map +0 -1
  132. package/dist/autocomplete.d.ts +0 -4
  133. package/dist/autocomplete.js +0 -25
  134. package/dist/autocomplete.js.map +0 -1
  135. package/dist/button-element.d.ts +0 -2
  136. package/dist/button-element.js +0 -3
  137. package/dist/button-element.js.map +0 -1
  138. package/dist/button.d.ts +0 -2
  139. package/dist/button.js +0 -12
  140. package/dist/button.js.map +0 -1
  141. package/dist/character-count-element.js +0 -10
  142. package/dist/character-count-element.js.map +0 -1
  143. package/dist/character-count.d.ts +0 -3
  144. package/dist/character-count.js +0 -26
  145. package/dist/character-count.js.map +0 -1
  146. package/dist/choices-element.d.ts +0 -8
  147. package/dist/choices-element.js +0 -9
  148. package/dist/choices-element.js.map +0 -1
  149. package/dist/choices.d.ts +0 -2
  150. package/dist/choices.js +0 -16
  151. package/dist/choices.js.map +0 -1
  152. package/dist/chunk-2IHAQAYF.js +0 -23
  153. package/dist/chunk-2IHAQAYF.js.map +0 -1
  154. package/dist/chunk-2ZJVSNC2.js +0 -31
  155. package/dist/chunk-2ZJVSNC2.js.map +0 -1
  156. package/dist/chunk-47NMY4SS.js +0 -108
  157. package/dist/chunk-47NMY4SS.js.map +0 -1
  158. package/dist/chunk-4XAR4FFG.js +0 -83
  159. package/dist/chunk-4XAR4FFG.js.map +0 -1
  160. package/dist/chunk-5HWRMQK2.js +0 -91
  161. package/dist/chunk-5HWRMQK2.js.map +0 -1
  162. package/dist/chunk-6ZFU4VYW.js +0 -41
  163. package/dist/chunk-B2I4J5NL.js +0 -264
  164. package/dist/chunk-B2I4J5NL.js.map +0 -1
  165. package/dist/chunk-DPERPCUH.js +0 -188
  166. package/dist/chunk-DPERPCUH.js.map +0 -1
  167. package/dist/chunk-ECYGKE4D.js +0 -168
  168. package/dist/chunk-ECYGKE4D.js.map +0 -1
  169. package/dist/chunk-ESBMTI25.js +0 -11
  170. package/dist/chunk-ESBMTI25.js.map +0 -1
  171. package/dist/chunk-ET7DCQM7.js +0 -133
  172. package/dist/chunk-ET7DCQM7.js.map +0 -1
  173. package/dist/chunk-F5XFC4QJ.js +0 -177
  174. package/dist/chunk-F5XFC4QJ.js.map +0 -1
  175. package/dist/chunk-GVGBDSDN.js +0 -78
  176. package/dist/chunk-GVGBDSDN.js.map +0 -1
  177. package/dist/chunk-IZQ2C4BC.js +0 -351
  178. package/dist/chunk-IZQ2C4BC.js.map +0 -1
  179. package/dist/chunk-L7E6GN2D.js +0 -87
  180. package/dist/chunk-L7E6GN2D.js.map +0 -1
  181. package/dist/chunk-LWIA644X.js +0 -34
  182. package/dist/chunk-LWIA644X.js.map +0 -1
  183. package/dist/chunk-NX4B3NKM.js +0 -35
  184. package/dist/chunk-NX4B3NKM.js.map +0 -1
  185. package/dist/chunk-PNWPGD7B.js +0 -68
  186. package/dist/chunk-PNWPGD7B.js.map +0 -1
  187. package/dist/chunk-QLQ6O7OW.js +0 -111
  188. package/dist/chunk-QLQ6O7OW.js.map +0 -1
  189. package/dist/chunk-RDUPELOK.js +0 -55
  190. package/dist/chunk-RDUPELOK.js.map +0 -1
  191. package/dist/chunk-RPMHI67T.js +0 -104
  192. package/dist/chunk-RPMHI67T.js.map +0 -1
  193. package/dist/chunk-TE4RUYVK.js +0 -97
  194. package/dist/chunk-TE4RUYVK.js.map +0 -1
  195. package/dist/chunk-TJVBFRIE.js +0 -60
  196. package/dist/chunk-TJVBFRIE.js.map +0 -1
  197. package/dist/chunk-U5OKNKYC.js +0 -510
  198. package/dist/chunk-U5OKNKYC.js.map +0 -1
  199. package/dist/chunk-UXJO4AJP.js +0 -290
  200. package/dist/chunk-UXJO4AJP.js.map +0 -1
  201. package/dist/chunk-VNXXENCU.js +0 -39
  202. package/dist/chunk-VNXXENCU.js.map +0 -1
  203. package/dist/chunk-XGK73UCD.js +0 -62
  204. package/dist/chunk-XGK73UCD.js.map +0 -1
  205. package/dist/chunk-XJYLFTYE.js +0 -157
  206. package/dist/chunk-XJYLFTYE.js.map +0 -1
  207. package/dist/chunk-YCESNTXQ.js +0 -241
  208. package/dist/chunk-YCESNTXQ.js.map +0 -1
  209. package/dist/chunk-ZTJLVNR4.js +0 -62
  210. package/dist/chunk-ZTJLVNR4.js.map +0 -1
  211. package/dist/disclosure-element.js +0 -9
  212. package/dist/disclosure-element.js.map +0 -1
  213. package/dist/disclosure.d.ts +0 -2
  214. package/dist/disclosure.js +0 -16
  215. package/dist/disclosure.js.map +0 -1
  216. package/dist/exit-this-page-element.d.ts +0 -22
  217. package/dist/exit-this-page-element.js +0 -13
  218. package/dist/exit-this-page-element.js.map +0 -1
  219. package/dist/exit-this-page.d.ts +0 -3
  220. package/dist/exit-this-page.js +0 -25
  221. package/dist/exit-this-page.js.map +0 -1
  222. package/dist/file-upload-element.js +0 -14
  223. package/dist/file-upload-element.js.map +0 -1
  224. package/dist/file-upload.d.ts +0 -3
  225. package/dist/file-upload.js +0 -25
  226. package/dist/file-upload.js.map +0 -1
  227. package/dist/focus-links-element.d.ts +0 -3
  228. package/dist/focus-links-element.js +0 -10
  229. package/dist/focus-links-element.js.map +0 -1
  230. package/dist/focus-links.d.ts +0 -2
  231. package/dist/focus-links.js +0 -12
  232. package/dist/focus-links.js.map +0 -1
  233. package/dist/index--FxJgSOS.d.ts +0 -108
  234. package/dist/index-CikOyFud.d.ts +0 -54
  235. package/dist/index-D8N5vxTL.d.ts +0 -90
  236. package/dist/index-DMWpkC_d.d.ts +0 -105
  237. package/dist/index-DN7fGMc3.d.ts +0 -20
  238. package/dist/index-DPXR1Yua.d.ts +0 -69
  239. package/dist/inline-script.d.ts +0 -29
  240. package/dist/inline-script.js +0 -63
  241. package/dist/inline-script.js.map +0 -1
  242. package/dist/modal-element.js +0 -11
  243. package/dist/modal-element.js.map +0 -1
  244. package/dist/modal.d.ts +0 -2
  245. package/dist/modal.js +0 -20
  246. package/dist/modal.js.map +0 -1
  247. package/dist/password-input-element.d.ts +0 -3
  248. package/dist/password-input-element.js +0 -9
  249. package/dist/password-input-element.js.map +0 -1
  250. package/dist/password-input.d.ts +0 -2
  251. package/dist/password-input.js +0 -18
  252. package/dist/password-input.js.map +0 -1
  253. package/dist/tabs-element.js +0 -9
  254. package/dist/tabs-element.js.map +0 -1
  255. package/dist/tabs.d.ts +0 -2
  256. package/dist/tabs.js +0 -28
  257. package/dist/tabs.js.map +0 -1
  258. package/dist/translation-BnpO2mN2.d.ts +0 -4
@@ -0,0 +1,46 @@
1
+ import * as React from 'react';
2
+ import type { ComponentProps } from 'react';
3
+ import { type Translation } from '../utils/translation.js';
4
+ export type { Translation } from '../utils/translation.js';
5
+ export type RootProps = React.HTMLAttributes<HTMLElement> & {
6
+ /** Shown while no file is chosen. Defaults to "No file chosen". */
7
+ noFileChosen?: string;
8
+ /** Shown when more than one file is chosen. `%{count}` is the number. Defaults to "%{count} files chosen". */
9
+ multipleFilesChosen?: Translation;
10
+ /** Announced when the user drags files into the drop zone. Defaults to "Entered drop zone". */
11
+ enteredDropZone?: string;
12
+ /** Announced when the user drags files out of the drop zone. Defaults to "Left drop zone". */
13
+ leftDropZone?: string;
14
+ /** Classes for the button while no file is chosen. */
15
+ emptyClass?: string;
16
+ /** Classes for the button while files are dragged over the drop zone. */
17
+ draggingClass?: string;
18
+ /** Classes for the drop zone while the input is disabled. */
19
+ disabledClass?: string;
20
+ };
21
+ export declare function Root({ noFileChosen, multipleFilesChosen, enteredDropZone, leftDropZone, emptyClass, draggingClass, disabledClass, ...props }: RootProps): React.JSX.Element;
22
+ type PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {
23
+ /** Render the only child instead, with this part's props merged onto it. */
24
+ asChild?: boolean;
25
+ };
26
+ export type DropZoneProps = PartProps<'div'>;
27
+ /** The area that shows files are being dragged over it. Holds the button and the input. */
28
+ export declare function DropZone({ asChild, ...props }: DropZoneProps): React.JSX.Element;
29
+ export type InputProps = Omit<PartProps<'input'>, 'type'>;
30
+ /** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */
31
+ export declare function Input({ asChild, ...props }: InputProps): React.JSX.Element;
32
+ export type ButtonProps = PartProps<'button'>;
33
+ /**
34
+ * Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it
35
+ * takes the input's id, so the input's label names it. Holds `Status`.
36
+ */
37
+ export declare function Button({ asChild, ...props }: ButtonProps): React.JSX.Element;
38
+ export type StatusProps = PartProps<'span'>;
39
+ /** Which files are chosen: "No file chosen", the file's name, or how many files. In `Button`. */
40
+ export declare function Status({ asChild, children, ...props }: StatusProps): React.JSX.Element;
41
+ export type SeparatorProps = PartProps<'span'>;
42
+ /** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `Button`. */
43
+ export declare function Separator({ asChild, children, ...props }: SeparatorProps): React.JSX.Element;
44
+ export type AnnouncementsProps = PartProps<'span'>;
45
+ /** Announces entering and leaving the drop zone. Make it visually hidden. */
46
+ export declare function Announcements({ asChild, ...props }: AnnouncementsProps): React.JSX.Element;
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { createContext, useContext, useState } from 'react';
4
+ import { Slot } from '../utils/slot.js';
5
+ import { translationAttributes } from '../utils/translation.js';
6
+ import { defaults, statusText, tagName } from './element.js';
7
+ // What the status starts with, so the element only changes text React rendered.
8
+ const InitialStatus = createContext(defaults['no-file-chosen']);
9
+ export function Root({ noFileChosen, multipleFilesChosen, enteredDropZone, leftDropZone, emptyClass, draggingClass, disabledClass, ...props }) {
10
+ // Rendered once and then left to the element, so a re-render never puts back a stale status.
11
+ const [initial] = useState(() => statusText([], { 'no-file-chosen': noFileChosen }, props.lang || 'en'));
12
+ return (React.createElement(InitialStatus.Provider, { value: initial }, React.createElement(tagName, {
13
+ ...props,
14
+ // The element owns `data-upgraded`.
15
+ suppressHydrationWarning: true,
16
+ 'no-file-chosen': noFileChosen,
17
+ ...translationAttributes('multiple-files-chosen', multipleFilesChosen),
18
+ 'entered-drop-zone': enteredDropZone,
19
+ 'left-drop-zone': leftDropZone,
20
+ 'empty-class': emptyClass,
21
+ 'dragging-class': draggingClass,
22
+ 'disabled-class': disabledClass,
23
+ })));
24
+ }
25
+ /** The area that shows files are being dragged over it. Holds the button and the input. */
26
+ export function DropZone({ asChild, ...props }) {
27
+ const Element = asChild ? Slot : 'div';
28
+ // The element owns its disabled classes after upgrade.
29
+ return React.createElement(Element, { "data-file-upload-drop-zone": "", suppressHydrationWarning: true, ...props });
30
+ }
31
+ /** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */
32
+ export function Input({ asChild, ...props }) {
33
+ const Element = asChild ? Slot : 'input';
34
+ // The element owns `id` and `hidden` after upgrade.
35
+ return React.createElement(Element, { type: "file", suppressHydrationWarning: true, ...props });
36
+ }
37
+ /**
38
+ * Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it
39
+ * takes the input's id, so the input's label names it. Holds `Status`.
40
+ */
41
+ export function Button({ asChild, ...props }) {
42
+ const Element = asChild ? Slot : 'button';
43
+ // The element owns `id`, `hidden`, `disabled`, its ARIA and its classes after upgrade.
44
+ return React.createElement(Element, { "data-file-upload-button": "", type: "button", hidden: true, suppressHydrationWarning: true, ...props });
45
+ }
46
+ /** Which files are chosen: "No file chosen", the file's name, or how many files. In `Button`. */
47
+ export function Status({ asChild, children, ...props }) {
48
+ const initial = useContext(InitialStatus);
49
+ const Element = asChild ? Slot : 'span';
50
+ // The element owns its text after upgrade.
51
+ return (React.createElement(Element, { "data-file-upload-status": "", "aria-live": "polite", suppressHydrationWarning: true, ...props }, children !== null && children !== void 0 ? children : initial));
52
+ }
53
+ /** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `Button`. */
54
+ export function Separator({ asChild, children = ', ', ...props }) {
55
+ const Element = asChild ? Slot : 'span';
56
+ // The element owns its `id` after upgrade.
57
+ return (React.createElement(Element, { "data-file-upload-separator": "", suppressHydrationWarning: true, ...props }, children));
58
+ }
59
+ /** Announces entering and leaving the drop zone. Make it visually hidden. */
60
+ export function Announcements({ asChild, ...props }) {
61
+ const Element = asChild ? Slot : 'span';
62
+ // The element owns its text after upgrade.
63
+ return React.createElement(Element, { "data-file-upload-announcements": "", "aria-live": "assertive", suppressHydrationWarning: true, ...props });
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file-upload/index.tsx"],"names":[],"mappings":"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","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useState } from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { translationAttributes, type Translation } from '../utils/translation.js';\nimport { defaults, statusText, tagName } from './element.js';\n\nexport type { Translation } from '../utils/translation.js';\n\n/*\n * Headless file upload: unstyled parts over the <govuk-react-file-upload> element (./element.ts),\n * which shows the button on upgrade, hides the input and handles dropped files. Every part except\n * Root takes `asChild`.\n *\n * The input's files are the state, owned by the browser, so there is nothing to control. Without\n * JavaScript the native file input shows and the button stays hidden.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Shown while no file is chosen. Defaults to \"No file chosen\". */\n noFileChosen?: string;\n /** Shown when more than one file is chosen. `%{count}` is the number. Defaults to \"%{count} files chosen\". */\n multipleFilesChosen?: Translation;\n /** Announced when the user drags files into the drop zone. Defaults to \"Entered drop zone\". */\n enteredDropZone?: string;\n /** Announced when the user drags files out of the drop zone. Defaults to \"Left drop zone\". */\n leftDropZone?: string;\n /** Classes for the button while no file is chosen. */\n emptyClass?: string;\n /** Classes for the button while files are dragged over the drop zone. */\n draggingClass?: string;\n /** Classes for the drop zone while the input is disabled. */\n disabledClass?: string;\n};\n\n// What the status starts with, so the element only changes text React rendered.\nconst InitialStatus = createContext<string>(defaults['no-file-chosen']);\n\nexport function Root({\n noFileChosen,\n multipleFilesChosen,\n enteredDropZone,\n leftDropZone,\n emptyClass,\n draggingClass,\n disabledClass,\n ...props\n}: RootProps) {\n // Rendered once and then left to the element, so a re-render never puts back a stale status.\n const [initial] = useState(() => statusText([], { 'no-file-chosen': noFileChosen }, props.lang || 'en'));\n return (\n <InitialStatus.Provider value={initial}>\n {React.createElement(tagName, {\n ...props,\n // The element owns `data-upgraded`.\n suppressHydrationWarning: true,\n 'no-file-chosen': noFileChosen,\n ...translationAttributes('multiple-files-chosen', multipleFilesChosen),\n 'entered-drop-zone': enteredDropZone,\n 'left-drop-zone': leftDropZone,\n 'empty-class': emptyClass,\n 'dragging-class': draggingClass,\n 'disabled-class': disabledClass,\n })}\n </InitialStatus.Provider>\n );\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type DropZoneProps = PartProps<'div'>;\n\n/** The area that shows files are being dragged over it. Holds the button and the input. */\nexport function DropZone({ asChild, ...props }: DropZoneProps) {\n const Element = asChild ? Slot : 'div';\n // The element owns its disabled classes after upgrade.\n return <Element data-file-upload-drop-zone=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type InputProps = Omit<PartProps<'input'>, 'type'>;\n\n/** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */\nexport function Input({ asChild, ...props }: InputProps) {\n const Element = asChild ? Slot : 'input';\n // The element owns `id` and `hidden` after upgrade.\n return <Element type=\"file\" suppressHydrationWarning {...props} />;\n}\n\nexport type ButtonProps = PartProps<'button'>;\n\n/**\n * Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it\n * takes the input's id, so the input's label names it. Holds `Status`.\n */\nexport function Button({ asChild, ...props }: ButtonProps) {\n const Element = asChild ? Slot : 'button';\n // The element owns `id`, `hidden`, `disabled`, its ARIA and its classes after upgrade.\n return <Element data-file-upload-button=\"\" type=\"button\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type StatusProps = PartProps<'span'>;\n\n/** Which files are chosen: \"No file chosen\", the file's name, or how many files. In `Button`. */\nexport function Status({ asChild, children, ...props }: StatusProps) {\n const initial = useContext(InitialStatus);\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return (\n <Element data-file-upload-status=\"\" aria-live=\"polite\" suppressHydrationWarning {...props}>\n {children ?? initial}\n </Element>\n );\n}\n\nexport type SeparatorProps = PartProps<'span'>;\n\n/** Between the label and the button's text in the button's accessible name. Defaults to \", \". In `Button`. */\nexport function Separator({ asChild, children = ', ', ...props }: SeparatorProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its `id` after upgrade.\n return (\n <Element data-file-upload-separator=\"\" suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n\nexport type AnnouncementsProps = PartProps<'span'>;\n\n/** Announces entering and leaving the drop zone. Make it visually hidden. */\nexport function Announcements({ asChild, ...props }: AnnouncementsProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return <Element data-file-upload-announcements=\"\" aria-live=\"assertive\" suppressHydrationWarning {...props} />;\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const tagName = "govuk-react-focus-links";
@@ -0,0 +1,90 @@
1
+ /*
2
+ * <govuk-react-focus-links>: a headless, light-DOM custom element that makes links to a part of the
3
+ * same page move focus there, with or without React, as govuk-frontend's error summary and skip
4
+ * link do.
5
+ *
6
+ * Without JavaScript the browser goes to the target as usual. With it:
7
+ * - A link to a form field focuses the field and scrolls its label into view, or its fieldset's
8
+ * legend for a radio, a checkbox, or a field near the legend, so users see the question.
9
+ * - A link to anything else, such as the main content, focuses the target, giving it
10
+ * `tabindex="-1"` and `focused-class` until it loses focus.
11
+ *
12
+ * Attributes:
13
+ * - `focused-class`: classes for a target that isn't a form field while it has focus.
14
+ */
15
+ import { setFocus } from '../utils/set-focus.js';
16
+ import { classesOf } from '../utils/dom.js';
17
+ export const tagName = 'govuk-react-focus-links';
18
+ const isField = (element) => element instanceof HTMLInputElement ||
19
+ element instanceof HTMLSelectElement ||
20
+ element instanceof HTMLTextAreaElement ||
21
+ element instanceof HTMLButtonElement;
22
+ /** As govuk-frontend: the legend users need to see to understand the field, or else its label. */
23
+ function legendOrLabel(field) {
24
+ var _a, _b;
25
+ const legend = (_a = field.closest('fieldset')) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('legend')[0];
26
+ if (legend) {
27
+ if (field instanceof HTMLInputElement && (field.type === 'checkbox' || field.type === 'radio'))
28
+ return legend;
29
+ const legendTop = legend.getBoundingClientRect().top;
30
+ const fieldRect = field.getBoundingClientRect();
31
+ if (fieldRect.height &&
32
+ window.innerHeight &&
33
+ fieldRect.top + fieldRect.height - legendTop < window.innerHeight / 2) {
34
+ return legend;
35
+ }
36
+ }
37
+ return (_b = document.querySelector(`label[for="${CSS.escape(field.id)}"]`)) !== null && _b !== void 0 ? _b : field.closest('label');
38
+ }
39
+ if (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {
40
+ class GovukReactFocusLinks extends HTMLElement {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.onClick = (event) => {
44
+ var _a;
45
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey)
46
+ return;
47
+ const link = event.target instanceof Element ? event.target.closest('a[href]') : null;
48
+ if (!(link instanceof HTMLAnchorElement) || !this.contains(link))
49
+ return;
50
+ // A bare `#id` is this page whatever the `<base>`, as govuk-frontend's error summary treats it.
51
+ const samePage = ((_a = link.getAttribute('href')) === null || _a === void 0 ? void 0 : _a.startsWith('#')) ||
52
+ (link.origin === window.location.origin &&
53
+ link.pathname === window.location.pathname &&
54
+ link.search === window.location.search);
55
+ if (!samePage)
56
+ return;
57
+ let id = link.hash.slice(1);
58
+ try {
59
+ id = decodeURIComponent(id);
60
+ }
61
+ catch (_b) {
62
+ // A stray `%`: use the id as written.
63
+ }
64
+ const target = id ? document.getElementById(id) : null;
65
+ if (!target)
66
+ return;
67
+ if (isField(target)) {
68
+ const label = legendOrLabel(target);
69
+ if (!label)
70
+ return;
71
+ // Scroll to the question, not the field, which can hide it.
72
+ event.preventDefault();
73
+ label.scrollIntoView();
74
+ target.focus({ preventScroll: true });
75
+ return;
76
+ }
77
+ setFocus(target, { focusedClasses: classesOf(this.getAttribute('focused-class')) });
78
+ };
79
+ }
80
+ connectedCallback() {
81
+ this.addEventListener('click', this.onClick);
82
+ }
83
+ disconnectedCallback() {
84
+ this.removeEventListener('click', this.onClick);
85
+ }
86
+ }
87
+ if (!customElements.get(tagName))
88
+ customElements.define(tagName, GovukReactFocusLinks);
89
+ }
90
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/focus-links/element.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * <govuk-react-focus-links>: a headless, light-DOM custom element that makes links to a part of the\n * same page move focus there, with or without React, as govuk-frontend's error summary and skip\n * link do.\n *\n * Without JavaScript the browser goes to the target as usual. With it:\n * - A link to a form field focuses the field and scrolls its label into view, or its fieldset's\n * legend for a radio, a checkbox, or a field near the legend, so users see the question.\n * - A link to anything else, such as the main content, focuses the target, giving it\n * `tabindex=\"-1\"` and `focused-class` until it loses focus.\n *\n * Attributes:\n * - `focused-class`: classes for a target that isn't a form field while it has focus.\n */\n\nimport { setFocus } from '../utils/set-focus.js';\nimport { classesOf } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-focus-links';\n\nconst isField = (element: Element) =>\n element instanceof HTMLInputElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement ||\n element instanceof HTMLButtonElement;\n\n/** As govuk-frontend: the legend users need to see to understand the field, or else its label. */\nfunction legendOrLabel(field: HTMLElement) {\n const legend = field.closest('fieldset')?.getElementsByTagName('legend')[0];\n if (legend) {\n if (field instanceof HTMLInputElement && (field.type === 'checkbox' || field.type === 'radio')) return legend;\n const legendTop = legend.getBoundingClientRect().top;\n const fieldRect = field.getBoundingClientRect();\n if (\n fieldRect.height &&\n window.innerHeight &&\n fieldRect.top + fieldRect.height - legendTop < window.innerHeight / 2\n ) {\n return legend;\n }\n }\n return document.querySelector(`label[for=\"${CSS.escape(field.id)}\"]`) ?? field.closest('label');\n}\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactFocusLinks extends HTMLElement {\n private readonly onClick = (event: MouseEvent) => {\n if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey) return;\n const link = event.target instanceof Element ? event.target.closest('a[href]') : null;\n if (!(link instanceof HTMLAnchorElement) || !this.contains(link)) return;\n // A bare `#id` is this page whatever the `<base>`, as govuk-frontend's error summary treats it.\n const samePage =\n link.getAttribute('href')?.startsWith('#') ||\n (link.origin === window.location.origin &&\n link.pathname === window.location.pathname &&\n link.search === window.location.search);\n if (!samePage) return;\n let id = link.hash.slice(1);\n try {\n id = decodeURIComponent(id);\n } catch {\n // A stray `%`: use the id as written.\n }\n const target = id ? document.getElementById(id) : null;\n if (!target) return;\n if (isField(target)) {\n const label = legendOrLabel(target);\n if (!label) return;\n // Scroll to the question, not the field, which can hide it.\n event.preventDefault();\n label.scrollIntoView();\n target.focus({ preventScroll: true });\n return;\n }\n setFocus(target, { focusedClasses: classesOf(this.getAttribute('focused-class')) });\n };\n\n connectedCallback() {\n this.addEventListener('click', this.onClick);\n }\n\n disconnectedCallback() {\n this.removeEventListener('click', this.onClick);\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactFocusLinks);\n}\n"]}
@@ -1,10 +1,9 @@
1
1
  import * as React from 'react';
2
-
3
- type RootProps = React.HTMLAttributes<HTMLElement> & {
2
+ export type RootProps = React.HTMLAttributes<HTMLElement> & {
4
3
  /** Classes for a target that isn't a form field while it has focus. */
5
4
  focusedClass?: string;
6
5
  };
7
- declare function Root({ focusedClass, ...props }: RootProps): React.DOMElement<{
6
+ export declare function Root({ focusedClass, ...props }: RootProps): React.DOMElement<{
8
7
  'focused-class': string;
9
8
  defaultChecked?: boolean;
10
9
  defaultValue?: string | number | readonly string[];
@@ -14,17 +13,17 @@ declare function Root({ focusedClass, ...props }: RootProps): React.DOMElement<{
14
13
  autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | (string & {});
15
14
  autoFocus?: boolean;
16
15
  className?: string;
17
- contentEditable?: (boolean | "true" | "false") | "inherit" | "plaintext-only";
16
+ contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only";
18
17
  contextMenu?: string;
19
18
  dir?: string;
20
- draggable?: boolean | "true" | "false";
19
+ draggable?: boolean | "false" | "true";
21
20
  enterKeyHint?: "search" | "enter" | "done" | "go" | "next" | "previous" | "send";
22
21
  hidden?: boolean;
23
22
  id?: string;
24
23
  lang?: string;
25
24
  nonce?: string;
26
25
  slot?: string;
27
- spellCheck?: boolean | "true" | "false";
26
+ spellCheck?: boolean | "false" | "true";
28
27
  style?: React.CSSProperties;
29
28
  tabIndex?: number;
30
29
  title?: string;
@@ -57,57 +56,57 @@ declare function Root({ focusedClass, ...props }: RootProps): React.DOMElement<{
57
56
  popoverTargetAction?: "toggle" | "show" | "hide";
58
57
  popoverTarget?: string;
59
58
  inert?: boolean;
60
- inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal";
59
+ inputMode?: "search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal";
61
60
  is?: string;
62
61
  exportparts?: string;
63
62
  part?: string;
64
63
  "aria-activedescendant"?: string;
65
- "aria-atomic"?: boolean | "true" | "false";
64
+ "aria-atomic"?: boolean | "false" | "true";
66
65
  "aria-autocomplete"?: "none" | "list" | "inline" | "both";
67
66
  "aria-braillelabel"?: string;
68
67
  "aria-brailleroledescription"?: string;
69
- "aria-busy"?: boolean | "true" | "false";
70
- "aria-checked"?: boolean | "true" | "false" | "mixed";
68
+ "aria-busy"?: boolean | "false" | "true";
69
+ "aria-checked"?: boolean | "false" | "true" | "mixed";
71
70
  "aria-colcount"?: number;
72
71
  "aria-colindex"?: number;
73
72
  "aria-colindextext"?: string;
74
73
  "aria-colspan"?: number;
75
74
  "aria-controls"?: string;
76
- "aria-current"?: boolean | "time" | "true" | "false" | "page" | "step" | "location" | "date";
75
+ "aria-current"?: boolean | "time" | "false" | "true" | "page" | "step" | "location" | "date";
77
76
  "aria-describedby"?: string;
78
77
  "aria-description"?: string;
79
78
  "aria-details"?: string;
80
- "aria-disabled"?: boolean | "true" | "false";
81
- "aria-dropeffect"?: "link" | "none" | "copy" | "execute" | "move" | "popup";
79
+ "aria-disabled"?: boolean | "false" | "true";
80
+ "aria-dropeffect"?: "link" | "copy" | "none" | "execute" | "move" | "popup";
82
81
  "aria-errormessage"?: string;
83
- "aria-expanded"?: boolean | "true" | "false";
82
+ "aria-expanded"?: boolean | "false" | "true";
84
83
  "aria-flowto"?: string;
85
- "aria-grabbed"?: boolean | "true" | "false";
86
- "aria-haspopup"?: boolean | "dialog" | "menu" | "true" | "false" | "grid" | "listbox" | "tree";
87
- "aria-hidden"?: boolean | "true" | "false";
88
- "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling";
84
+ "aria-grabbed"?: boolean | "false" | "true";
85
+ "aria-haspopup"?: boolean | "dialog" | "menu" | "false" | "true" | "grid" | "listbox" | "tree";
86
+ "aria-hidden"?: boolean | "false" | "true";
87
+ "aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling";
89
88
  "aria-keyshortcuts"?: string;
90
89
  "aria-label"?: string;
91
90
  "aria-labelledby"?: string;
92
91
  "aria-level"?: number;
93
92
  "aria-live"?: "off" | "assertive" | "polite";
94
- "aria-modal"?: boolean | "true" | "false";
95
- "aria-multiline"?: boolean | "true" | "false";
96
- "aria-multiselectable"?: boolean | "true" | "false";
93
+ "aria-modal"?: boolean | "false" | "true";
94
+ "aria-multiline"?: boolean | "false" | "true";
95
+ "aria-multiselectable"?: boolean | "false" | "true";
97
96
  "aria-orientation"?: "horizontal" | "vertical";
98
97
  "aria-owns"?: string;
99
98
  "aria-placeholder"?: string;
100
99
  "aria-posinset"?: number;
101
- "aria-pressed"?: boolean | "true" | "false" | "mixed";
102
- "aria-readonly"?: boolean | "true" | "false";
100
+ "aria-pressed"?: boolean | "false" | "true" | "mixed";
101
+ "aria-readonly"?: boolean | "false" | "true";
103
102
  "aria-relevant"?: "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals";
104
- "aria-required"?: boolean | "true" | "false";
103
+ "aria-required"?: boolean | "false" | "true";
105
104
  "aria-roledescription"?: string;
106
105
  "aria-rowcount"?: number;
107
106
  "aria-rowindex"?: number;
108
107
  "aria-rowindextext"?: string;
109
108
  "aria-rowspan"?: number;
110
- "aria-selected"?: boolean | "true" | "false";
109
+ "aria-selected"?: boolean | "false" | "true";
111
110
  "aria-setsize"?: number;
112
111
  "aria-sort"?: "none" | "ascending" | "descending" | "other";
113
112
  "aria-valuemax"?: number;
@@ -287,13 +286,3 @@ declare function Root({ focusedClass, ...props }: RootProps): React.DOMElement<{
287
286
  onTransitionStart?: React.TransitionEventHandler<HTMLElement>;
288
287
  onTransitionStartCapture?: React.TransitionEventHandler<HTMLElement>;
289
288
  }, Element>;
290
-
291
- declare const index_Root: typeof Root;
292
- type index_RootProps = RootProps;
293
- declare namespace index {
294
- export { index_Root as Root };
295
- export type { index_RootProps as RootProps };
296
- }
297
-
298
- export { Root as R, index as i };
299
- export type { RootProps as a };
@@ -0,0 +1,7 @@
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { tagName } from './element.js';
4
+ export function Root({ focusedClass, ...props }) {
5
+ return React.createElement(tagName, { ...props, 'focused-class': focusedClass });
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/focus-links/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAavC,MAAM,UAAU,IAAI,CAAC,EAAE,YAAY,EAAE,GAAG,KAAK,EAAa;IACxD,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { tagName } from './element.js';\n\n/*\n * Headless focus links: the <govuk-react-focus-links> element (./element.ts) makes links to a part\n * of the same page, inside it, move focus there. Links to a form field also scroll its label or\n * legend into view.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Classes for a target that isn't a form field while it has focus. */\n focusedClass?: string;\n};\n\nexport function Root({ focusedClass, ...props }: RootProps) {\n return React.createElement(tagName, { ...props, 'focused-class': focusedClass });\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,17 +1,13 @@
1
- export { i as Accordion } from './index-DMWpkC_d.js';
2
- export { i as Tabs } from './index--FxJgSOS.js';
3
- export { i as Modal } from './index-CikOyFud.js';
4
- export { i as PasswordInput } from './index-sEHnx4-M.js';
5
- export { i as Disclosure } from './index-D4Gzyvfu.js';
6
- export { i as CharacterCount } from './index-D8N5vxTL.js';
7
- export { i as Choices } from './index-WuGvkTxu.js';
8
- export { i as AutoFocus } from './index-Bul0NJh_.js';
9
- export { i as FocusLinks } from './index-BR3MAGF8.js';
10
- export { i as Button } from './index-DN7fGMc3.js';
11
- export { i as ExitThisPage } from './index-qF0jIQCW.js';
12
- export { i as FileUpload } from './index-DPXR1Yua.js';
13
- export { i as Autocomplete } from './index-D7lMYMUR.js';
14
- import 'react';
15
- import './translation-BnpO2mN2.js';
16
- import './exit-this-page-element.js';
17
- import './autocomplete-element.js';
1
+ export * as Accordion from './accordion/index.js';
2
+ export * as Tabs from './tabs/index.js';
3
+ export * as Modal from './modal/index.js';
4
+ export * as PasswordInput from './password-input/index.js';
5
+ export * as Disclosure from './disclosure/index.js';
6
+ export * as CharacterCount from './character-count/index.js';
7
+ export * as Choices from './choices/index.js';
8
+ export * as AutoFocus from './auto-focus/index.js';
9
+ export * as FocusLinks from './focus-links/index.js';
10
+ export * as Button from './button/index.js';
11
+ export * as ExitThisPage from './exit-this-page/index.js';
12
+ export * as FileUpload from './file-upload/index.js';
13
+ export * as Autocomplete from './autocomplete/index.js';
package/dist/index.js CHANGED
@@ -1,73 +1,14 @@
1
- 'use client';
2
- import {
3
- autocomplete_exports
4
- } from "./chunk-XJYLFTYE.js";
5
- import "./chunk-U5OKNKYC.js";
6
- import {
7
- choices_exports
8
- } from "./chunk-TJVBFRIE.js";
9
- import "./chunk-ET7DCQM7.js";
10
- import {
11
- focus_links_exports
12
- } from "./chunk-2IHAQAYF.js";
13
- import "./chunk-PNWPGD7B.js";
14
- import {
15
- file_upload_exports
16
- } from "./chunk-5HWRMQK2.js";
17
- import "./chunk-YCESNTXQ.js";
18
- import {
19
- password_input_exports
20
- } from "./chunk-ZTJLVNR4.js";
21
- import "./chunk-TE4RUYVK.js";
22
- import {
23
- character_count_exports
24
- } from "./chunk-QLQ6O7OW.js";
25
- import "./chunk-UXJO4AJP.js";
26
- import "./chunk-RDUPELOK.js";
27
- import {
28
- auto_focus_exports
29
- } from "./chunk-6ZFU4VYW.js";
30
- import "./chunk-XGK73UCD.js";
31
- import "./chunk-LWIA644X.js";
32
- import {
33
- button_exports
34
- } from "./chunk-2ZJVSNC2.js";
35
- import "./chunk-VNXXENCU.js";
36
- import {
37
- exit_this_page_exports
38
- } from "./chunk-4XAR4FFG.js";
39
- import "./chunk-ECYGKE4D.js";
40
- import {
41
- accordion_exports
42
- } from "./chunk-DPERPCUH.js";
43
- import "./chunk-B2I4J5NL.js";
44
- import {
45
- disclosure_exports
46
- } from "./chunk-GVGBDSDN.js";
47
- import "./chunk-RPMHI67T.js";
48
- import {
49
- tabs_exports
50
- } from "./chunk-F5XFC4QJ.js";
51
- import "./chunk-IZQ2C4BC.js";
52
- import {
53
- modal_exports
54
- } from "./chunk-47NMY4SS.js";
55
- import "./chunk-L7E6GN2D.js";
56
- import "./chunk-NX4B3NKM.js";
57
- import "./chunk-ESBMTI25.js";
58
- export {
59
- accordion_exports as Accordion,
60
- auto_focus_exports as AutoFocus,
61
- autocomplete_exports as Autocomplete,
62
- button_exports as Button,
63
- character_count_exports as CharacterCount,
64
- choices_exports as Choices,
65
- disclosure_exports as Disclosure,
66
- exit_this_page_exports as ExitThisPage,
67
- file_upload_exports as FileUpload,
68
- focus_links_exports as FocusLinks,
69
- modal_exports as Modal,
70
- password_input_exports as PasswordInput,
71
- tabs_exports as Tabs
72
- };
1
+ export * as Accordion from './accordion/index.js';
2
+ export * as Tabs from './tabs/index.js';
3
+ export * as Modal from './modal/index.js';
4
+ export * as PasswordInput from './password-input/index.js';
5
+ export * as Disclosure from './disclosure/index.js';
6
+ export * as CharacterCount from './character-count/index.js';
7
+ export * as Choices from './choices/index.js';
8
+ export * as AutoFocus from './auto-focus/index.js';
9
+ export * as FocusLinks from './focus-links/index.js';
10
+ export * as Button from './button/index.js';
11
+ export * as ExitThisPage from './exit-this-page/index.js';
12
+ export * as FileUpload from './file-upload/index.js';
13
+ export * as Autocomplete from './autocomplete/index.js';
73
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC","sourcesContent":["export * as Accordion from './accordion/index.js';\nexport * as Tabs from './tabs/index.js';\nexport * as Modal from './modal/index.js';\nexport * as PasswordInput from './password-input/index.js';\nexport * as Disclosure from './disclosure/index.js';\nexport * as CharacterCount from './character-count/index.js';\nexport * as Choices from './choices/index.js';\nexport * as AutoFocus from './auto-focus/index.js';\nexport * as FocusLinks from './focus-links/index.js';\nexport * as Button from './button/index.js';\nexport * as ExitThisPage from './exit-this-page/index.js';\nexport * as FileUpload from './file-upload/index.js';\nexport * as Autocomplete from './autocomplete/index.js';\n"]}
@@ -1 +1 @@
1
- "use strict";(()=>{var u="govuk-react-accordion",m={"show-section-text":"Show","hide-section-text":"Hide","show-section-label":"Show this section","hide-section-label":"Hide this section","show-all-sections-text":"Show all sections","hide-all-sections-text":"Hide all sections"},c=a=>a?.split(/\s+/).filter(Boolean),g=(a,d)=>{a.textContent!==d&&(a.textContent=d)},f=a=>a?.split(/\s+/).filter(Boolean)??[];if(typeof HTMLElement<"u"&&typeof customElements<"u"){class a extends HTMLElement{constructor(){super(...arguments);this.open=new Set;this.upgraded=!1;this.controlled=!1;this.prepared=new WeakSet;this.onClick=e=>{let t=e.target instanceof Element?e.target:null,s=t?.closest("button[data-accordion-trigger]");if(s&&this.ownsElement(s)){let n=this.sectionOf(s)?.dataset.value;if(n===void 0)return;let r=new Set(this.open);r.has(n)?r.delete(n):r.add(n),this.change(r);return}let i=t?.closest("button[data-accordion-show-all]");if(i&&this.ownsElement(i)){let n=this.sections.map(r=>r.dataset.value??"");this.change(new Set(this.allOpen?[]:n))}};this.onBeforeMatch=e=>{let s=(e.target instanceof Element?this.sectionOf(e.target):void 0)?.dataset.value;s===void 0||this.open.has(s)||this.change(new Set([...this.open,s]),!0)}}static get observedAttributes(){return["value"]}get openValues(){return this.upgraded?[...this.open]:void 0}get pickedValue(){return this.picked}connectedCallback(){this.observer=new MutationObserver(e=>{if(!this.upgraded){this.setup();return}e.some(t=>t.type==="childList")&&this.sections.forEach(t=>this.prepare(t)),this.render()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),this.upgraded?(this.listen(),this.render()):this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener("click",this.onClick),this.removeEventListener("beforematch",this.onBeforeMatch,!0)}attributeChangedCallback(){let e=c(this.getAttribute("value"));this.controlled=e!==void 0,e&&(this.open=new Set(e),this.render())}get sections(){return this.own("[data-accordion-section]")}get allOpen(){return this.sections.every(e=>this.open.has(e.dataset.value??""))}own(e){return Array.from(this.querySelectorAll(e)).filter(t=>this.ownsElement(t))}ownsElement(e){return e.closest(u)===this}sectionOf(e){let t=e.closest("[data-accordion-section]");return t&&this.ownsElement(t)?t:void 0}find(e,t){return Array.from(e.querySelectorAll(t)).find(s=>this.sectionOf(s)===e)}text(e){return this.getAttribute(e)??m[e]}get remember(){return this.getAttribute("remember-expanded")!=="false"}setup(){let e=this.sections;if(!e.some(i=>this.find(i,"button[data-accordion-trigger]")))return;this.upgraded=!0;let t=c(this.getAttribute("value"));this.controlled=t!==void 0,this.open=new Set(t??c(this.getAttribute("default-value"))),this.dataset.upgraded="";let s=f(this.getAttribute("upgraded-class"));s.length&&this.classList.add(...s),this.own("[data-accordion-controls]").forEach(i=>{i.hidden=!1}),e.forEach(i=>this.prepare(i)),this.listen(),this.render()}listen(){this.addEventListener("click",this.onClick),this.addEventListener("beforematch",this.onBeforeMatch,!0)}prepare(e){let t=this.find(e,"button[data-accordion-trigger]");if(!t||this.prepared.has(e))return;this.prepared.add(e);let s=e.dataset.value??"";if(!this.controlled){let n=c(this.getAttribute("default-value"));(n?n.includes(s):e.hasAttribute("data-expanded"))&&this.open.add(s),this.restore(e)}Array.from(e.querySelectorAll("[data-accordion-fallback]")).filter(n=>this.sectionOf(n)===e).forEach(n=>{n.hidden=!0}),t.hidden=!1;let i=this.find(e,"[data-accordion-content]");i?.id&&t.setAttribute("aria-controls",i.id)}restore(e){let t=this.find(e,"[data-accordion-content]")?.id,s=e.dataset.value;if(!(!this.remember||!t||s===void 0))try{let i=window.sessionStorage.getItem(t);i==="true"?this.open.add(s):i==="false"&&this.open.delete(s)}catch{}}store(e){this.remember&&this.sections.forEach(t=>{let s=t.dataset.value??"",i=this.find(t,"[data-accordion-content]")?.id;if(!(!i||e.has(s)===this.open.has(s)))try{window.sessionStorage.setItem(i,String(this.open.has(s)))}catch{}})}change(e,t=!1){let s=this.sections.map(i=>i.dataset.value??"").filter(i=>e.has(i));if(!this.controlled||t){let i=this.open;this.open=new Set(s),this.controlled||(this.picked=s,this.store(i)),this.render()}this.dispatchEvent(new CustomEvent("govuk-react-accordion:change",{detail:{value:s},bubbles:!0}))}render(){if(!this.upgraded)return;let e=f(this.getAttribute("expanded-section-class")),t=f(this.getAttribute("collapsed-icon-class")),s=(n,r)=>{Array.from(n.querySelectorAll("[data-accordion-icon]")).forEach(o=>{t.forEach(l=>o.classList.toggle(l,!r))})};this.sections.forEach(n=>{let r=this.open.has(n.dataset.value??""),o=this.find(n,"button[data-accordion-trigger]"),l=this.find(n,"[data-accordion-content]");if(n.dataset.state=r?"open":"closed",e.forEach(h=>n.classList.toggle(h,r)),l&&(r?l.removeAttribute("hidden"):l.setAttribute("hidden","until-found")),!o)return;o.setAttribute("aria-expanded",String(r));let v=Array.from(o.querySelectorAll("[data-accordion-label]")).map(h=>h.textContent?.trim()??"");o.setAttribute("aria-label",[...v,this.text(r?"hide-section-label":"show-section-label")].join(" , "));let p=o.querySelector("[data-accordion-toggle-text]");p&&g(p,this.text(r?"hide-section-text":"show-section-text")),s(o,r)});let i=this.allOpen;this.own("button[data-accordion-show-all]").forEach(n=>{n.setAttribute("aria-expanded",String(i));let r=n.querySelector("[data-accordion-show-all-text]");r&&g(r,this.text(i?"hide-all-sections-text":"show-all-sections-text")),s(n,i)})}}customElements.get(u)||customElements.define(u,a)}})();
1
+ "use strict";(()=>{var d=a=>a?.split(/\s+/).filter(Boolean)??[];function p(a,c){if(a.textContent===c)return;let{firstChild:u}=a;u instanceof Text&&a.childNodes.length===1?u.nodeValue=c:a.textContent=c}var g="govuk-react-accordion",m={"show-section-text":"Show","hide-section-text":"Hide","show-section-label":"Show this section","hide-section-label":"Hide this section","show-all-sections-text":"Show all sections","hide-all-sections-text":"Hide all sections"},h=a=>a?.split(/\s+/).filter(Boolean);if(typeof HTMLElement<"u"&&typeof customElements<"u"){class a extends HTMLElement{constructor(){super(...arguments);this.open=new Set;this.upgraded=!1;this.controlled=!1;this.prepared=new WeakSet;this.onClick=t=>{let e=t.target instanceof Element?t.target:null,s=e?.closest("button[data-accordion-trigger]");if(s&&this.ownsElement(s)){let n=this.sectionOf(s)?.dataset.value;if(n===void 0)return;let r=new Set(this.open);r.has(n)?r.delete(n):r.add(n),this.change(r);return}let i=e?.closest("button[data-accordion-show-all]");if(i&&this.ownsElement(i)){let n=this.sections.map(r=>r.dataset.value??"");this.change(new Set(this.allOpen?[]:n))}};this.onBeforeMatch=t=>{let s=(t.target instanceof Element?this.sectionOf(t.target):void 0)?.dataset.value;s===void 0||this.open.has(s)||this.change(new Set([...this.open,s]),!0)}}static get observedAttributes(){return["value"]}get openValues(){return this.upgraded?[...this.open]:void 0}get pickedValue(){return this.picked}connectedCallback(){this.observer=new MutationObserver(t=>{if(!this.upgraded){this.setup();return}t.some(e=>e.type==="childList")&&this.sections.forEach(e=>this.prepare(e)),this.render()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),this.upgraded?(this.listen(),this.render()):this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener("click",this.onClick),this.removeEventListener("beforematch",this.onBeforeMatch,!0)}attributeChangedCallback(){let t=h(this.getAttribute("value"));this.controlled=t!==void 0,t&&(this.open=new Set(t),this.render())}get sections(){return this.own("[data-accordion-section]")}get allOpen(){return this.sections.every(t=>this.open.has(t.dataset.value??""))}own(t){return Array.from(this.querySelectorAll(t)).filter(e=>this.ownsElement(e))}ownsElement(t){return t.closest(g)===this}sectionOf(t){let e=t.closest("[data-accordion-section]");return e&&this.ownsElement(e)?e:void 0}find(t,e){return Array.from(t.querySelectorAll(e)).find(s=>this.sectionOf(s)===t)}text(t){return this.getAttribute(t)??m[t]}get remember(){return this.getAttribute("remember-expanded")!=="false"}setup(){let t=this.sections;if(!t.some(i=>this.find(i,"button[data-accordion-trigger]")))return;this.upgraded=!0;let e=h(this.getAttribute("value"));this.controlled=e!==void 0,this.open=new Set(e??h(this.getAttribute("default-value"))),this.dataset.upgraded="";let s=d(this.getAttribute("upgraded-class"));s.length&&this.classList.add(...s),this.own("[data-accordion-controls]").forEach(i=>{i.hidden=!1}),t.forEach(i=>this.prepare(i)),this.listen(),this.render()}listen(){this.addEventListener("click",this.onClick),this.addEventListener("beforematch",this.onBeforeMatch,!0)}prepare(t){let e=this.find(t,"button[data-accordion-trigger]");if(!e||this.prepared.has(t))return;this.prepared.add(t);let s=t.dataset.value??"";if(!this.controlled){let n=h(this.getAttribute("default-value"));(n?n.includes(s):t.hasAttribute("data-expanded"))&&this.open.add(s),this.restore(t)}Array.from(t.querySelectorAll("[data-accordion-fallback]")).filter(n=>this.sectionOf(n)===t).forEach(n=>{n.hidden=!0}),e.hidden=!1;let i=this.find(t,"[data-accordion-content]");i?.id&&e.setAttribute("aria-controls",i.id)}restore(t){let e=this.find(t,"[data-accordion-content]")?.id,s=t.dataset.value;if(!(!this.remember||!e||s===void 0))try{let i=window.sessionStorage.getItem(e);i==="true"?this.open.add(s):i==="false"&&this.open.delete(s)}catch{}}store(t){this.remember&&this.sections.forEach(e=>{let s=e.dataset.value??"",i=this.find(e,"[data-accordion-content]")?.id;if(!(!i||t.has(s)===this.open.has(s)))try{window.sessionStorage.setItem(i,String(this.open.has(s)))}catch{}})}change(t,e=!1){let s=this.sections.map(i=>i.dataset.value??"").filter(i=>t.has(i));if(!this.controlled||e){let i=this.open;this.open=new Set(s),this.controlled||(this.picked=s,this.store(i)),this.render()}this.dispatchEvent(new CustomEvent("govuk-react-accordion:change",{detail:{value:s},bubbles:!0}))}render(){if(!this.upgraded)return;let t=d(this.getAttribute("expanded-section-class")),e=d(this.getAttribute("collapsed-icon-class")),s=(n,r)=>{Array.from(n.querySelectorAll("[data-accordion-icon]")).forEach(o=>{e.forEach(l=>o.classList.toggle(l,!r))})};this.sections.forEach(n=>{let r=this.open.has(n.dataset.value??""),o=this.find(n,"button[data-accordion-trigger]"),l=this.find(n,"[data-accordion-content]");if(n.dataset.state=r?"open":"closed",t.forEach(f=>n.classList.toggle(f,r)),l&&(r?l.removeAttribute("hidden"):l.setAttribute("hidden","until-found")),!o)return;o.setAttribute("aria-expanded",String(r));let b=Array.from(o.querySelectorAll("[data-accordion-label]")).map(f=>f.textContent?.trim()??"");o.setAttribute("aria-label",[...b,this.text(r?"hide-section-label":"show-section-label")].join(" , "));let v=o.querySelector("[data-accordion-toggle-text]");v&&p(v,this.text(r?"hide-section-text":"show-section-text")),s(o,r)});let i=this.allOpen;this.own("button[data-accordion-show-all]").forEach(n=>{n.setAttribute("aria-expanded",String(i));let r=n.querySelector("[data-accordion-show-all-text]");r&&p(r,this.text(i?"hide-all-sections-text":"show-all-sections-text")),s(n,i)})}}customElements.get(g)||customElements.define(g,a)}})();
@@ -1 +1 @@
1
- "use strict";(()=>{function o(t,i,s){s.forEach(e=>t.classList.remove(e)),i&&t.removeAttribute("tabindex"),t.removeAttribute("data-focus-tabindex"),t.removeAttribute("autofocus")}var c=t=>!t.hasAttribute("tabindex")||t.hasAttribute("data-focus-tabindex")&&t.getAttribute("tabindex")==="-1";function n(t){o(t,t.hasAttribute("tabindex")&&c(t),[])}function u(t,{focusedClasses:i=[],preventScroll:s=!1}={}){let e=c(t);return t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),document.activeElement!==t&&(i.forEach(r=>t.classList.add(r)),t.focus({preventScroll:s})),document.activeElement!==t?(o(t,e,i),!1):(i.forEach(r=>t.classList.add(r)),t.addEventListener("blur",()=>o(t,e,i),{once:!0}),!0)}var a="govuk-react-auto-focus";if(typeof HTMLElement<"u"&&typeof customElements<"u"){class t extends HTMLElement{constructor(){super(...arguments);this.focused=!1}connectedCallback(){this.focusTarget()||(this.observer=new MutationObserver(()=>{this.focusTarget()&&this.observer?.disconnect()}),this.observer.observe(this,{childList:!0,subtree:!0}))}disconnectedCallback(){this.observer?.disconnect()}get target(){let e=Array.from(this.querySelectorAll("[data-auto-focus]")).find(r=>r.closest(a)===this)??this.firstElementChild;return e instanceof HTMLElement?e:void 0}focusTarget(){if(this.focused)return!0;let{target:e}=this;if(!e)return!1;if(this.focused=!0,this.hasAttribute("disabled"))return!0;if(e.hasAttribute("autofocus")){let r=document.activeElement;if(r===e)return u(e,{preventScroll:!0}),!0;if(r&&r!==document.body)return n(e),!0}return queueMicrotask(()=>{(!e.isConnected||!u(e))&&(this.focused=!1)}),!0}}customElements.get(a)||customElements.define(a,t)}})();
1
+ "use strict";(()=>{function s(t,r,o){o.forEach(e=>t.classList.remove(e)),r&&t.removeAttribute("tabindex"),t.removeAttribute("data-focus-tabindex"),t.removeAttribute("autofocus")}var a=t=>!t.hasAttribute("tabindex")||t.hasAttribute("data-focus-tabindex")&&t.getAttribute("tabindex")==="-1";function c(t){s(t,t.hasAttribute("tabindex")&&a(t),[])}function u(t,{focusedClasses:r=[],preventScroll:o=!1}={}){let e=a(t);return t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),document.activeElement!==t&&(r.forEach(i=>t.classList.add(i)),t.focus({preventScroll:o})),document.activeElement!==t?(s(t,e,r),!1):(r.forEach(i=>t.classList.add(i)),t.addEventListener("blur",()=>s(t,e,r),{once:!0}),!0)}function d(t,r){if(r())return;let o=new MutationObserver(()=>{r()&&o.disconnect()});return o.observe(t,{childList:!0,subtree:!0}),o}var n="govuk-react-auto-focus";if(typeof HTMLElement<"u"&&typeof customElements<"u"){class t extends HTMLElement{constructor(){super(...arguments);this.focused=!1}connectedCallback(){this.observer=d(this,()=>this.focusTarget())}disconnectedCallback(){this.observer?.disconnect()}get target(){let e=Array.from(this.querySelectorAll("[data-auto-focus]")).find(i=>i.closest(n)===this)??this.firstElementChild;return e instanceof HTMLElement?e:void 0}focusTarget(){if(this.focused)return!0;let{target:e}=this;if(!e)return!1;if(this.focused=!0,this.hasAttribute("disabled"))return!0;if(e.hasAttribute("autofocus")){let i=document.activeElement;if(i===e)return u(e,{preventScroll:!0}),!0;if(i&&i!==document.body)return c(e),!0}return queueMicrotask(()=>{(!e.isConnected||!u(e))&&(this.focused=!1)}),!0}}customElements.get(n)||customElements.define(n,t)}})();