whitehall-ui 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +4 -1
  2. package/dist/{chunk-KWAC6IEK.js → chunk-2KB4IAMZ.js} +9 -22
  3. package/dist/{chunk-5TI2WXYU.js → chunk-3UX7QPLM.js} +10 -21
  4. package/dist/{chunk-SK27BMU5.js → chunk-4GQRYMDK.js} +11 -23
  5. package/dist/{chunk-OP35ZJ4X.js → chunk-4TBXH62Z.js} +6 -7
  6. package/dist/{chunk-M6CLPMRP.js → chunk-6WLHJ5MN.js} +34 -76
  7. package/dist/chunk-7IOR7UNU.js +77 -0
  8. package/dist/chunk-7Q2C5RB7.js +167 -0
  9. package/dist/{chunk-5PIQJ22R.js → chunk-ASBIQC77.js} +13 -18
  10. package/dist/{chunk-KD4LPFIZ.js → chunk-C2YQVLZ7.js} +15 -18
  11. package/dist/chunk-CBT6WCJ7.js +52 -0
  12. package/dist/{chunk-3YIKJK6M.js → chunk-CYBPAHLZ.js} +48 -52
  13. package/dist/{chunk-VB6V3PHD.js → chunk-D2T6BUOB.js} +6 -16
  14. package/dist/chunk-DZ3743JO.js +38 -0
  15. package/dist/{chunk-AO6HPG4R.js → chunk-EDOSCND4.js} +5 -20
  16. package/dist/chunk-FJHNUBEM.js +59 -0
  17. package/dist/chunk-FVBDMMNR.js +143 -0
  18. package/dist/chunk-GKHD33N6.js +52 -0
  19. package/dist/{chunk-3INCIYDO.js → chunk-GLDCEDTR.js} +22 -77
  20. package/dist/{chunk-G6T44BDV.js → chunk-HBLVAX45.js} +7 -11
  21. package/dist/{chunk-UWQFFFTB.js → chunk-JCERRZV6.js} +13 -13
  22. package/dist/chunk-KXQGZLMK.js +120 -0
  23. package/dist/{chunk-CEPBVMFU.js → chunk-MFI5R2TJ.js} +1 -3
  24. package/dist/{chunk-5XNKIBMP.js → chunk-MYMVHSRJ.js} +3 -4
  25. package/dist/chunk-N5PY3VZH.js +192 -0
  26. package/dist/{chunk-P4GCF5FQ.js → chunk-OQILIT3B.js} +26 -15
  27. package/dist/{chunk-6VXVJERU.js → chunk-QKR7NELW.js} +4 -8
  28. package/dist/chunk-QPN5J5IU.js +177 -0
  29. package/dist/chunk-RGXB6M3G.js +87 -0
  30. package/dist/chunk-TAVSU2XB.js +90 -0
  31. package/dist/chunk-TGNN5ZP3.js +81 -0
  32. package/dist/chunk-TICBCBDN.js +18 -0
  33. package/dist/{chunk-7ZCZQN5N.js → chunk-UK7RLSTJ.js} +15 -22
  34. package/dist/chunk-UXOJELVU.js +37 -0
  35. package/dist/{chunk-QTSEOPVX.js → chunk-VCJE5UO2.js} +23 -25
  36. package/dist/{chunk-N67H5OUQ.js → chunk-VHSAXVCF.js} +7 -5
  37. package/dist/chunk-VMI2XU5D.js +74 -0
  38. package/dist/{chunk-TXGBUZB4.js → chunk-VRGDQ3SF.js} +3 -10
  39. package/dist/chunk-W4CWUYTA.js +44 -0
  40. package/dist/{chunk-LRNZYPC2.js → chunk-YF6EZ57H.js} +14 -44
  41. package/dist/chunk-ZAKQHDVD.js +40 -0
  42. package/dist/chunk-ZJB7BBTN.js +188 -0
  43. package/dist/index.d.ts +15 -13
  44. package/dist/index.js +41 -39
  45. package/dist/lib/utils.d.ts +2 -1
  46. package/dist/lib/utils.js +1 -1
  47. package/dist/ui/accordion.d.ts +8 -13
  48. package/dist/ui/accordion.js +2 -2
  49. package/dist/ui/back-link.d.ts +4 -4
  50. package/dist/ui/back-link.js +2 -2
  51. package/dist/ui/breadcrumbs.d.ts +10 -16
  52. package/dist/ui/breadcrumbs.js +2 -2
  53. package/dist/ui/button.d.ts +7 -8
  54. package/dist/ui/button.js +2 -2
  55. package/dist/ui/character-count.d.ts +11 -15
  56. package/dist/ui/character-count.js +3 -3
  57. package/dist/ui/checkboxes.d.ts +9 -17
  58. package/dist/ui/checkboxes.js +2 -2
  59. package/dist/ui/cookie-banner.d.ts +12 -21
  60. package/dist/ui/cookie-banner.js +2 -2
  61. package/dist/ui/date-input.d.ts +10 -16
  62. package/dist/ui/date-input.js +2 -2
  63. package/dist/ui/details.d.ts +8 -17
  64. package/dist/ui/details.js +2 -2
  65. package/dist/ui/error-message.d.ts +4 -4
  66. package/dist/ui/error-message.js +2 -2
  67. package/dist/ui/error-summary.d.ts +5 -4
  68. package/dist/ui/error-summary.js +2 -2
  69. package/dist/ui/exit-this-page.d.ts +4 -4
  70. package/dist/ui/exit-this-page.js +3 -3
  71. package/dist/ui/feedback.d.ts +13 -0
  72. package/dist/ui/feedback.js +2 -0
  73. package/dist/ui/fieldset.d.ts +9 -13
  74. package/dist/ui/fieldset.js +2 -2
  75. package/dist/ui/file-upload.d.ts +4 -5
  76. package/dist/ui/file-upload.js +2 -2
  77. package/dist/ui/footer.d.ts +39 -50
  78. package/dist/ui/footer.js +2 -2
  79. package/dist/ui/generic-header.d.ts +10 -15
  80. package/dist/ui/generic-header.js +2 -2
  81. package/dist/ui/header.d.ts +14 -32
  82. package/dist/ui/header.js +2 -2
  83. package/dist/ui/hint.d.ts +4 -5
  84. package/dist/ui/hint.js +2 -2
  85. package/dist/ui/inset-text.d.ts +4 -5
  86. package/dist/ui/inset-text.js +2 -2
  87. package/dist/ui/label.d.ts +7 -9
  88. package/dist/ui/label.js +2 -2
  89. package/dist/ui/language-navigation.d.ts +20 -0
  90. package/dist/ui/language-navigation.js +2 -0
  91. package/dist/ui/link.d.ts +5 -6
  92. package/dist/ui/link.js +2 -2
  93. package/dist/ui/notification-banner.d.ts +15 -24
  94. package/dist/ui/notification-banner.js +2 -2
  95. package/dist/ui/pagination.d.ts +20 -34
  96. package/dist/ui/pagination.js +2 -2
  97. package/dist/ui/panel.d.ts +11 -12
  98. package/dist/ui/panel.js +2 -2
  99. package/dist/ui/password-input.d.ts +7 -6
  100. package/dist/ui/password-input.js +4 -4
  101. package/dist/ui/phase-banner.d.ts +10 -17
  102. package/dist/ui/phase-banner.js +2 -2
  103. package/dist/ui/radios.d.ts +8 -13
  104. package/dist/ui/radios.js +2 -2
  105. package/dist/ui/select.d.ts +6 -30
  106. package/dist/ui/select.js +2 -2
  107. package/dist/ui/service-navigation.d.ts +15 -23
  108. package/dist/ui/service-navigation.js +2 -2
  109. package/dist/ui/skip-link.d.ts +4 -5
  110. package/dist/ui/skip-link.js +2 -2
  111. package/dist/ui/summary-list.d.ts +24 -41
  112. package/dist/ui/summary-list.js +2 -2
  113. package/dist/ui/table.d.ts +21 -26
  114. package/dist/ui/table.js +2 -2
  115. package/dist/ui/tabs.d.ts +7 -9
  116. package/dist/ui/tabs.js +2 -2
  117. package/dist/ui/tag.d.ts +4 -6
  118. package/dist/ui/tag.js +2 -2
  119. package/dist/ui/task-list.d.ts +14 -23
  120. package/dist/ui/task-list.js +2 -2
  121. package/dist/ui/text-input.d.ts +5 -6
  122. package/dist/ui/text-input.js +2 -2
  123. package/dist/ui/textarea.d.ts +4 -6
  124. package/dist/ui/textarea.js +2 -2
  125. package/dist/ui/warning-text.d.ts +4 -4
  126. package/dist/ui/warning-text.js +2 -2
  127. package/package.json +111 -263
  128. package/registry/default/theme/govuk-tokens.css +207 -40
  129. package/dist/chunk-2QKZ6DPC.js +0 -27
  130. package/dist/chunk-4MXR4WNS.js +0 -17
  131. package/dist/chunk-5AKGRLG2.js +0 -190
  132. package/dist/chunk-5H55YDJS.js +0 -69
  133. package/dist/chunk-72PH2FMG.js +0 -180
  134. package/dist/chunk-GUZIKVAE.js +0 -119
  135. package/dist/chunk-JESMK3XK.js +0 -105
  136. package/dist/chunk-JFZN5XP6.js +0 -88
  137. package/dist/chunk-NRXTKHI2.js +0 -169
  138. package/dist/chunk-PGZHPAT5.js +0 -183
  139. package/dist/chunk-RPV43YDC.js +0 -93
  140. package/dist/chunk-VQOCX44T.js +0 -41
  141. package/dist/chunk-WONVZ7WK.js +0 -29
  142. package/dist/chunk-WPPWPEFV.js +0 -150
  143. package/dist/chunk-XQOYWPKV.js +0 -48
  144. package/dist/chunk-YAKI4SI7.js +0 -205
  145. package/dist/chunk-YCLGXX3R.js +0 -68
