@communitiesuk/svelte-component-library 0.1.18 → 0.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -6
- package/dist/assets/css/base.css +9 -0
- package/dist/assets/css/code-block.css +116 -0
- package/dist/assets/css/components.css +47 -0
- package/dist/assets/css/fonts.css +19 -0
- package/dist/assets/css/govuk-additional.css +142 -0
- package/dist/assets/css/govuk-frontend.min.css +2 -2
- package/dist/assets/css/moduk.css +1 -0
- package/dist/assets/css/moj-frontend.min copy.css +4108 -0
- package/dist/assets/css/moj-frontend.min.css +2 -0
- package/dist/assets/css/moj-frontend.min.css.map +1 -0
- package/dist/assets/css/utilities.css +0 -0
- package/dist/assets/images/govuk-crest.svg +1 -1
- package/dist/assets/js/govuk-frontend.min.js +1 -0
- package/dist/assets/js/moj-frontend.min.js +1 -0
- package/dist/assets/rebrand/images/favicon.ico +0 -0
- package/dist/assets/rebrand/images/favicon.svg +1 -0
- package/dist/assets/rebrand/images/govuk-crest.svg +1 -0
- package/dist/assets/rebrand/images/govuk-icon-180.png +0 -0
- package/dist/assets/rebrand/images/govuk-icon-192.png +0 -0
- package/dist/assets/rebrand/images/govuk-icon-512.png +0 -0
- package/dist/assets/rebrand/images/govuk-icon-mask.svg +1 -0
- package/dist/assets/rebrand/images/govuk-opengraph-image.png +0 -0
- package/dist/assets/rebrand/manifest.json +39 -0
- package/dist/components/data-vis/line-chart/Line.svelte +48 -40
- package/dist/components/data-vis/line-chart/Line.svelte.d.ts +6 -4
- package/dist/components/data-vis/line-chart/LineChart.svelte +145 -36
- package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +25 -9
- package/dist/components/data-vis/line-chart/Lines.svelte +10 -23
- package/dist/components/data-vis/line-chart/Lines.svelte.d.ts +8 -4
- package/dist/components/data-vis/line-chart/Marker.svelte +31 -5
- package/dist/components/data-vis/line-chart/Marker.svelte.d.ts +6 -2
- package/dist/components/data-vis/line-chart/SeriesLabel.svelte +7 -8
- package/dist/components/data-vis/line-chart/SeriesLabel.svelte.d.ts +2 -2
- package/dist/components/data-vis/line-chart/ValueLabel.svelte +26 -34
- package/dist/components/data-vis/line-chart/ValueLabel.svelte.d.ts +8 -4
- package/dist/components/data-vis/map/Map.svelte +299 -71
- package/dist/components/data-vis/map/Map.svelte.d.ts +39 -12
- package/dist/components/data-vis/map/NonStandardControls.svelte +10 -1
- package/dist/components/data-vis/map/NonStandardControls.svelte.d.ts +12 -11
- package/dist/components/data-vis/map/Tooltip.svelte +3 -4
- package/dist/components/data-vis/map/Tooltip.svelte.d.ts +0 -2
- package/dist/components/data-vis/map/mapUtils.d.ts +2 -0
- package/dist/components/data-vis/map/mapUtils.js +50 -0
- package/dist/components/data-vis/table/Table.svelte +28 -40
- package/dist/components/data-vis/table/Table.svelte.d.ts +0 -2
- package/dist/components/layout/Breadcrumbs.svelte +10 -12
- package/dist/components/layout/Breadcrumbs.svelte.d.ts +1 -0
- package/dist/components/layout/Footer.svelte +69 -4
- package/dist/components/layout/Footer.svelte.d.ts +3 -0
- package/dist/components/layout/Header.svelte +56 -16
- package/dist/components/layout/Header.svelte.d.ts +1 -0
- package/dist/components/layout/InternalHeader.svelte +155 -150
- package/dist/components/layout/InternalHeader.svelte.d.ts +1 -0
- package/dist/components/ui/Button.svelte +78 -4
- package/dist/components/ui/Button.svelte.d.ts +2 -0
- package/dist/components/ui/CookieBanner.svelte +356 -0
- package/dist/components/ui/CookieBanner.svelte.d.ts +18 -0
- package/dist/components/ui/FilterPanel.svelte +167 -158
- package/dist/components/ui/FilterPanel.svelte.d.ts +2 -0
- package/dist/components/ui/Masthead.svelte +35 -23
- package/dist/components/ui/Masthead.svelte.d.ts +2 -0
- package/dist/components/ui/PostcodeOrAreaSearch.svelte +200 -0
- package/dist/components/ui/PostcodeOrAreaSearch.svelte.d.ts +37 -0
- package/dist/components/ui/Search.svelte +2 -2
- package/dist/components/ui/SearchAutocomplete.svelte +104 -14
- package/dist/components/ui/SearchAutocomplete.svelte.d.ts +4 -0
- package/dist/data/IMD2019.json +32846 -0
- package/dist/data/places.csv +20039 -0
- package/dist/data/places.json +100192 -0
- package/dist/data/svgFontDimensions.json +90 -0
- package/dist/data/testData.json +52632 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/package-wrapping/BaseInformation.svelte +0 -33
- package/dist/package-wrapping/SidebarContainer.svelte +0 -7
- package/dist/utils/area-search/geoConfig.d.ts +435 -0
- package/dist/utils/area-search/geoConfig.js +291 -0
- package/dist/utils/cookiesNavigation.d.ts +44 -0
- package/dist/utils/cookiesNavigation.js +63 -0
- package/dist/utils/data-transformations/convert-csv-to-json-proper.cjs +88 -0
- package/dist/utils/data-transformations/convert-csv-to-json-proper.d.cts +1 -0
- package/dist/utils/data-transformations/convertCSV.d.ts +6 -0
- package/dist/utils/data-transformations/convertCSV.js +40 -21
- package/dist/utils/text-string-conversion/textStringConversion.d.ts +6 -0
- package/dist/utils/text-string-conversion/textStringConversion.js +10 -0
- package/package.json +18 -7
- package/dist/components/ui/Breadcrumbs.svelte +0 -198
- package/dist/components/ui/Breadcrumbs.svelte.d.ts +0 -24
- package/dist/components/ui/Footer.svelte +0 -171
- package/dist/components/ui/Footer.svelte.d.ts +0 -30
- package/dist/components/ui/Header.svelte +0 -43
- package/dist/components/ui/Header.svelte.d.ts +0 -7
- package/dist/components/ui/ServiceNavigation.svelte +0 -143
- package/dist/components/ui/ServiceNavigation.svelte.d.ts +0 -13
- package/dist/components/ui/SideNavigation.svelte +0 -346
- package/dist/components/ui/SideNavigation.svelte.d.ts +0 -25
|
@@ -9,6 +9,7 @@ type $$ComponentProps = {
|
|
|
9
9
|
firstSvgColor?: string;
|
|
10
10
|
backgroundColor?: string;
|
|
11
11
|
showSignOut?: boolean;
|
|
12
|
+
includeCrest?: boolean;
|
|
12
13
|
};
|
|
13
14
|
declare const InternalHeader: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
15
|
type InternalHeader = ReturnType<typeof InternalHeader>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
buttonType,
|
|
5
5
|
componentNameProp = undefined,
|
|
6
6
|
onClickFunction = undefined,
|
|
7
|
+
noPadding = false,
|
|
7
8
|
} = $props();
|
|
8
9
|
|
|
9
10
|
let buttonClass = $derived(
|
|
@@ -19,10 +20,10 @@
|
|
|
19
20
|
);
|
|
20
21
|
</script>
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
{#if noPadding}
|
|
23
24
|
{#if buttonType === "start"}
|
|
24
25
|
<a
|
|
25
|
-
href="#"
|
|
26
|
+
href={"#"}
|
|
26
27
|
role="button"
|
|
27
28
|
draggable="false"
|
|
28
29
|
class="govuk-button govuk-button--start"
|
|
@@ -63,14 +64,16 @@
|
|
|
63
64
|
aria-hidden="true"
|
|
64
65
|
role="img"
|
|
65
66
|
viewBox="0 0 22 22"
|
|
66
|
-
fill="
|
|
67
|
+
fill="currentColor"
|
|
67
68
|
xmlns="http://www.w3.org/2000/svg"
|
|
68
69
|
>
|
|
69
70
|
<path
|
|
71
|
+
class="top-triangle"
|
|
70
72
|
d="M8.1875 9.5L10.9609 3.95703L13.7344 9.5H8.1875Z"
|
|
71
73
|
fill="currentColor"
|
|
72
74
|
></path>
|
|
73
75
|
<path
|
|
76
|
+
class="bottom-triangle"
|
|
74
77
|
d="M13.7344 12.0781L10.9609 17.6211L8.1875 12.0781H13.7344Z"
|
|
75
78
|
fill="currentColor"
|
|
76
79
|
></path>
|
|
@@ -86,7 +89,78 @@
|
|
|
86
89
|
{textContent}
|
|
87
90
|
</button>
|
|
88
91
|
{/if}
|
|
89
|
-
|
|
92
|
+
{:else}
|
|
93
|
+
<div class="p-4">
|
|
94
|
+
{#if buttonType === "start"}
|
|
95
|
+
<a
|
|
96
|
+
href={"#"}
|
|
97
|
+
role="button"
|
|
98
|
+
draggable="false"
|
|
99
|
+
class="govuk-button govuk-button--start"
|
|
100
|
+
data-module="govuk-button"
|
|
101
|
+
onclick={onClickFunction}
|
|
102
|
+
>
|
|
103
|
+
{textContent}
|
|
104
|
+
<svg
|
|
105
|
+
class="govuk-button__start-icon"
|
|
106
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
107
|
+
width="17.5"
|
|
108
|
+
height="19"
|
|
109
|
+
viewBox="0 0 33 40"
|
|
110
|
+
aria-hidden="true"
|
|
111
|
+
focusable="false"
|
|
112
|
+
>
|
|
113
|
+
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
|
|
114
|
+
</svg>
|
|
115
|
+
</a>
|
|
116
|
+
{:else if buttonType === "disabled"}
|
|
117
|
+
<button
|
|
118
|
+
type="submit"
|
|
119
|
+
disabled
|
|
120
|
+
aria-disabled="true"
|
|
121
|
+
class="govuk-button"
|
|
122
|
+
data-module="govuk-button"
|
|
123
|
+
onclick={onClickFunction}
|
|
124
|
+
>
|
|
125
|
+
{textContent}
|
|
126
|
+
</button>
|
|
127
|
+
{:else if buttonType === "table header"}
|
|
128
|
+
<button type="button" class="text-header" onclick={onClickFunction}>
|
|
129
|
+
{textContent}
|
|
130
|
+
<svg
|
|
131
|
+
width="22"
|
|
132
|
+
height="22"
|
|
133
|
+
focusable="false"
|
|
134
|
+
aria-hidden="true"
|
|
135
|
+
role="img"
|
|
136
|
+
viewBox="0 0 22 22"
|
|
137
|
+
fill="none"
|
|
138
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
139
|
+
>
|
|
140
|
+
<path
|
|
141
|
+
class="top-triangle"
|
|
142
|
+
d="M8.1875 9.5L10.9609 3.95703L13.7344 9.5H8.1875Z"
|
|
143
|
+
fill="currentColor"
|
|
144
|
+
></path>
|
|
145
|
+
<path
|
|
146
|
+
class="bottom-triangle"
|
|
147
|
+
d="M13.7344 12.0781L10.9609 17.6211L8.1875 12.0781H13.7344Z"
|
|
148
|
+
fill="currentColor"
|
|
149
|
+
></path>
|
|
150
|
+
</svg>
|
|
151
|
+
</button>
|
|
152
|
+
{:else}
|
|
153
|
+
<button
|
|
154
|
+
type="button"
|
|
155
|
+
class={buttonClass}
|
|
156
|
+
data-module="govuk-button"
|
|
157
|
+
onclick={onClickFunction}
|
|
158
|
+
>
|
|
159
|
+
{textContent}
|
|
160
|
+
</button>
|
|
161
|
+
{/if}
|
|
162
|
+
</div>
|
|
163
|
+
{/if}
|
|
90
164
|
|
|
91
165
|
<style>
|
|
92
166
|
.text-header {
|
|
@@ -8,10 +8,12 @@ declare const Button: import("svelte").Component<{
|
|
|
8
8
|
buttonType: any;
|
|
9
9
|
componentNameProp?: any;
|
|
10
10
|
onClickFunction?: any;
|
|
11
|
+
noPadding?: boolean;
|
|
11
12
|
}, {}, "">;
|
|
12
13
|
type $$ComponentProps = {
|
|
13
14
|
textContent?: any;
|
|
14
15
|
buttonType: any;
|
|
15
16
|
componentNameProp?: any;
|
|
16
17
|
onClickFunction?: any;
|
|
18
|
+
noPadding?: boolean;
|
|
17
19
|
};
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { browser } from "$app/environment";
|
|
4
|
+
import { page } from "$app/state";
|
|
5
|
+
import {
|
|
6
|
+
handleCookiesNavigation as handleCookiesNav,
|
|
7
|
+
createCookiesUrl,
|
|
8
|
+
} from "./../../utils/cookiesNavigation";
|
|
9
|
+
|
|
10
|
+
interface ConsentMode {
|
|
11
|
+
ad_storage: "granted" | "denied";
|
|
12
|
+
analytics_storage: "granted" | "denied";
|
|
13
|
+
personalization_storage: "granted" | "denied";
|
|
14
|
+
functionality_storage: "granted" | "denied";
|
|
15
|
+
security_storage: "granted" | "denied";
|
|
16
|
+
accepted?: boolean;
|
|
17
|
+
rejected?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CookieBannerProps {
|
|
21
|
+
// Text content props
|
|
22
|
+
heading?: string;
|
|
23
|
+
essentialCookiesText?: string;
|
|
24
|
+
additionalCookiesText?: string;
|
|
25
|
+
acceptButtonText?: string;
|
|
26
|
+
rejectButtonText?: string;
|
|
27
|
+
viewCookiesText?: string;
|
|
28
|
+
acceptedMessage?: string;
|
|
29
|
+
rejectedMessage?: string;
|
|
30
|
+
changeSettingsText?: string;
|
|
31
|
+
hideMessageText?: string;
|
|
32
|
+
|
|
33
|
+
// Navigation props
|
|
34
|
+
cookiesPageUrl?: string;
|
|
35
|
+
|
|
36
|
+
// Accessibility props
|
|
37
|
+
ariaLabel?: string;
|
|
38
|
+
|
|
39
|
+
// Demo/isolation props
|
|
40
|
+
demoMode?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let {
|
|
44
|
+
heading = "Cookies on MHCLG Svelte Component Library",
|
|
45
|
+
essentialCookiesText = "We use some essential cookies to make this service work.",
|
|
46
|
+
additionalCookiesText = "We'd like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.",
|
|
47
|
+
acceptButtonText = "Accept additional cookies",
|
|
48
|
+
rejectButtonText = "Reject additional cookies",
|
|
49
|
+
viewCookiesText = "View cookies",
|
|
50
|
+
acceptedMessage = "You've accepted additional cookies. You can",
|
|
51
|
+
rejectedMessage = "You've rejected additional cookies. You can",
|
|
52
|
+
changeSettingsText = "change your cookie settings",
|
|
53
|
+
hideMessageText = "Hide cookie message",
|
|
54
|
+
cookiesPageUrl = "/cookies-page",
|
|
55
|
+
ariaLabel = "Cookies on MHCLG Svelte Component Library",
|
|
56
|
+
demoMode = false,
|
|
57
|
+
}: CookieBannerProps = $props();
|
|
58
|
+
|
|
59
|
+
// Banner state management
|
|
60
|
+
let bannerVisible = $state(true);
|
|
61
|
+
let currentMessage = $state<"initial" | "accepted" | "rejected">("initial");
|
|
62
|
+
let consentMode = $state<ConsentMode | null>(null);
|
|
63
|
+
|
|
64
|
+
// Initialize Google Tag Manager dataLayer
|
|
65
|
+
function initializeGTM(): void {
|
|
66
|
+
if (browser && typeof window !== "undefined") {
|
|
67
|
+
(window as any).dataLayer = (window as any).dataLayer || [];
|
|
68
|
+
(window as any).gtag = function () {
|
|
69
|
+
(window as any).dataLayer.push(arguments);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Helper function to call gtag
|
|
75
|
+
function gtag(...args: any[]): void {
|
|
76
|
+
if (browser && (window as any).gtag) {
|
|
77
|
+
(window as any).gtag(...args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Load consent preferences from localStorage
|
|
82
|
+
function loadConsent(): ConsentMode | null {
|
|
83
|
+
if (!browser || demoMode) return null;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const stored = localStorage.getItem("consentMode");
|
|
87
|
+
return stored ? JSON.parse(stored) : null;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error("Error loading consent from localStorage:", e);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Save consent preferences to localStorage
|
|
95
|
+
function saveConsent(consent: ConsentMode): void {
|
|
96
|
+
if (!browser || demoMode) return;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
localStorage.setItem("consentMode", JSON.stringify(consent));
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error("Error saving consent to localStorage:", e);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Check if banner should be hidden
|
|
106
|
+
function isBannerHidden(): boolean {
|
|
107
|
+
if (!browser || demoMode) return false;
|
|
108
|
+
return localStorage.getItem("bannerHidden") === "true";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Hide banner permanently
|
|
112
|
+
function hideBanner(): void {
|
|
113
|
+
if (!browser || demoMode) {
|
|
114
|
+
// In demo mode, just hide the banner without affecting storage
|
|
115
|
+
bannerVisible = false;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
localStorage.setItem("bannerHidden", "true");
|
|
119
|
+
bannerVisible = false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Set default denied consent
|
|
123
|
+
function setDefaultConsent(): ConsentMode {
|
|
124
|
+
const defaultConsent: ConsentMode = {
|
|
125
|
+
ad_storage: "denied",
|
|
126
|
+
analytics_storage: "denied",
|
|
127
|
+
personalization_storage: "denied",
|
|
128
|
+
functionality_storage: "denied",
|
|
129
|
+
security_storage: "denied",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
if (!demoMode) {
|
|
133
|
+
gtag("consent", "default", defaultConsent);
|
|
134
|
+
}
|
|
135
|
+
saveConsent(defaultConsent);
|
|
136
|
+
return defaultConsent;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Update consent and inform Google Analytics
|
|
140
|
+
function updateConsent(consent: ConsentMode): void {
|
|
141
|
+
if (!demoMode) {
|
|
142
|
+
gtag("consent", "update", consent);
|
|
143
|
+
}
|
|
144
|
+
saveConsent(consent);
|
|
145
|
+
consentMode = consent;
|
|
146
|
+
|
|
147
|
+
// Update current message based on consent
|
|
148
|
+
if (consent.accepted) {
|
|
149
|
+
currentMessage = "accepted";
|
|
150
|
+
} else if (consent.rejected) {
|
|
151
|
+
currentMessage = "rejected";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Accept additional cookies
|
|
156
|
+
function acceptCookies(): void {
|
|
157
|
+
const consent: ConsentMode = {
|
|
158
|
+
ad_storage: "denied",
|
|
159
|
+
analytics_storage: "granted",
|
|
160
|
+
personalization_storage: "denied",
|
|
161
|
+
functionality_storage: "denied",
|
|
162
|
+
security_storage: "denied",
|
|
163
|
+
accepted: true,
|
|
164
|
+
};
|
|
165
|
+
updateConsent(consent);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Reject additional cookies
|
|
169
|
+
function rejectCookies(): void {
|
|
170
|
+
const consent: ConsentMode = {
|
|
171
|
+
ad_storage: "denied",
|
|
172
|
+
analytics_storage: "denied",
|
|
173
|
+
personalization_storage: "denied",
|
|
174
|
+
functionality_storage: "denied",
|
|
175
|
+
security_storage: "denied",
|
|
176
|
+
rejected: true,
|
|
177
|
+
};
|
|
178
|
+
updateConsent(consent);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Create wrapper function for demo mode handling
|
|
182
|
+
function handleCookiesNavigation(event: Event): void {
|
|
183
|
+
return handleCookiesNav(event, demoMode);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Create the cookies page URL with current query parameters
|
|
187
|
+
let cookiesUrl = $derived(createCookiesUrl(cookiesPageUrl));
|
|
188
|
+
|
|
189
|
+
// Initialize component on mount
|
|
190
|
+
onMount(() => {
|
|
191
|
+
initializeGTM();
|
|
192
|
+
|
|
193
|
+
// Check if banner should be hidden
|
|
194
|
+
if (isBannerHidden()) {
|
|
195
|
+
bannerVisible = false;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Load existing consent or set defaults
|
|
200
|
+
const existingConsent = loadConsent();
|
|
201
|
+
if (existingConsent) {
|
|
202
|
+
consentMode = existingConsent;
|
|
203
|
+
gtag("consent", "update", existingConsent);
|
|
204
|
+
|
|
205
|
+
// Set initial message state based on existing consent
|
|
206
|
+
if (existingConsent.accepted) {
|
|
207
|
+
currentMessage = "accepted";
|
|
208
|
+
} else if (existingConsent.rejected) {
|
|
209
|
+
currentMessage = "rejected";
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
consentMode = setDefaultConsent();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Handle storage changes (same tab - from cookies page)
|
|
217
|
+
function handleStorageChange(): void {
|
|
218
|
+
if (demoMode) return; // Don't respond to storage changes in demo mode
|
|
219
|
+
|
|
220
|
+
const updatedConsent = loadConsent();
|
|
221
|
+
const bannerHidden = isBannerHidden();
|
|
222
|
+
|
|
223
|
+
if (bannerHidden) {
|
|
224
|
+
bannerVisible = false;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (updatedConsent) {
|
|
229
|
+
consentMode = updatedConsent;
|
|
230
|
+
gtag("consent", "update", updatedConsent);
|
|
231
|
+
|
|
232
|
+
if (updatedConsent.accepted) {
|
|
233
|
+
currentMessage = "accepted";
|
|
234
|
+
} else if (updatedConsent.rejected) {
|
|
235
|
+
currentMessage = "rejected";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Handle native storage events (cross-tab changes)
|
|
241
|
+
function handleCrossTabStorage(event: StorageEvent): void {
|
|
242
|
+
if (demoMode) return; // Don't respond to storage changes in demo mode
|
|
243
|
+
|
|
244
|
+
// Only respond to changes to our consentMode or bannerHidden keys
|
|
245
|
+
if (event.key === "consentMode" || event.key === "bannerHidden") {
|
|
246
|
+
handleStorageChange();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<!-- Listen for both native and custom storage events -->
|
|
252
|
+
<svelte:window
|
|
253
|
+
onstorage={handleCrossTabStorage}
|
|
254
|
+
onlocalStorageChange={handleStorageChange}
|
|
255
|
+
/>
|
|
256
|
+
|
|
257
|
+
{#snippet settingsLink()}
|
|
258
|
+
<a href={cookiesUrl} class="govuk-link" onclick={handleCookiesNavigation}>
|
|
259
|
+
{changeSettingsText}
|
|
260
|
+
</a>
|
|
261
|
+
{/snippet}
|
|
262
|
+
|
|
263
|
+
{#snippet hideBannerButton()}
|
|
264
|
+
<button
|
|
265
|
+
type="button"
|
|
266
|
+
class="govuk-button"
|
|
267
|
+
data-module="govuk-button"
|
|
268
|
+
onclick={hideBanner}
|
|
269
|
+
>
|
|
270
|
+
{hideMessageText}
|
|
271
|
+
</button>
|
|
272
|
+
{/snippet}
|
|
273
|
+
|
|
274
|
+
{#snippet confirmationMessage(message)}
|
|
275
|
+
<div class="govuk-cookie-banner__message govuk-width-container">
|
|
276
|
+
<div class="govuk-grid-row">
|
|
277
|
+
<div class="govuk-grid-column-two-thirds">
|
|
278
|
+
<div class="govuk-cookie-banner__content">
|
|
279
|
+
<p class="govuk-body">
|
|
280
|
+
{message}
|
|
281
|
+
{@render settingsLink()}
|
|
282
|
+
at any time.
|
|
283
|
+
</p>
|
|
284
|
+
</div>
|
|
285
|
+
</div>
|
|
286
|
+
</div>
|
|
287
|
+
<div class="govuk-button-group">
|
|
288
|
+
{@render hideBannerButton()}
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
{/snippet}
|
|
292
|
+
|
|
293
|
+
{#if bannerVisible}
|
|
294
|
+
<div
|
|
295
|
+
class="govuk-cookie-banner"
|
|
296
|
+
data-nosnippet
|
|
297
|
+
role="region"
|
|
298
|
+
aria-label={ariaLabel}
|
|
299
|
+
>
|
|
300
|
+
<!-- Initial consent request message -->
|
|
301
|
+
{#if currentMessage === "initial"}
|
|
302
|
+
<div class="govuk-cookie-banner__message govuk-width-container">
|
|
303
|
+
<div class="govuk-grid-row">
|
|
304
|
+
<div class="govuk-grid-column-two-thirds">
|
|
305
|
+
<h2 class="govuk-cookie-banner__heading govuk-heading-m">
|
|
306
|
+
{heading}
|
|
307
|
+
</h2>
|
|
308
|
+
<div class="govuk-cookie-banner__content">
|
|
309
|
+
<p class="govuk-body">{essentialCookiesText}</p>
|
|
310
|
+
<p class="govuk-body">{additionalCookiesText}</p>
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
<div class="govuk-button-group">
|
|
315
|
+
<button
|
|
316
|
+
type="button"
|
|
317
|
+
class="govuk-button"
|
|
318
|
+
data-module="govuk-button"
|
|
319
|
+
onclick={acceptCookies}
|
|
320
|
+
>
|
|
321
|
+
{acceptButtonText}
|
|
322
|
+
</button>
|
|
323
|
+
<button
|
|
324
|
+
type="button"
|
|
325
|
+
class="govuk-button"
|
|
326
|
+
data-module="govuk-button"
|
|
327
|
+
onclick={rejectCookies}
|
|
328
|
+
>
|
|
329
|
+
{rejectButtonText}
|
|
330
|
+
</button>
|
|
331
|
+
<a
|
|
332
|
+
href={cookiesUrl}
|
|
333
|
+
class="govuk-link"
|
|
334
|
+
onclick={handleCookiesNavigation}
|
|
335
|
+
>
|
|
336
|
+
{viewCookiesText}
|
|
337
|
+
</a>
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
{/if}
|
|
341
|
+
|
|
342
|
+
<!-- Accepted cookies confirmation message -->
|
|
343
|
+
{#if currentMessage === "accepted"}
|
|
344
|
+
{@render confirmationMessage(acceptedMessage)}
|
|
345
|
+
{/if}
|
|
346
|
+
|
|
347
|
+
<!-- Rejected cookies confirmation message -->
|
|
348
|
+
{#if currentMessage === "rejected"}
|
|
349
|
+
{@render confirmationMessage(rejectedMessage)}
|
|
350
|
+
{/if}
|
|
351
|
+
</div>
|
|
352
|
+
{/if}
|
|
353
|
+
|
|
354
|
+
<style>
|
|
355
|
+
|
|
356
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface CookieBannerProps {
|
|
2
|
+
heading?: string;
|
|
3
|
+
essentialCookiesText?: string;
|
|
4
|
+
additionalCookiesText?: string;
|
|
5
|
+
acceptButtonText?: string;
|
|
6
|
+
rejectButtonText?: string;
|
|
7
|
+
viewCookiesText?: string;
|
|
8
|
+
acceptedMessage?: string;
|
|
9
|
+
rejectedMessage?: string;
|
|
10
|
+
changeSettingsText?: string;
|
|
11
|
+
hideMessageText?: string;
|
|
12
|
+
cookiesPageUrl?: string;
|
|
13
|
+
ariaLabel?: string;
|
|
14
|
+
demoMode?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const CookieBanner: import("svelte").Component<CookieBannerProps, {}, "">;
|
|
17
|
+
type CookieBanner = ReturnType<typeof CookieBanner>;
|
|
18
|
+
export default CookieBanner;
|