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
@@ -1,180 +0,0 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
2
- import { useRef, useState, useId } from 'react';
3
- import { cva } from 'class-variance-authority';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
5
-
6
- var fileUploadButtonVariants = cva(
7
- [
8
- "group block w-full text-left cursor-pointer appearance-none",
9
- "font-govuk text-govuk-body text-govuk-black",
10
- "p-govuk-file-upload sm:p-govuk-file-upload-lg",
11
- "border-2 bg-white",
12
- "focus:outline-3 focus:outline-govuk-yellow focus:outline-offset-0",
13
- "focus:border-govuk-black focus:bg-govuk-light-grey",
14
- "focus:inset-ring-2 focus:inset-ring-govuk-black",
15
- "disabled:opacity-50 disabled:pointer-events-none"
16
- ],
17
- {
18
- variants: {
19
- empty: {
20
- true: [
21
- "border-dashed border-govuk-grey",
22
- "hover:border-govuk-file-upload-hover-border hover:bg-govuk-light-grey"
23
- ],
24
- false: [
25
- "border-solid border-govuk-mid-grey",
26
- "hover:border-dashed hover:border-govuk-file-upload-hover-border"
27
- ]
28
- },
29
- dragging: {
30
- true: "border-solid border-govuk-black bg-govuk-light-grey",
31
- false: ""
32
- },
33
- error: {
34
- true: "border-govuk-error",
35
- false: ""
36
- }
37
- },
38
- defaultVariants: {
39
- empty: true,
40
- dragging: false,
41
- error: false
42
- }
43
- }
44
- );
45
- var statusStyles = [
46
- "block mb-govuk-2 px-govuk-2 py-govuk-3",
47
- "text-left wrap-break-word font-govuk text-govuk-body"
48
- ];
49
- var pseudoButtonStyles = [
50
- "inline-block leading-none",
51
- "px-govuk-button-x pt-govuk-button-pt pb-govuk-button-pb",
52
- "mr-govuk-2 mb-govuk-file-upload-pseudo-mb",
53
- "border-2 border-transparent",
54
- "font-govuk text-govuk-body",
55
- "bg-govuk-light-grey text-govuk-black shadow-govuk-light-grey",
56
- "group-hover:bg-govuk-mid-grey",
57
- "group-focus:bg-govuk-yellow group-focus:shadow-govuk-yellow"
58
- ];
59
- var instructionStyles = [
60
- "inline-block mt-govuk-file-upload-instruction-mt mb-0",
61
- "text-left font-govuk text-govuk-body text-govuk-black"
62
- ];
63
- var FileUpload = ({
64
- className,
65
- id,
66
- name,
67
- disabled = false,
68
- error = false,
69
- multiple,
70
- chooseFileButtonText = "Choose file",
71
- dropInstructionText = "or drop file",
72
- noFileChosenText = "No file chosen",
73
- onChange,
74
- ref,
75
- ...props
76
- }) => {
77
- const internalRef = useRef(null);
78
- const [status, setStatus] = useState(noFileChosenText);
79
- const [empty, setEmpty] = useState(true);
80
- const [dragging, setDragging] = useState(false);
81
- const generatedId = useId();
82
- const buttonId = id ?? generatedId;
83
- const inputId = `${buttonId}-input`;
84
- const setRefs = (node) => {
85
- internalRef.current = node;
86
- if (typeof ref === "function") {
87
- ref(node);
88
- } else if (ref) {
89
- ref.current = node;
90
- }
91
- };
92
- const updateFromFiles = (files) => {
93
- if (!files || files.length === 0) {
94
- setStatus(noFileChosenText);
95
- setEmpty(true);
96
- } else if (files.length === 1) {
97
- setStatus(files[0].name);
98
- setEmpty(false);
99
- } else {
100
- setStatus(`${files.length} files chosen`);
101
- setEmpty(false);
102
- }
103
- };
104
- const handleChange = (event) => {
105
- updateFromFiles(event.target.files);
106
- onChange?.(event);
107
- };
108
- const handleDrop = (event) => {
109
- event.preventDefault();
110
- setDragging(false);
111
- if (disabled) {
112
- return;
113
- }
114
- const droppedFiles = event.dataTransfer.files;
115
- if (droppedFiles.length > 0 && internalRef.current) {
116
- internalRef.current.files = droppedFiles;
117
- updateFromFiles(droppedFiles);
118
- internalRef.current.dispatchEvent(new Event("change", { bubbles: true }));
119
- }
120
- };
121
- return /* @__PURE__ */ jsxs(
122
- "div",
123
- {
124
- className: cn(
125
- "relative block",
126
- disabled && "cursor-not-allowed",
127
- className
128
- ),
129
- children: [
130
- /* @__PURE__ */ jsxs(
131
- "button",
132
- {
133
- type: "button",
134
- id: buttonId,
135
- disabled,
136
- onClick: () => internalRef.current?.click(),
137
- onDragOver: (event) => event.preventDefault(),
138
- onDragEnter: () => !disabled && setDragging(true),
139
- onDragLeave: () => setDragging(false),
140
- onDrop: handleDrop,
141
- className: fileUploadButtonVariants({ empty, dragging, error }),
142
- children: [
143
- /* @__PURE__ */ jsx(
144
- "span",
145
- {
146
- "aria-live": "polite",
147
- className: cn(
148
- statusStyles,
149
- empty ? "bg-govuk-tag-blue-bg text-govuk-black" : "bg-govuk-brand text-white"
150
- ),
151
- children: status
152
- }
153
- ),
154
- /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-baseline", children: [
155
- /* @__PURE__ */ jsx("span", { className: cn(pseudoButtonStyles), children: chooseFileButtonText }),
156
- /* @__PURE__ */ jsx("span", { className: cn(instructionStyles), children: dropInstructionText })
157
- ] })
158
- ]
159
- }
160
- ),
161
- /* @__PURE__ */ jsx(
162
- "input",
163
- {
164
- ref: setRefs,
165
- id: inputId,
166
- name,
167
- type: "file",
168
- multiple,
169
- disabled,
170
- hidden: true,
171
- onChange: handleChange,
172
- ...props
173
- }
174
- )
175
- ]
176
- }
177
- );
178
- };
179
-
180
- export { FileUpload, fileUploadButtonVariants };
@@ -1,119 +0,0 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
2
- import { jsx } from 'react/jsx-runtime';
3
-
4
- var NotificationBanner = ({
5
- className,
6
- variant = "default",
7
- ref,
8
- children,
9
- ...props
10
- }) => /* @__PURE__ */ jsx(
11
- "section",
12
- {
13
- ref,
14
- role: variant === "success" ? "alert" : void 0,
15
- "aria-labelledby": props["aria-labelledby"] ?? "govuk-notification-banner-title",
16
- className: cn(
17
- "font-govuk text-govuk-body",
18
- "mb-govuk-8",
19
- variant === "success" ? "border-govuk-notification-banner-success bg-govuk-green" : "border-govuk-notification-banner bg-govuk-brand",
20
- "focus:outline-3 focus:outline-govuk-yellow",
21
- className
22
- ),
23
- ...props,
24
- children
25
- }
26
- );
27
- var NotificationBannerHeader = ({
28
- className,
29
- ref,
30
- children,
31
- ...props
32
- }) => /* @__PURE__ */ jsx(
33
- "div",
34
- {
35
- ref,
36
- className: cn(
37
- "py-govuk-1 px-govuk-3 sm:px-govuk-4",
38
- "border-b border-b-transparent",
39
- className
40
- ),
41
- ...props,
42
- children
43
- }
44
- );
45
- var NotificationBannerTitle = ({
46
- className,
47
- ref,
48
- children = "Important",
49
- id = "govuk-notification-banner-title",
50
- ...props
51
- }) => /* @__PURE__ */ jsx(
52
- "h2",
53
- {
54
- ref,
55
- id,
56
- className: cn("text-govuk-body font-bold m-0 p-0 text-white", className),
57
- ...props,
58
- children
59
- }
60
- );
61
- var NotificationBannerContent = ({
62
- className,
63
- ref,
64
- children,
65
- ...props
66
- }) => /* @__PURE__ */ jsx(
67
- "div",
68
- {
69
- ref,
70
- className: cn(
71
- "p-govuk-3 sm:p-govuk-4",
72
- "text-govuk-black bg-white",
73
- "*:last:mb-0",
74
- className
75
- ),
76
- ...props,
77
- children
78
- }
79
- );
80
- var NotificationBannerHeading = ({
81
- className,
82
- ref,
83
- children,
84
- ...props
85
- }) => /* @__PURE__ */ jsx(
86
- "h3",
87
- {
88
- ref,
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
- ref,
100
- children,
101
- ...props
102
- }) => /* @__PURE__ */ jsx(
103
- "a",
104
- {
105
- ref,
106
- className: cn(
107
- "font-govuk text-govuk-brand font-bold",
108
- "underline govuk-link-underline",
109
- "hover:govuk-link-underline-hover",
110
- "focus:govuk-link-focus",
111
- "visited:text-govuk-brand",
112
- className
113
- ),
114
- ...props,
115
- children
116
- }
117
- );
118
-
119
- export { NotificationBanner, NotificationBannerContent, NotificationBannerHeader, NotificationBannerHeading, NotificationBannerLink, NotificationBannerTitle };
@@ -1,105 +0,0 @@
1
- import { Textarea } from './chunk-AO6HPG4R.js';
2
- import { cn } from './chunk-WONVZ7WK.js';
3
- import { useState, useCallback } from 'react';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
5
-
6
- var countWords = (text) => {
7
- const trimmed = text.trim();
8
- if (trimmed === "") return 0;
9
- return trimmed.split(/\s+/).length;
10
- };
11
- var defaultFormatMessage = (remaining, mode) => {
12
- const unit = mode === "words" ? "words" : "characters";
13
- if (remaining >= 0) {
14
- return `You have ${remaining} ${unit} remaining`;
15
- }
16
- const over = Math.abs(remaining);
17
- return `You have ${over} ${unit} too many`;
18
- };
19
- var getCount = (text, mode) => {
20
- if (mode === "words") return countWords(text);
21
- return text.length;
22
- };
23
- var CharacterCount = ({
24
- id,
25
- maxCount,
26
- mode = "characters",
27
- threshold = 0,
28
- rows = 5,
29
- defaultValue = "",
30
- value,
31
- error = false,
32
- disabled = false,
33
- className,
34
- textareaClassName,
35
- onChange,
36
- name,
37
- ref,
38
- formatMessage = defaultFormatMessage
39
- }) => {
40
- const [internalValue, setInternalValue] = useState(defaultValue);
41
- const currentValue = value ?? internalValue;
42
- const currentCount = getCount(currentValue, mode);
43
- const remaining = maxCount - currentCount;
44
- const isOverLimit = remaining < 0;
45
- const thresholdValue = Math.ceil(maxCount * threshold / 100);
46
- const showMessage = threshold === 0 || currentCount >= thresholdValue;
47
- const message = formatMessage(remaining, mode);
48
- const handleChange = useCallback(
49
- (e) => {
50
- if (value === void 0) {
51
- setInternalValue(e.target.value);
52
- }
53
- onChange?.(e);
54
- },
55
- [value, onChange]
56
- );
57
- return /* @__PURE__ */ jsxs("div", { className: cn("font-govuk mb-govuk-6", className), children: [
58
- /* @__PURE__ */ jsx(
59
- Textarea,
60
- {
61
- ref,
62
- id,
63
- name,
64
- rows,
65
- value: currentValue,
66
- onChange: handleChange,
67
- error: error || isOverLimit,
68
- disabled,
69
- "aria-describedby": `${id}-info`,
70
- className: cn("mb-govuk-1", textareaClassName)
71
- }
72
- ),
73
- /* @__PURE__ */ jsx(
74
- CharacterCountMessage,
75
- {
76
- id: `${id}-info`,
77
- className: cn(
78
- isOverLimit && "text-govuk-error font-bold",
79
- !showMessage && "invisible"
80
- ),
81
- children: message
82
- }
83
- )
84
- ] });
85
- };
86
- var CharacterCountMessage = ({
87
- className,
88
- children,
89
- ref,
90
- ...props
91
- }) => /* @__PURE__ */ jsx(
92
- "div",
93
- {
94
- ref,
95
- className: cn(
96
- "font-govuk text-govuk-body text-govuk-dark-grey",
97
- "mt-0 mb-0 tabular-nums",
98
- className
99
- ),
100
- ...props,
101
- children
102
- }
103
- );
104
-
105
- export { CharacterCount, CharacterCountMessage };
@@ -1,88 +0,0 @@
1
- import { cn } from './chunk-WONVZ7WK.js';
2
- import { cva } from 'class-variance-authority';
3
- import { jsx } from 'react/jsx-runtime';
4
-
5
- var tableCaptionVariants = cva("font-bold table-caption text-left", {
6
- variants: {
7
- size: {
8
- m: "text-govuk-heading-m mb-govuk-3",
9
- l: "text-govuk-heading-l mb-govuk-3",
10
- xl: "text-govuk-heading-xl mb-govuk-3"
11
- }
12
- }
13
- });
14
- var Table = ({ className, ref, children, ...props }) => /* @__PURE__ */ jsx(
15
- "table",
16
- {
17
- ref,
18
- className: cn(
19
- "w-full mb-govuk-6 border-spacing-0 border-collapse",
20
- "font-govuk text-govuk-body text-govuk-black",
21
- className
22
- ),
23
- ...props,
24
- children
25
- }
26
- );
27
- var TableCaption = ({
28
- className,
29
- ref,
30
- children,
31
- size,
32
- ...props
33
- }) => /* @__PURE__ */ jsx(
34
- "caption",
35
- {
36
- ref,
37
- className: cn(
38
- "font-govuk font-bold table-caption text-left",
39
- tableCaptionVariants({ size }),
40
- className
41
- ),
42
- ...props,
43
- children
44
- }
45
- );
46
- var TableHead = ({ className, ref, children, ...props }) => /* @__PURE__ */ jsx("thead", { ref, className: cn(className), ...props, children });
47
- var TableBody = ({ className, ref, children, ...props }) => /* @__PURE__ */ jsx("tbody", { ref, className: cn(className), ...props, children });
48
- var TableRow = ({ className, ref, children, ...props }) => /* @__PURE__ */ jsx("tr", { ref, className: cn(className), ...props, children });
49
- var TableHeader = ({
50
- className,
51
- ref,
52
- children,
53
- numeric,
54
- ...props
55
- }) => /* @__PURE__ */ jsx(
56
- "th",
57
- {
58
- ref,
59
- className: cn(
60
- "govuk-table-cell font-bold",
61
- numeric && "text-right tabular-nums",
62
- className
63
- ),
64
- ...props,
65
- children
66
- }
67
- );
68
- var TableCell = ({
69
- className,
70
- ref,
71
- children,
72
- numeric,
73
- ...props
74
- }) => /* @__PURE__ */ jsx(
75
- "td",
76
- {
77
- ref,
78
- className: cn(
79
- "govuk-table-cell",
80
- numeric && "text-right tabular-nums",
81
- className
82
- ),
83
- ...props,
84
- children
85
- }
86
- );
87
-
88
- export { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, tableCaptionVariants };
@@ -1,169 +0,0 @@
1
- import { buttonVariants } from './chunk-5PIQJ22R.js';
2
- import { cn } from './chunk-WONVZ7WK.js';
3
- import { useState, useRef, useEffect } from 'react';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
5
-
6
- var REQUIRED_PRESSES = 3;
7
- var TIMEOUT_MS = 5e3;
8
- var indicatorStyles = [
9
- "p-govuk-2 pb-0 pointer-events-none text-center"
10
- ];
11
- var dotStyles = [
12
- "inline-block box-border rounded-full",
13
- "w-govuk-exit-page-dot h-govuk-exit-page-dot",
14
- "mx-govuk-exit-page-dot-gap",
15
- "border-2 border-solid border-current"
16
- ];
17
- var ExitThisPage = ({
18
- className,
19
- redirectUrl = "https://www.bbc.co.uk/weather",
20
- text = "Exit this page",
21
- activatedText = "Loading.",
22
- timedOutText = "Exit this page expired.",
23
- pressTwoMoreTimesText = "Shift, press 2 more times to exit.",
24
- pressOneMoreTimeText = "Shift, press 1 more time to exit.",
25
- ref,
26
- ...props
27
- }) => {
28
- const [keypressCount, setKeypressCount] = useState(0);
29
- const [announcement, setAnnouncement] = useState("");
30
- const [activated, setActivated] = useState(false);
31
- const countRef = useRef(0);
32
- const lastKeyModifiedRef = useRef(false);
33
- const keypressTimeoutRef = useRef(null);
34
- const messageTimeoutRef = useRef(null);
35
- const exitPage = () => {
36
- setAnnouncement("");
37
- setActivated(true);
38
- globalThis.location.assign(redirectUrl);
39
- };
40
- const handleClick = (event) => {
41
- event.preventDefault();
42
- exitPage();
43
- };
44
- useEffect(() => {
45
- const clearKeypressTimer = () => {
46
- if (keypressTimeoutRef.current !== null) {
47
- globalThis.clearTimeout(keypressTimeoutRef.current);
48
- keypressTimeoutRef.current = null;
49
- }
50
- };
51
- const resetKeypressTimer = () => {
52
- clearKeypressTimer();
53
- countRef.current = 0;
54
- setKeypressCount(0);
55
- setAnnouncement(timedOutText);
56
- if (messageTimeoutRef.current !== null) {
57
- globalThis.clearTimeout(messageTimeoutRef.current);
58
- }
59
- messageTimeoutRef.current = globalThis.setTimeout(() => {
60
- setAnnouncement("");
61
- }, TIMEOUT_MS);
62
- };
63
- const setKeypressTimer = () => {
64
- clearKeypressTimer();
65
- keypressTimeoutRef.current = globalThis.setTimeout(
66
- resetKeypressTimer,
67
- TIMEOUT_MS
68
- );
69
- };
70
- const handleKeyup = (event) => {
71
- if (event.key === "Shift" && !lastKeyModifiedRef.current) {
72
- countRef.current += 1;
73
- setKeypressCount(countRef.current);
74
- if (messageTimeoutRef.current !== null) {
75
- globalThis.clearTimeout(messageTimeoutRef.current);
76
- messageTimeoutRef.current = null;
77
- }
78
- if (countRef.current >= REQUIRED_PRESSES) {
79
- countRef.current = 0;
80
- clearKeypressTimer();
81
- exitPage();
82
- } else {
83
- setAnnouncement(
84
- countRef.current === 1 ? pressTwoMoreTimesText : pressOneMoreTimeText
85
- );
86
- setKeypressTimer();
87
- }
88
- } else if (keypressTimeoutRef.current !== null) {
89
- resetKeypressTimer();
90
- }
91
- lastKeyModifiedRef.current = event.shiftKey;
92
- };
93
- document.addEventListener("keyup", handleKeyup, true);
94
- return () => {
95
- document.removeEventListener("keyup", handleKeyup, true);
96
- clearKeypressTimer();
97
- if (messageTimeoutRef.current !== null) {
98
- globalThis.clearTimeout(messageTimeoutRef.current);
99
- }
100
- };
101
- }, [
102
- redirectUrl,
103
- timedOutText,
104
- pressTwoMoreTimesText,
105
- pressOneMoreTimeText
106
- ]);
107
- return /* @__PURE__ */ jsxs(
108
- "div",
109
- {
110
- ref,
111
- className: cn(
112
- "block sm:inline-block",
113
- "sticky top-0 left-0 z-govuk-exit-page w-full",
114
- "mb-govuk-8",
115
- "sm:right-0 sm:left-auto sm:w-auto sm:float-right",
116
- "print:hidden",
117
- className
118
- ),
119
- ...props,
120
- children: [
121
- /* @__PURE__ */ jsxs(
122
- "a",
123
- {
124
- href: redirectUrl,
125
- rel: "nofollow noreferrer",
126
- onClick: handleClick,
127
- className: cn(
128
- buttonVariants({ variant: "warning" }),
129
- "mb-0 max-sm:w-full"
130
- ),
131
- children: [
132
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Emergency" }),
133
- " ",
134
- text,
135
- /* @__PURE__ */ jsx(
136
- "span",
137
- {
138
- "aria-hidden": "true",
139
- className: cn(indicatorStyles, keypressCount > 0 ? "block" : "hidden"),
140
- children: [0, 1, 2].map((index) => /* @__PURE__ */ jsx(
141
- "span",
142
- {
143
- className: cn(
144
- dotStyles,
145
- index < keypressCount && "border-govuk-exit-page-dot"
146
- )
147
- },
148
- index
149
- ))
150
- }
151
- )
152
- ]
153
- }
154
- ),
155
- /* @__PURE__ */ jsx("output", { className: "sr-only", children: announcement }),
156
- activated && /* @__PURE__ */ jsx(
157
- "div",
158
- {
159
- role: "alert",
160
- className: "fixed inset-0 z-govuk-exit-page-overlay bg-govuk-canvas text-govuk-canvas-text",
161
- children: activatedText
162
- }
163
- )
164
- ]
165
- }
166
- );
167
- };
168
-
169
- export { ExitThisPage };