@@ -0,0 +1,120 @@
1
+ import { cn, mergeRefs } from './chunk-GKHD33N6.js';
2
+ import { useRef, useEffect } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ var NotificationBanner = ({
6
+ className,
7
+ variant = "default",
8
+ disableAutoFocus,
9
+ ref,
10
+ ...props
11
+ }) => {
12
+ const innerRef = useRef(null);
13
+ useEffect(() => {
14
+ const node = innerRef.current;
15
+ if (variant !== "success" || disableAutoFocus || !node) return;
16
+ node.setAttribute("tabindex", "-1");
17
+ node.addEventListener("blur", () => node.removeAttribute("tabindex"), {
18
+ once: true
19
+ });
20
+ node.focus();
21
+ }, [variant, disableAutoFocus]);
22
+ return /* @__PURE__ */ jsx(
23
+ "section",
24
+ {
25
+ ref: mergeRefs(innerRef, ref),
26
+ role: variant === "success" ? "alert" : void 0,
27
+ "aria-labelledby": "govuk-notification-banner-title",
28
+ "data-variant": variant,
29
+ className: cn(
30
+ "group/banner font-govuk text-govuk-body",
31
+ "mb-govuk-6 sm:mb-govuk-8",
32
+ variant === "success" ? "border-govuk-notification-banner-success bg-govuk-green" : "border-govuk-notification-banner bg-govuk-brand",
33
+ "focus:outline-3 focus:outline-govuk-yellow",
34
+ className
35
+ ),
36
+ ...props
37
+ }
38
+ );
39
+ };
40
+ var NotificationBannerHeader = ({
41
+ className,
42
+ ...props
43
+ }) => /* @__PURE__ */ jsx(
44
+ "div",
45
+ {
46
+ className: cn(
47
+ "py-govuk-1 px-govuk-3 sm:px-govuk-4",
48
+ "border-b border-b-transparent",
49
+ className
50
+ ),
51
+ ...props
52
+ }
53
+ );
54
+ var NotificationBannerTitle = ({
55
+ className,
56
+ children = "Important",
57
+ ...props
58
+ }) => /* @__PURE__ */ jsx(
59
+ "h2",
60
+ {
61
+ id: "govuk-notification-banner-title",
62
+ className: cn("text-govuk-body font-bold m-0 p-0 text-white", className),
63
+ ...props,
64
+ children
65
+ }
66
+ );
67
+ var NotificationBannerContent = ({
68
+ className,
69
+ ...props
70
+ }) => /* @__PURE__ */ jsx(
71
+ "div",
72
+ {
73
+ className: cn(
74
+ "p-govuk-3 sm:p-govuk-4",
75
+ "text-govuk-black bg-white",
76
+ "*:box-border *:max-w-govuk-notification-content *:last:mb-0",
77
+ className
78
+ ),
79
+ ...props
80
+ }
81
+ );
82
+ var NotificationBannerHeading = ({
83
+ className,
84
+ children,
85
+ ...props
86
+ }) => /* @__PURE__ */ jsx(
87
+ "h3",
88
+ {
89
+ className: cn(
90
+ "text-govuk-heading-m font-bold m-0 mb-govuk-3 p-0",
91
+ className
92
+ ),
93
+ ...props,
94
+ children
95
+ }
96
+ );
97
+ var NotificationBannerLink = ({
98
+ className,
99
+ children,
100
+ ...props
101
+ }) => /* @__PURE__ */ jsx(
102
+ "a",
103
+ {
104
+ className: cn(
105
+ "font-govuk underline govuk-link-underline",
106
+ "hover:govuk-link-underline-hover focus:govuk-link-focus",
107
+ "text-govuk-link visited:text-govuk-link",
108
+ "hover:text-govuk-brand-hover active:text-govuk-black",
109
+ "group-data-[variant=success]/banner:text-govuk-green",
110
+ "group-data-[variant=success]/banner:visited:text-govuk-green",
111
+ "group-data-[variant=success]/banner:hover:text-govuk-success-hover",
112
+ "group-data-[variant=success]/banner:active:text-govuk-green",
113
+ className
114
+ ),
115
+ ...props,
116
+ children
117
+ }
118
+ );
119
+
120
+ export { NotificationBanner, NotificationBannerContent, NotificationBannerHeader, NotificationBannerHeading, NotificationBannerLink, NotificationBannerTitle };
@@ -1,16 +1,14 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
1
+ import { cn } from './chunk-GKHD33N6.js';
2
2
  import { jsxs } from 'react/jsx-runtime';
3
3
 
4
4
  var ErrorMessage = ({
5
5
  className,
6
6
  children,
7
7
  visuallyHiddenText = "Error",
8
- ref,
9
8
  ...props
10
9
  }) => /* @__PURE__ */ jsxs(
11
10
  "p",
12
11
  {
13
- ref,
14
12
  className: cn(
15
13
  "block",
16
14
  "mt-0 mb-govuk-3",
@@ -1,14 +1,13 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
1
+ import { cn } from './chunk-GKHD33N6.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
 
4
- var InsetText = ({ className, ref, ...props }) => /* @__PURE__ */ jsx(
4
+ var InsetText = ({ className, ...props }) => /* @__PURE__ */ jsx(
5
5
  "div",
6
6
  {
7
- ref,
8
7
  className: cn(
9
8
  "clear-both",
10
9
  "p-govuk-3",
11
- "my-govuk-4",
10
+ "my-govuk-r6",
12
11
  "border-l-govuk-inset",
13
12
  "text-govuk-tag font-normal font-govuk text-govuk-black",
14
13
  "*:first:mt-0 *:last:mb-0",
@@ -0,0 +1,192 @@
1
+ import { cn } from './chunk-GKHD33N6.js';
2
+ import { createContext, useId, use, useSyncExternalStore } from 'react';
3
+ import { Tabs as Tabs$1 } from '@base-ui/react/tabs';
4
+ import { jsx, jsxs } from 'react/jsx-runtime';
5
+
6
+ var STACKED_QUERY = "(width < 40rem)";
7
+ var stackedQuery;
8
+ var getStackedQuery = () => {
9
+ stackedQuery ??= window.matchMedia(STACKED_QUERY);
10
+ return stackedQuery;
11
+ };
12
+ var subscribeToStacked = (onStoreChange) => {
13
+ const query = getStackedQuery();
14
+ query.addEventListener("change", onStoreChange);
15
+ return () => query.removeEventListener("change", onStoreChange);
16
+ };
17
+ var getStackedSnapshot = () => getStackedQuery().matches;
18
+ var getStackedServerSnapshot = () => false;
19
+ var useIsStacked = () => useSyncExternalStore(
20
+ subscribeToStacked,
21
+ getStackedSnapshot,
22
+ getStackedServerSnapshot
23
+ );
24
+ var TabsContext = createContext({ stacked: false, idPrefix: "" });
25
+ var usePanelId = (value) => {
26
+ const { idPrefix } = use(TabsContext);
27
+ return `${idPrefix}-${String(value)}`;
28
+ };
29
+ var domStyle = (style) => typeof style === "function" ? void 0 : style;
30
+ var rootStyles = "mt-govuk-1 mb-govuk-r6 font-govuk text-govuk-body text-govuk-black";
31
+ var Tabs = ({
32
+ className,
33
+ defaultValue,
34
+ value,
35
+ onValueChange,
36
+ orientation,
37
+ render,
38
+ style,
39
+ ...props
40
+ }) => {
41
+ const stacked = useIsStacked();
42
+ const idPrefix = useId();
43
+ if (stacked) {
44
+ return /* @__PURE__ */ jsx(TabsContext, { value: { stacked: true, idPrefix }, children: /* @__PURE__ */ jsx(
45
+ "div",
46
+ {
47
+ className: cn(rootStyles, className),
48
+ style: domStyle(style),
49
+ ...props
50
+ }
51
+ ) });
52
+ }
53
+ return /* @__PURE__ */ jsx(TabsContext, { value: { stacked: false, idPrefix }, children: /* @__PURE__ */ jsx(
54
+ Tabs$1.Root,
55
+ {
56
+ defaultValue,
57
+ value,
58
+ onValueChange,
59
+ orientation,
60
+ render,
61
+ style,
62
+ className: cn(rootStyles, className),
63
+ ...props
64
+ }
65
+ ) });
66
+ };
67
+ var TabsList = ({
68
+ className,
69
+ children,
70
+ contentsLabel = "Contents",
71
+ activateOnFocus = true,
72
+ loopFocus = false,
73
+ render,
74
+ style,
75
+ ...props
76
+ }) => {
77
+ const { stacked } = use(TabsContext);
78
+ if (stacked) {
79
+ return /* @__PURE__ */ jsxs(
80
+ "div",
81
+ {
82
+ className: cn("mb-govuk-4", className),
83
+ style: domStyle(style),
84
+ ...props,
85
+ children: [
86
+ /* @__PURE__ */ jsx("h2", { className: "mt-0 mb-govuk-2 text-govuk-body font-normal", children: contentsLabel }),
87
+ /* @__PURE__ */ jsx("ul", { className: "m-0 p-0 list-none", children })
88
+ ]
89
+ }
90
+ );
91
+ }
92
+ return /* @__PURE__ */ jsx(
93
+ Tabs$1.List,
94
+ {
95
+ activateOnFocus,
96
+ loopFocus,
97
+ render,
98
+ style,
99
+ className: cn("flex flex-wrap m-0 p-0 border-b border-govuk-mid-grey", className),
100
+ ...props,
101
+ children
102
+ }
103
+ );
104
+ };
105
+ var TabsTab = ({ className, children, value, ...props }) => {
106
+ const { stacked } = use(TabsContext);
107
+ const panelId = usePanelId(value);
108
+ if (stacked) {
109
+ return /* @__PURE__ */ jsx("li", { className: "ml-govuk-5 before:-ml-govuk-5 before:pr-govuk-1 before:content-['\u2014_']", children: /* @__PURE__ */ jsx(
110
+ "a",
111
+ {
112
+ href: `#${panelId}`,
113
+ className: cn(
114
+ "inline-block mb-govuk-2",
115
+ "text-govuk-link underline govuk-link-underline",
116
+ "visited:text-govuk-visited active:text-govuk-black",
117
+ "hover:text-govuk-brand-hover hover:govuk-link-underline-hover",
118
+ "focus:govuk-link-focus",
119
+ className
120
+ ),
121
+ children
122
+ }
123
+ ) });
124
+ }
125
+ return /* @__PURE__ */ jsx(
126
+ Tabs$1.Tab,
127
+ {
128
+ value,
129
+ className: cn(
130
+ "group relative cursor-pointer border-0 outline-none",
131
+ "mr-govuk-1 py-govuk-2 px-govuk-4",
132
+ "bg-govuk-light-grey text-center",
133
+ "govuk-tab",
134
+ className
135
+ ),
136
+ ...props,
137
+ children: /* @__PURE__ */ jsx(
138
+ "span",
139
+ {
140
+ className: cn(
141
+ "text-govuk-black underline govuk-link-underline",
142
+ "group-hover:govuk-link-underline-hover",
143
+ "group-focus-visible:govuk-link-focus group-focus-visible:no-underline",
144
+ "group-data-active:no-underline"
145
+ ),
146
+ children
147
+ }
148
+ )
149
+ }
150
+ );
151
+ };
152
+ var TabsPanel = ({
153
+ className,
154
+ value,
155
+ keepMounted,
156
+ render,
157
+ style,
158
+ ...props
159
+ }) => {
160
+ const { stacked } = use(TabsContext);
161
+ const panelId = usePanelId(value);
162
+ if (stacked) {
163
+ return /* @__PURE__ */ jsx(
164
+ "div",
165
+ {
166
+ id: panelId,
167
+ className: cn("mb-govuk-6 *:last:mb-0", className),
168
+ style: domStyle(style),
169
+ ...props
170
+ }
171
+ );
172
+ }
173
+ return /* @__PURE__ */ jsx(
174
+ Tabs$1.Panel,
175
+ {
176
+ value,
177
+ keepMounted,
178
+ render,
179
+ style,
180
+ tabIndex: -1,
181
+ className: cn(
182
+ "py-govuk-6 px-govuk-4",
183
+ "govuk-tab-panel-border",
184
+ "*:last:mb-0",
185
+ className
186
+ ),
187
+ ...props
188
+ }
189
+ );
190
+ };
191
+
192
+ export { Tabs, TabsList, TabsPanel, TabsTab };
@@ -1,39 +1,49 @@
1
- import { TextInput } from './chunk-QTSEOPVX.js';
2
- import { Button } from './chunk-5PIQJ22R.js';
3
- import { cn } from './chunk-WONVZ7WK.js';
4
- import { useId, useState } from 'react';
1
+ import { TextInput } from './chunk-VCJE5UO2.js';
2
+ import { Button } from './chunk-ASBIQC77.js';
3
+ import { cn } from './chunk-GKHD33N6.js';
4
+ import { useId, useState, useRef, useEffect } from 'react';
5
+ import { flushSync } from 'react-dom';
5
6
  import { jsxs, jsx } from 'react/jsx-runtime';
6
7
 
7
8
  var PasswordInput = ({
8
9
  className,
9
10
  id,
10
- error = false,
11
- disabled = false,
12
- autoComplete = "current-password",
11
+ disabled,
13
12
  showPasswordText = "Show",
14
13
  hidePasswordText = "Hide",
15
14
  showPasswordAriaLabel = "Show password",
16
15
  hidePasswordAriaLabel = "Hide password",
17
- passwordShownAnnouncement = "Your password is shown",
16
+ passwordShownAnnouncement = "Your password is visible",
18
17
  passwordHiddenAnnouncement = "Your password is hidden",
19
- ref,
20
18
  ...props
21
19
  }) => {
22
20
  const generatedId = useId();
23
21
  const inputId = id ?? generatedId;
24
- const [shown, setShown] = useState(false);
22
+ const [shown, setShown] = useState();
23
+ const toggleRef = useRef(null);
24
+ useEffect(() => {
25
+ const form = toggleRef.current?.closest("form");
26
+ const hide = () => flushSync(() => setShown((prev) => prev && false));
27
+ const handlePageShow = (event) => {
28
+ if (event.persisted) hide();
29
+ };
30
+ form?.addEventListener("submit", hide);
31
+ globalThis.addEventListener("pageshow", handlePageShow);
32
+ return () => {
33
+ form?.removeEventListener("submit", hide);
34
+ globalThis.removeEventListener("pageshow", handlePageShow);
35
+ };
36
+ }, []);
25
37
  return /* @__PURE__ */ jsxs("div", { className: "flex items-start", children: [
26
38
  /* @__PURE__ */ jsx(
27
39
  TextInput,
28
40
  {
29
- ref,
30
41
  id: inputId,
31
42
  type: shown ? "text" : "password",
32
- error,
33
43
  disabled,
34
44
  spellCheck: false,
35
45
  autoCapitalize: "none",
36
- autoComplete,
46
+ autoComplete: "current-password",
37
47
  className: cn("flex-auto", className),
38
48
  ...props
39
49
  }
@@ -41,6 +51,7 @@ var PasswordInput = ({
41
51
  /* @__PURE__ */ jsx(
42
52
  Button,
43
53
  {
54
+ ref: toggleRef,
44
55
  type: "button",
45
56
  variant: "secondary",
46
57
  disabled,
@@ -50,12 +61,12 @@ var PasswordInput = ({
50
61
  className: cn(
51
62
  "mt-0 mb-0 ml-govuk-1",
52
63
  "w-24 sm:w-24 shrink-0 grow-0",
53
- "leading-none whitespace-nowrap"
64
+ "whitespace-nowrap"
54
65
  ),
55
66
  children: shown ? hidePasswordText : showPasswordText
56
67
  }
57
68
  ),
58
- /* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", children: shown ? passwordShownAnnouncement : passwordHiddenAnnouncement })
69
+ /* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", children: shown !== void 0 && (shown ? passwordShownAnnouncement : passwordHiddenAnnouncement) })
59
70
  ] });
60
71
  };
61
72
 
@@ -1,4 +1,4 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
1
+ import { cn } from './chunk-GKHD33N6.js';
2
2
  import { cva } from 'class-variance-authority';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
@@ -10,15 +10,11 @@ var labelVariants = cva(["block", "font-govuk text-govuk-black"], {
10
10
  m: "text-govuk-heading-m font-bold mb-govuk-3",
11
11
  s: "text-govuk-body font-bold mb-govuk-1"
12
12
  }
13
- },
14
- defaultVariants: {
15
- size: void 0
16
13
  }
17
14
  });
18
- var Label = ({ className, size, htmlFor, ref, ...props }) => /* @__PURE__ */ jsx(
15
+ var Label = ({ className, size, htmlFor, ...props }) => /* @__PURE__ */ jsx(
19
16
  "label",
20
17
  {
21
- ref,
22
18
  htmlFor,
23
19
  className: cn(
24
20
  labelVariants({ size }),
@@ -31,8 +27,8 @@ var Label = ({ className, size, htmlFor, ref, ...props }) => /* @__PURE__ */ jsx
31
27
  var LabelWrapper = ({
32
28
  as: Tag = "h1",
33
29
  className,
34
- ref,
30
+ children,
35
31
  ...props
36
- }) => /* @__PURE__ */ jsx(Tag, { ref, className: cn("m-0", className), ...props });
32
+ }) => /* @__PURE__ */ jsx(Tag, { className: cn("m-0", className), ...props, children });
37
33
 
38
34
  export { Label, LabelWrapper, labelVariants };
@@ -0,0 +1,177 @@
1
+ import { buttonVariants } from './chunk-ASBIQC77.js';
2
+ import { cn } from './chunk-GKHD33N6.js';
3
+ import { useState, useRef, useEffectEvent, useEffect } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+
7
+ var REQUIRED_PRESSES = 3;
8
+ var TIMEOUT_MS = 5e3;
9
+ var HIDE_CONTENT_CLASS = "govuk-exit-this-page-hide-content";
10
+ var ExitThisPage = ({
11
+ className,
12
+ redirectUrl = "https://www.bbc.co.uk/weather",
13
+ text = "Exit this page",
14
+ activatedText = "Loading.",
15
+ timedOutText = "Exit this page expired.",
16
+ pressTwoMoreTimesText = "Shift, press 2 more times to exit.",
17
+ pressOneMoreTimeText = "Shift, press 1 more time to exit.",
18
+ ...props
19
+ }) => {
20
+ const [keypressCount, setKeypressCount] = useState(0);
21
+ const [announcement, setAnnouncement] = useState("");
22
+ const [activated, setActivated] = useState(false);
23
+ const countRef = useRef(0);
24
+ const lastKeyModifiedRef = useRef(false);
25
+ const keypressTimeoutRef = useRef(void 0);
26
+ const messageTimeoutRef = useRef(void 0);
27
+ const exitPage = () => {
28
+ setAnnouncement("");
29
+ setActivated(true);
30
+ document.body.classList.add(HIDE_CONTENT_CLASS);
31
+ globalThis.location.assign(redirectUrl);
32
+ };
33
+ const clearKeypressTimer = () => {
34
+ globalThis.clearTimeout(keypressTimeoutRef.current);
35
+ keypressTimeoutRef.current = void 0;
36
+ };
37
+ const resetKeypressTimer = () => {
38
+ clearKeypressTimer();
39
+ countRef.current = 0;
40
+ setKeypressCount(0);
41
+ setAnnouncement(timedOutText);
42
+ globalThis.clearTimeout(messageTimeoutRef.current);
43
+ messageTimeoutRef.current = globalThis.setTimeout(() => {
44
+ setAnnouncement("");
45
+ }, TIMEOUT_MS);
46
+ };
47
+ const onKeyup = useEffectEvent((event) => {
48
+ if (event.key === "Shift" && !lastKeyModifiedRef.current) {
49
+ countRef.current += 1;
50
+ setKeypressCount(countRef.current);
51
+ globalThis.clearTimeout(messageTimeoutRef.current);
52
+ if (countRef.current >= REQUIRED_PRESSES) {
53
+ countRef.current = 0;
54
+ clearKeypressTimer();
55
+ exitPage();
56
+ } else {
57
+ setAnnouncement(
58
+ countRef.current === 1 ? pressTwoMoreTimesText : pressOneMoreTimeText
59
+ );
60
+ clearKeypressTimer();
61
+ keypressTimeoutRef.current = globalThis.setTimeout(
62
+ resetKeypressTimer,
63
+ TIMEOUT_MS
64
+ );
65
+ }
66
+ } else if (keypressTimeoutRef.current !== void 0) {
67
+ resetKeypressTimer();
68
+ }
69
+ lastKeyModifiedRef.current = event.shiftKey;
70
+ });
71
+ useEffect(() => {
72
+ const keypressTimeout = keypressTimeoutRef;
73
+ const messageTimeout = messageTimeoutRef;
74
+ const handleKeyup = (event) => onKeyup(event);
75
+ const handlePageShow = (event) => {
76
+ if (!event.persisted) return;
77
+ document.body.classList.remove(HIDE_CONTENT_CLASS);
78
+ globalThis.clearTimeout(keypressTimeout.current);
79
+ globalThis.clearTimeout(messageTimeout.current);
80
+ keypressTimeout.current = void 0;
81
+ countRef.current = 0;
82
+ setKeypressCount(0);
83
+ setAnnouncement("");
84
+ setActivated(false);
85
+ };
86
+ document.addEventListener("keyup", handleKeyup, true);
87
+ globalThis.addEventListener("pageshow", handlePageShow);
88
+ return () => {
89
+ document.removeEventListener("keyup", handleKeyup, true);
90
+ globalThis.removeEventListener("pageshow", handlePageShow);
91
+ globalThis.clearTimeout(keypressTimeout.current);
92
+ globalThis.clearTimeout(messageTimeout.current);
93
+ };
94
+ }, []);
95
+ return /* @__PURE__ */ jsxs(
96
+ "div",
97
+ {
98
+ "data-exit-this-page": true,
99
+ className: cn(
100
+ "block sm:inline-block",
101
+ "sticky top-0 left-0 z-govuk-exit-page w-full",
102
+ "mb-govuk-6 sm:mb-govuk-8",
103
+ "sm:right-0 sm:left-auto sm:w-auto sm:float-right",
104
+ "print:hidden",
105
+ className
106
+ ),
107
+ ...props,
108
+ children: [
109
+ /* @__PURE__ */ jsxs(
110
+ "a",
111
+ {
112
+ href: redirectUrl,
113
+ role: "button",
114
+ draggable: false,
115
+ rel: "nofollow noreferrer",
116
+ onClick: (event) => {
117
+ event.preventDefault();
118
+ exitPage();
119
+ },
120
+ onKeyDown: (event) => {
121
+ if (event.key !== " ") return;
122
+ event.preventDefault();
123
+ event.currentTarget.click();
124
+ },
125
+ className: cn(
126
+ buttonVariants({ variant: "warning" }),
127
+ "mb-0 max-sm:w-full"
128
+ ),
129
+ children: [
130
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Emergency" }),
131
+ " ",
132
+ text,
133
+ /* @__PURE__ */ jsx(
134
+ "span",
135
+ {
136
+ "aria-hidden": "true",
137
+ className: cn(
138
+ "p-govuk-2 pb-0 leading-0 pointer-events-none text-center",
139
+ keypressCount > 0 ? "block" : "hidden"
140
+ ),
141
+ children: [0, 1, 2].map((index) => /* @__PURE__ */ jsx(
142
+ "span",
143
+ {
144
+ className: cn(
145
+ "inline-block box-border rounded-full",
146
+ "w-govuk-exit-page-dot h-govuk-exit-page-dot",
147
+ "mx-govuk-exit-page-dot-gap",
148
+ "border-2 border-solid border-current",
149
+ index < keypressCount && "border-govuk-exit-page-dot"
150
+ )
151
+ },
152
+ index
153
+ ))
154
+ }
155
+ )
156
+ ]
157
+ }
158
+ ),
159
+ /* @__PURE__ */ jsx("output", { className: "sr-only", children: announcement }),
160
+ activated && createPortal(
161
+ /* @__PURE__ */ jsx(
162
+ "div",
163
+ {
164
+ role: "alert",
165
+ "data-exit-overlay": true,
166
+ className: "fixed inset-0 z-govuk-exit-page-overlay bg-govuk-canvas text-govuk-canvas-text",
167
+ children: activatedText
168
+ }
169
+ ),
170
+ document.body
171
+ )
172
+ ]
173
+ }
174
+ );
175
+ };
176
+
177
+ export { ExitThisPage };