@communitiesuk/svelte-component-library 0.1.17

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 (217) hide show
  1. package/README.md +188 -0
  2. package/dist/assets/css/govuk-frontend.min.css +2 -0
  3. package/dist/assets/css/govuk-frontend.min.css.map +1 -0
  4. package/dist/assets/fonts/bold-affa96571d-v2.woff +0 -0
  5. package/dist/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
  6. package/dist/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
  7. package/dist/assets/fonts/light-f591b13f7d-v2.woff +0 -0
  8. package/dist/assets/govuk_publishing_components/images/icon-autocomplete-search-suggestion.svg +4 -0
  9. package/dist/assets/govuk_publishing_components/images/icon-close.svg +1 -0
  10. package/dist/assets/images/favicon.ico +0 -0
  11. package/dist/assets/images/favicon.svg +1 -0
  12. package/dist/assets/images/govuk-crest-2x.png +0 -0
  13. package/dist/assets/images/govuk-crest.png +0 -0
  14. package/dist/assets/images/govuk-crest.svg +1 -0
  15. package/dist/assets/images/govuk-icon-180.png +0 -0
  16. package/dist/assets/images/govuk-icon-192.png +0 -0
  17. package/dist/assets/images/govuk-icon-512.png +0 -0
  18. package/dist/assets/images/govuk-icon-mask.svg +1 -0
  19. package/dist/assets/images/govuk-opengraph-image.png +0 -0
  20. package/dist/assets/images/homepage-illustration.svg +1 -0
  21. package/dist/assets/images/homepage.svg +44 -0
  22. package/dist/assets/images/masthead-illustration.svg +123 -0
  23. package/dist/assets/images/oflog_crest_black.png +0 -0
  24. package/dist/assets/images/oflog_crest_white.png +0 -0
  25. package/dist/assets/images/undraw_approved-wireframe_odf4.svg +1 -0
  26. package/dist/assets/images/undraw_collaborators_rgw4.svg +1 -0
  27. package/dist/assets/images/undraw_content-creator_vuqg.svg +1 -0
  28. package/dist/assets/images/undraw_online-media_opxh.svg +1 -0
  29. package/dist/assets/images/undraw_pull-request_zlsu.svg +1 -0
  30. package/dist/assets/images/undraw_reviewed-docs_g0cg.svg +1 -0
  31. package/dist/components/FilterPanel/codeBlocks.d.ts +3 -0
  32. package/dist/components/FilterPanel/codeBlocks.js +418 -0
  33. package/dist/components/content/InsetText.svelte +21 -0
  34. package/dist/components/content/InsetText.svelte.d.ts +7 -0
  35. package/dist/components/content/WarningText.svelte +27 -0
  36. package/dist/components/content/WarningText.svelte.d.ts +8 -0
  37. package/dist/components/data-vis/axis/Axis.svelte +51 -0
  38. package/dist/components/data-vis/axis/Axis.svelte.d.ts +33 -0
  39. package/dist/components/data-vis/axis/Ticks.svelte +113 -0
  40. package/dist/components/data-vis/axis/Ticks.svelte.d.ts +33 -0
  41. package/dist/components/data-vis/line-chart/Line.svelte +150 -0
  42. package/dist/components/data-vis/line-chart/Line.svelte.d.ts +85 -0
  43. package/dist/components/data-vis/line-chart/LineChart.svelte +249 -0
  44. package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +73 -0
  45. package/dist/components/data-vis/line-chart/Lines.svelte +138 -0
  46. package/dist/components/data-vis/line-chart/Lines.svelte.d.ts +57 -0
  47. package/dist/components/data-vis/line-chart/Marker.svelte +61 -0
  48. package/dist/components/data-vis/line-chart/Marker.svelte.d.ts +37 -0
  49. package/dist/components/data-vis/line-chart/SeriesLabel.svelte +67 -0
  50. package/dist/components/data-vis/line-chart/SeriesLabel.svelte.d.ts +43 -0
  51. package/dist/components/data-vis/line-chart/ValueLabel.svelte +50 -0
  52. package/dist/components/data-vis/line-chart/ValueLabel.svelte.d.ts +25 -0
  53. package/dist/components/data-vis/map/Map.svelte +392 -0
  54. package/dist/components/data-vis/map/Map.svelte.d.ts +47 -0
  55. package/dist/components/data-vis/map/MapLegend.svelte +41 -0
  56. package/dist/components/data-vis/map/MapLegend.svelte.d.ts +15 -0
  57. package/dist/components/data-vis/map/NonStandardControls.svelte +42 -0
  58. package/dist/components/data-vis/map/NonStandardControls.svelte.d.ts +13 -0
  59. package/dist/components/data-vis/map/Tooltip.svelte +41 -0
  60. package/dist/components/data-vis/map/Tooltip.svelte.d.ts +19 -0
  61. package/dist/components/data-vis/map/colorbrewer.d.ts +337 -0
  62. package/dist/components/data-vis/map/colorbrewer.js +1523 -0
  63. package/dist/components/data-vis/map/colors.d.ts +13 -0
  64. package/dist/components/data-vis/map/colors.js +65 -0
  65. package/dist/components/data-vis/map/dataJoin.d.ts +2 -0
  66. package/dist/components/data-vis/map/dataJoin.js +27 -0
  67. package/dist/components/data-vis/map/fullTopo.json +1 -0
  68. package/dist/components/data-vis/map/jenks.d.ts +1 -0
  69. package/dist/components/data-vis/map/jenks.js +51 -0
  70. package/dist/components/data-vis/map/lad2023.json +1 -0
  71. package/dist/components/data-vis/map/mapUtils.d.ts +5 -0
  72. package/dist/components/data-vis/map/mapUtils.js +86 -0
  73. package/dist/components/data-vis/map/topo.json +1 -0
  74. package/dist/components/data-vis/table/Table.svelte +247 -0
  75. package/dist/components/data-vis/table/Table.svelte.d.ts +19 -0
  76. package/dist/components/layout/Breadcrumbs.svelte +191 -0
  77. package/dist/components/layout/Breadcrumbs.svelte.d.ts +24 -0
  78. package/dist/components/layout/Footer.svelte +171 -0
  79. package/dist/components/layout/Footer.svelte.d.ts +30 -0
  80. package/dist/components/layout/Header.svelte +43 -0
  81. package/dist/components/layout/Header.svelte.d.ts +7 -0
  82. package/dist/components/layout/InternalHeader.svelte +628 -0
  83. package/dist/components/layout/InternalHeader.svelte.d.ts +15 -0
  84. package/dist/components/layout/PhaseBanner.svelte +28 -0
  85. package/dist/components/layout/PhaseBanner.svelte.d.ts +9 -0
  86. package/dist/components/layout/ServiceNavigation.svelte +143 -0
  87. package/dist/components/layout/ServiceNavigation.svelte.d.ts +13 -0
  88. package/dist/components/layout/SideNavigation.svelte +345 -0
  89. package/dist/components/layout/SideNavigation.svelte.d.ts +25 -0
  90. package/dist/components/layout/service-navigation-nested-mobile/HeaderNav.svelte +91 -0
  91. package/dist/components/layout/service-navigation-nested-mobile/HeaderNav.svelte.d.ts +15 -0
  92. package/dist/components/layout/service-navigation-nested-mobile/MobileNav.svelte +233 -0
  93. package/dist/components/layout/service-navigation-nested-mobile/MobileNav.svelte.d.ts +27 -0
  94. package/dist/components/layout/service-navigation-nested-mobile/ServiceNavigationNestedMobile.svelte +70 -0
  95. package/dist/components/layout/service-navigation-nested-mobile/ServiceNavigationNestedMobile.svelte.d.ts +11 -0
  96. package/dist/components/layout/service-navigation-nested-mobile/SideNav.svelte +276 -0
  97. package/dist/components/layout/service-navigation-nested-mobile/SideNav.svelte.d.ts +22 -0
  98. package/dist/components/ui/Accordion.svelte +244 -0
  99. package/dist/components/ui/Accordion.svelte.d.ts +23 -0
  100. package/dist/components/ui/Breadcrumbs.svelte +198 -0
  101. package/dist/components/ui/Breadcrumbs.svelte.d.ts +24 -0
  102. package/dist/components/ui/Button.svelte +96 -0
  103. package/dist/components/ui/Button.svelte.d.ts +17 -0
  104. package/dist/components/ui/CheckBox.svelte +198 -0
  105. package/dist/components/ui/CheckBox.svelte.d.ts +27 -0
  106. package/dist/components/ui/ContentsList.svelte +1117 -0
  107. package/dist/components/ui/ContentsList.svelte.d.ts +25 -0
  108. package/dist/components/ui/DateInput.svelte +255 -0
  109. package/dist/components/ui/DateInput.svelte.d.ts +59 -0
  110. package/dist/components/ui/Details.svelte +12 -0
  111. package/dist/components/ui/Details.svelte.d.ts +13 -0
  112. package/dist/components/ui/FilterPanel.svelte +588 -0
  113. package/dist/components/ui/FilterPanel.svelte.d.ts +74 -0
  114. package/dist/components/ui/Footer.svelte +171 -0
  115. package/dist/components/ui/Footer.svelte.d.ts +30 -0
  116. package/dist/components/ui/Header.svelte +43 -0
  117. package/dist/components/ui/Header.svelte.d.ts +7 -0
  118. package/dist/components/ui/Masthead.svelte +267 -0
  119. package/dist/components/ui/Masthead.svelte.d.ts +12 -0
  120. package/dist/components/ui/NavigationExample.svelte +117 -0
  121. package/dist/components/ui/NavigationExample.svelte.d.ts +3 -0
  122. package/dist/components/ui/NotificationBanner.svelte +93 -0
  123. package/dist/components/ui/NotificationBanner.svelte.d.ts +15 -0
  124. package/dist/components/ui/Radios.svelte +176 -0
  125. package/dist/components/ui/Radios.svelte.d.ts +28 -0
  126. package/dist/components/ui/RelatedContent.svelte +596 -0
  127. package/dist/components/ui/RelatedContent.svelte.d.ts +29 -0
  128. package/dist/components/ui/Search.svelte +499 -0
  129. package/dist/components/ui/Search.svelte.d.ts +32 -0
  130. package/dist/components/ui/SearchAutocomplete.svelte +655 -0
  131. package/dist/components/ui/SearchAutocomplete.svelte.d.ts +37 -0
  132. package/dist/components/ui/Select.svelte +116 -0
  133. package/dist/components/ui/Select.svelte.d.ts +22 -0
  134. package/dist/components/ui/ServiceNavigation.svelte +143 -0
  135. package/dist/components/ui/ServiceNavigation.svelte.d.ts +13 -0
  136. package/dist/components/ui/SideNavigation.svelte +346 -0
  137. package/dist/components/ui/SideNavigation.svelte.d.ts +25 -0
  138. package/dist/components/ui/Tabs.svelte +306 -0
  139. package/dist/components/ui/Tabs.svelte.d.ts +18 -0
  140. package/dist/components/ui/WhatsNew.svelte +155 -0
  141. package/dist/components/ui/WhatsNew.svelte.d.ts +29 -0
  142. package/dist/config.d.ts +51 -0
  143. package/dist/config.js +44 -0
  144. package/dist/icons/DoubleChevronButton.svelte +62 -0
  145. package/dist/icons/DoubleChevronButton.svelte.d.ts +13 -0
  146. package/dist/icons/IconSearch.svelte +42 -0
  147. package/dist/icons/IconSearch.svelte.d.ts +6 -0
  148. package/dist/icons/SingleChevronButtonWithLabel.svelte +132 -0
  149. package/dist/icons/SingleChevronButtonWithLabel.svelte.d.ts +19 -0
  150. package/dist/index.d.ts +44 -0
  151. package/dist/index.js +45 -0
  152. package/dist/main.css +1 -0
  153. package/dist/package-wrapping/BaseInformation.svelte +82 -0
  154. package/dist/package-wrapping/BaseInformation.svelte.d.ts +15 -0
  155. package/dist/package-wrapping/BaseNameAndStatus.svelte +108 -0
  156. package/dist/package-wrapping/BaseNameAndStatus.svelte.d.ts +10 -0
  157. package/dist/package-wrapping/CodeBlock.svelte +62 -0
  158. package/dist/package-wrapping/CodeBlock.svelte.d.ts +12 -0
  159. package/dist/package-wrapping/ComponentDemo.svelte +114 -0
  160. package/dist/package-wrapping/ComponentDemo.svelte.d.ts +25 -0
  161. package/dist/package-wrapping/ComponentDemoTEMP.svelte +305 -0
  162. package/dist/package-wrapping/ComponentDemoTEMP.svelte.d.ts +21 -0
  163. package/dist/package-wrapping/ComponentDetails.svelte +123 -0
  164. package/dist/package-wrapping/ComponentDetails.svelte.d.ts +13 -0
  165. package/dist/package-wrapping/DividerLine.svelte +21 -0
  166. package/dist/package-wrapping/DividerLine.svelte.d.ts +17 -0
  167. package/dist/package-wrapping/InputForParameter.svelte +205 -0
  168. package/dist/package-wrapping/InputForParameter.svelte.d.ts +13 -0
  169. package/dist/package-wrapping/InputForParameterUpdated.svelte +222 -0
  170. package/dist/package-wrapping/InputForParameterUpdated.svelte.d.ts +17 -0
  171. package/dist/package-wrapping/InputForParameterUpdatedTEMP.svelte +203 -0
  172. package/dist/package-wrapping/InputForParameterUpdatedTEMP.svelte.d.ts +17 -0
  173. package/dist/package-wrapping/ListOfComponentStatuses.svelte +19 -0
  174. package/dist/package-wrapping/ListOfComponentStatuses.svelte.d.ts +11 -0
  175. package/dist/package-wrapping/OverlayAndComponentContainer.svelte +426 -0
  176. package/dist/package-wrapping/OverlayAndComponentContainer.svelte.d.ts +33 -0
  177. package/dist/package-wrapping/ParametersSection.svelte +235 -0
  178. package/dist/package-wrapping/ParametersSection.svelte.d.ts +19 -0
  179. package/dist/package-wrapping/ParsingErrorToastsContainer.svelte +50 -0
  180. package/dist/package-wrapping/ParsingErrorToastsContainer.svelte.d.ts +15 -0
  181. package/dist/package-wrapping/Pill.svelte +54 -0
  182. package/dist/package-wrapping/Pill.svelte.d.ts +25 -0
  183. package/dist/package-wrapping/PlaygroundDetails.svelte +106 -0
  184. package/dist/package-wrapping/PlaygroundDetails.svelte.d.ts +13 -0
  185. package/dist/package-wrapping/ScreenSizeRadio.svelte +24 -0
  186. package/dist/package-wrapping/ScreenSizeRadio.svelte.d.ts +11 -0
  187. package/dist/package-wrapping/ScreenSizeRadioUpdated.svelte +23 -0
  188. package/dist/package-wrapping/ScreenSizeRadioUpdated.svelte.d.ts +11 -0
  189. package/dist/package-wrapping/SidebarContainer.svelte +103 -0
  190. package/dist/package-wrapping/SidebarContainer.svelte.d.ts +23 -0
  191. package/dist/package-wrapping/WrapperDetailsUpdate.svelte +40 -0
  192. package/dist/package-wrapping/WrapperDetailsUpdate.svelte.d.ts +15 -0
  193. package/dist/package-wrapping/templates/Template.svelte +100 -0
  194. package/dist/package-wrapping/templates/Template.svelte.d.ts +25 -0
  195. package/dist/templates/ComponentPageTemplate.svelte +1 -0
  196. package/dist/templates/ComponentPageTemplate.svelte.d.ts +26 -0
  197. package/dist/utils/data-transformations/convertCSV.d.ts +2 -0
  198. package/dist/utils/data-transformations/convertCSV.js +22 -0
  199. package/dist/utils/data-transformations/getValueFromParametersArray.d.ts +1 -0
  200. package/dist/utils/data-transformations/getValueFromParametersArray.js +9 -0
  201. package/dist/utils/layoutNavHelpers.d.ts +70 -0
  202. package/dist/utils/layoutNavHelpers.js +129 -0
  203. package/dist/utils/package-wrapping-specific/addIndexAndInitialValue.d.ts +1 -0
  204. package/dist/utils/package-wrapping-specific/addIndexAndInitialValue.js +21 -0
  205. package/dist/utils/package-wrapping-specific/createBindableParametersValuesArray.d.ts +1 -0
  206. package/dist/utils/package-wrapping-specific/createBindableParametersValuesArray.js +12 -0
  207. package/dist/utils/package-wrapping-specific/createParametersObject.d.ts +1 -0
  208. package/dist/utils/package-wrapping-specific/createParametersObject.js +29 -0
  209. package/dist/utils/package-wrapping-specific/defineDefaultEventHandler.d.ts +1 -0
  210. package/dist/utils/package-wrapping-specific/defineDefaultEventHandler.js +14 -0
  211. package/dist/utils/package-wrapping-specific/trackVisibleParameters.d.ts +1 -0
  212. package/dist/utils/package-wrapping-specific/trackVisibleParameters.js +29 -0
  213. package/dist/utils/syntax-highlighting/shikiHighlight.d.ts +7 -0
  214. package/dist/utils/syntax-highlighting/shikiHighlight.js +76 -0
  215. package/dist/utils/text-string-conversion/textStringConversion.d.ts +9 -0
  216. package/dist/utils/text-string-conversion/textStringConversion.js +86 -0
  217. package/package.json +113 -0
@@ -0,0 +1,116 @@
1
+ <script lang="ts">
2
+ import { clsx as cx } from "clsx";
3
+
4
+ type SelectItem = {
5
+ value: string | number;
6
+ text: string;
7
+ disabled?: boolean;
8
+ };
9
+
10
+ let {
11
+ // Core attributes
12
+ id,
13
+ name,
14
+ items,
15
+ value = $bindable<string | number | undefined>(), // Use bindable value
16
+
17
+ // Label and hints
18
+ label,
19
+ labelIsPageHeading = false,
20
+ hint = undefined,
21
+
22
+ // Error handling
23
+ error = undefined, // serverside error message
24
+ validate = undefined, // Client-side validation function
25
+
26
+ // Styling and layout
27
+ formGroupClasses = "", // Additional classes for the form group wrapper
28
+ fullWidth = false, // If true, applies full width style
29
+ describedBy = "", // Optional override for aria-describedby
30
+ ...attributes // Allow passing additional HTML attributes to the select element
31
+ }: {
32
+ id: string;
33
+ name: string;
34
+ items: SelectItem[];
35
+ value?: string | number | undefined;
36
+ label: string;
37
+ labelIsPageHeading?: boolean;
38
+ hint?: string;
39
+ error?: string; // Changed back from serverErrorMessage
40
+ validate?: (value: string | number | undefined) => string | undefined;
41
+ formGroupClasses?: string;
42
+ fullWidth?: boolean;
43
+ describedBy?: string;
44
+ } & Omit<
45
+ import("svelte/elements").HTMLSelectAttributes,
46
+ "id" | "name" | "value" | "class" | "aria-describedby"
47
+ > = $props();
48
+
49
+ // Client-side validation result
50
+ let validationError = $derived(validate ? validate(value) : undefined);
51
+ </script>
52
+
53
+ <div
54
+ class={cx(
55
+ "govuk-form-group",
56
+ (validationError || error) && "govuk-form-group--error", // Check both validation and server error
57
+ formGroupClasses,
58
+ )}
59
+ >
60
+ {#if labelIsPageHeading}
61
+ <h1 class="govuk-label-wrapper">
62
+ <label class="govuk-label govuk-label--l" for={id}>
63
+ {label}
64
+ </label>
65
+ </h1>
66
+ {:else}
67
+ <label class="govuk-label" for={id}>
68
+ {label}
69
+ </label>
70
+ {/if}
71
+
72
+ {#if hint}
73
+ <div id="{id}-hint" class="govuk-hint">
74
+ {hint}
75
+ </div>
76
+ {/if}
77
+
78
+ {#if validationError || error}
79
+ <!-- Check both validation and server error -->
80
+ <p id="{id}-error" class="govuk-error-message">
81
+ <span class="govuk-visually-hidden">Error:</span>
82
+ {validationError || error}
83
+ <!-- Display whichever error exists (client first) -->
84
+ </p>
85
+ {/if}
86
+
87
+ <select
88
+ class={cx(
89
+ "govuk-select",
90
+ (validationError || error) && "govuk-select--error", // Check both validation and server error
91
+ fullWidth && "govuk-!-width-full",
92
+ )}
93
+ {id}
94
+ {name}
95
+ bind:value
96
+ aria-describedby={// Recompute directly here based on new logic
97
+ describedBy ||
98
+ [
99
+ hint ? `${id}-hint` : null,
100
+ validationError || error ? `${id}-error` : null,
101
+ ]
102
+ .filter(Boolean)
103
+ .join(" ") ||
104
+ undefined}
105
+ {...attributes}
106
+ >
107
+ {#each items as item (item.value)}
108
+ <option value={item.value} disabled={item.disabled}>
109
+ {item.text}
110
+ </option>
111
+ {/each}
112
+ </select>
113
+ </div>
114
+
115
+ <style>
116
+ </style>
@@ -0,0 +1,22 @@
1
+ type SelectItem = {
2
+ value: string | number;
3
+ text: string;
4
+ disabled?: boolean;
5
+ };
6
+ type $$ComponentProps = {
7
+ id: string;
8
+ name: string;
9
+ items: SelectItem[];
10
+ value?: string | number | undefined;
11
+ label: string;
12
+ labelIsPageHeading?: boolean;
13
+ hint?: string;
14
+ error?: string;
15
+ validate?: (value: string | number | undefined) => string | undefined;
16
+ formGroupClasses?: string;
17
+ fullWidth?: boolean;
18
+ describedBy?: string;
19
+ } & Omit<import("svelte/elements").HTMLSelectAttributes, "id" | "name" | "value" | "class" | "aria-describedby">;
20
+ declare const Select: import("svelte").Component<$$ComponentProps, {}, "value">;
21
+ type Select = ReturnType<typeof Select>;
22
+ export default Select;
@@ -0,0 +1,143 @@
1
+ <!-- Service Navigation component
2
+ Use the component with or without navigation items based on your needs. -->
3
+
4
+ <script lang="ts">
5
+ import { onMount } from "svelte";
6
+ import { browser } from "$app/environment";
7
+
8
+ // Define types for navigation items
9
+ type NavigationItem = {
10
+ href: string;
11
+ label: string;
12
+ isActive?: boolean;
13
+ };
14
+
15
+ let {
16
+ serviceName = "Service name",
17
+ serviceUrl = "#",
18
+ navigationItems = undefined,
19
+ } = $props<{
20
+ serviceName?: string;
21
+ serviceUrl?: string;
22
+ navigationItems?: NavigationItem[];
23
+ }>();
24
+
25
+ // Reactive state declarations
26
+ let hasNavigation = $derived(navigationItems && navigationItems.length > 0);
27
+ let menuIsOpen = $state(false);
28
+ let isDesktopView = $state(true); // Default to desktop view until we can check
29
+ let tabletBreakpoint = $state("");
30
+
31
+ // References to DOM elements
32
+ let navigationElement = $state<HTMLElement | null>(null);
33
+ let buttonElement = $state<HTMLButtonElement | null>(null);
34
+
35
+ // Derived values for UI state
36
+ let isMenuVisible = $derived(isDesktopView || menuIsOpen);
37
+ let isButtonHidden = $derived(isDesktopView);
38
+
39
+ onMount(() => {
40
+ if (!browser) return;
41
+
42
+ // Get the breakpoint from CSS custom property
43
+ const property = "--govuk-frontend-breakpoint-tablet";
44
+ const value = window
45
+ .getComputedStyle(document.documentElement)
46
+ .getPropertyValue(property)
47
+ .trim();
48
+
49
+ tabletBreakpoint = value || "768px";
50
+
51
+ if (!value) {
52
+ console.warn(
53
+ "CSS custom property (--govuk-frontend-breakpoint-tablet) not found, using fallback",
54
+ );
55
+ }
56
+
57
+ // Initialize media query
58
+ const mql = window.matchMedia(`(min-width: ${tabletBreakpoint})`);
59
+
60
+ // Set initial state
61
+ isDesktopView = mql.matches;
62
+
63
+ // Set up event listener for viewport changes
64
+ const handleViewportChange = (e: MediaQueryListEvent) => {
65
+ isDesktopView = e.matches;
66
+ if (isDesktopView) {
67
+ // Reset menu state when switching to desktop
68
+ menuIsOpen = false;
69
+ }
70
+ };
71
+
72
+ mql.addEventListener("change", handleViewportChange);
73
+
74
+ return () => {
75
+ mql.removeEventListener("change", handleViewportChange);
76
+ };
77
+ });
78
+
79
+ // Handle menu button click
80
+ function toggleMenu() {
81
+ menuIsOpen = !menuIsOpen;
82
+ }
83
+ </script>
84
+
85
+ <section
86
+ aria-label="Service information"
87
+ class="govuk-service-navigation"
88
+ data-module="govuk-service-navigation"
89
+ >
90
+ <div class="govuk-width-container">
91
+ <div class="govuk-service-navigation__container">
92
+ <span class="govuk-service-navigation__service-name">
93
+ <a href={serviceUrl} class="govuk-service-navigation__link">
94
+ {serviceName}
95
+ </a>
96
+ </span>
97
+
98
+ {#if hasNavigation}
99
+ <nav aria-label="Menu" class="govuk-service-navigation__wrapper">
100
+ <button
101
+ type="button"
102
+ class="govuk-service-navigation__toggle govuk-js-service-navigation-toggle"
103
+ aria-controls="navigation"
104
+ aria-expanded={menuIsOpen}
105
+ onclick={toggleMenu}
106
+ bind:this={buttonElement}
107
+ hidden={isButtonHidden}
108
+ >
109
+ Menu
110
+ </button>
111
+ <ul
112
+ class="govuk-service-navigation__list"
113
+ id="navigation"
114
+ bind:this={navigationElement}
115
+ hidden={!isMenuVisible}
116
+ >
117
+ {#each navigationItems as item}
118
+ <li
119
+ class="govuk-service-navigation__item{item.isActive
120
+ ? ' govuk-service-navigation__item--active'
121
+ : ''}"
122
+ >
123
+ <a
124
+ class="govuk-service-navigation__link"
125
+ href={item.href}
126
+ aria-current={item.isActive ? "true" : undefined}
127
+ >
128
+ {#if item.isActive}
129
+ <strong class="govuk-service-navigation__active-fallback"
130
+ >{item.label}</strong
131
+ >
132
+ {:else}
133
+ {item.label}
134
+ {/if}
135
+ </a>
136
+ </li>
137
+ {/each}
138
+ </ul>
139
+ </nav>
140
+ {/if}
141
+ </div>
142
+ </div>
143
+ </section>
@@ -0,0 +1,13 @@
1
+ type NavigationItem = {
2
+ href: string;
3
+ label: string;
4
+ isActive?: boolean;
5
+ };
6
+ type $$ComponentProps = {
7
+ serviceName?: string;
8
+ serviceUrl?: string;
9
+ navigationItems?: NavigationItem[];
10
+ };
11
+ declare const ServiceNavigation: import("svelte").Component<$$ComponentProps, {}, "">;
12
+ type ServiceNavigation = ReturnType<typeof ServiceNavigation>;
13
+ export default ServiceNavigation;
@@ -0,0 +1,346 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+
4
+ // Define types for items and subitems
5
+ export type NavItem = {
6
+ id?: string;
7
+ text: string;
8
+ href: string;
9
+ subItems?: NavSubItem[];
10
+ };
11
+
12
+ export type NavSubItem = {
13
+ id?: string;
14
+ text: string;
15
+ href: string;
16
+ };
17
+
18
+ // Component props
19
+ let {
20
+ items = [],
21
+ ariaLabel = "Side",
22
+ selectedItem = $bindable(""),
23
+ selectedSubItem = $bindable(""),
24
+ mobile = {
25
+ disabled: false,
26
+ showButtonText: "Show navigation",
27
+ hideButtonText: "Hide navigation",
28
+ },
29
+ } = $props<{
30
+ items: NavItem[];
31
+ ariaLabel?: string;
32
+ selectedItem?: string;
33
+ selectedSubItem?: string;
34
+ mobile?: {
35
+ disabled?: boolean;
36
+ showButtonText?: string;
37
+ hideButtonText?: string;
38
+ };
39
+ }>();
40
+
41
+ // State for mobile navigation
42
+ let expanded = $state(false);
43
+ let isJsEnabled = $state(false);
44
+ let mobileClosed = $state(false);
45
+
46
+ // Check if JavaScript is enabled on mount
47
+ onMount(() => {
48
+ isJsEnabled = true;
49
+ // Initialize mobileClosed based on initial state
50
+ mobileClosed = isJsEnabled && !expanded && !mobile.disabled;
51
+ });
52
+
53
+ // Toggle mobile navigation
54
+ function toggleSideNavigation(event: Event) {
55
+ event.preventDefault();
56
+ expanded = !expanded;
57
+ // Update mobileClosed when expanded changes
58
+ mobileClosed = isJsEnabled && !expanded && !mobile.disabled;
59
+ }
60
+ </script>
61
+
62
+ {#if !mobile.disabled}
63
+ <button
64
+ class="dwp-side-navigation__button"
65
+ data-module="dwp-side-navigation"
66
+ data-target="dwp-side-navigation-panel"
67
+ aria-expanded={expanded}
68
+ onclick={toggleSideNavigation}
69
+ >
70
+ <span class="dwp-side-navigation__section-toggle-focus">
71
+ <span
72
+ class="dwp-side-navigation__chevron {expanded
73
+ ? 'dwp-side-navigation__chevron--down'
74
+ : ''}"
75
+ ></span>
76
+ <span class="dwp-side-navigation__section-toggle-text">
77
+ {expanded ? mobile.hideButtonText : mobile.showButtonText}
78
+ </span>
79
+ </span>
80
+ </button>
81
+ {/if}
82
+
83
+ <nav
84
+ class="dwp-side-navigation {mobileClosed
85
+ ? 'dwp-side-navigation--mobile'
86
+ : ''}"
87
+ aria-label={ariaLabel}
88
+ role="navigation"
89
+ >
90
+ <ul class="dwp-side-navigation__list">
91
+ {#each items as item}
92
+ {@const currentSection = item.href && item.href === selectedItem}
93
+ {@const selected = selectedSubItem || selectedItem}
94
+ <li
95
+ class="dwp-side-navigation__item{currentSection
96
+ ? ' dwp-side-navigation__item--selected'
97
+ : ''}"
98
+ >
99
+ <a
100
+ id={item.id}
101
+ href={item.href}
102
+ class="dwp-side-navigation__link{selected === item.href
103
+ ? ' dwp-side-navigation__link--selected'
104
+ : ''}"
105
+ aria-current={selected === item.href ? "true" : undefined}
106
+ >
107
+ {item.text}
108
+ </a>
109
+ {#if currentSection && item.subItems && item.subItems.length > 0}
110
+ <ul
111
+ class="dwp-side-navigation__list dwp-side-navigation__list--sub-item"
112
+ >
113
+ {#each item.subItems as subItem}
114
+ <li class="dwp-side-navigation__sub-item">
115
+ <a
116
+ id={subItem.id}
117
+ href={subItem.href}
118
+ class="dwp-side-navigation__link{selected === subItem.href
119
+ ? ' dwp-side-navigation__link--selected'
120
+ : ''}"
121
+ aria-current={selected === subItem.href ? "true" : undefined}
122
+ >
123
+ {subItem.text}
124
+ </a>
125
+ </li>
126
+ {/each}
127
+ </ul>
128
+ {/if}
129
+ </li>
130
+ {/each}
131
+ </ul>
132
+ </nav>
133
+
134
+ <style>
135
+ .dwp-side-navigation {
136
+ margin-bottom: var(--govuk-spacing-2, 10px);
137
+ }
138
+
139
+ @media (max-width: 767px) {
140
+ .dwp-side-navigation {
141
+ max-width: 220px;
142
+ }
143
+ }
144
+
145
+ .dwp-side-navigation__button {
146
+ display: none;
147
+ font-size: 19px;
148
+ line-height: 1.25;
149
+ margin-bottom: var(--govuk-spacing-2, 10px);
150
+ padding: var(--govuk-spacing-1, 5px) 2px var(--govuk-spacing-1, 5px) 0;
151
+ border-width: 0;
152
+ color: var(--govuk-link-colour, #1d70b8);
153
+ background: none;
154
+ cursor: pointer;
155
+ -webkit-appearance: none;
156
+ }
157
+
158
+ @media (max-width: 767px) {
159
+ .dwp-side-navigation__button {
160
+ padding: var(--govuk-spacing-2, 10px) var(--govuk-spacing-2, 10px)
161
+ var(--govuk-spacing-2, 10px) 0;
162
+ }
163
+ }
164
+
165
+ .dwp-side-navigation__button:hover {
166
+ color: #0b0c0c;
167
+ background: #f3f2f1;
168
+ }
169
+
170
+ .dwp-side-navigation__button:hover .dwp-side-navigation__chevron {
171
+ color: #0b0c0c;
172
+ background: #0b0c0c;
173
+ }
174
+
175
+ .dwp-side-navigation__button:hover .dwp-side-navigation__chevron::after {
176
+ color: #f3f2f1;
177
+ }
178
+
179
+ .dwp-side-navigation__button:focus {
180
+ outline: 3px solid transparent;
181
+ color: #0b0c0c;
182
+ background-color: #ffdd00;
183
+ box-shadow:
184
+ 0 -2px #ffdd00,
185
+ 0 4px #0b0c0c;
186
+ text-decoration: none;
187
+ }
188
+
189
+ .dwp-side-navigation__button:focus .dwp-side-navigation__chevron {
190
+ color: #0b0c0c;
191
+ background: #0b0c0c;
192
+ }
193
+
194
+ .dwp-side-navigation__button:focus .dwp-side-navigation__chevron::after {
195
+ color: #ffdd00;
196
+ }
197
+
198
+ .dwp-side-navigation__section-toggle-text {
199
+ margin-left: var(--govuk-spacing-2, 10px);
200
+ vertical-align: middle;
201
+ }
202
+
203
+ .dwp-side-navigation__chevron {
204
+ box-sizing: border-box;
205
+ display: inline-block;
206
+ position: relative;
207
+ width: 20px;
208
+ height: 20px;
209
+ border: 1px solid;
210
+ border-radius: 50%;
211
+ vertical-align: middle;
212
+ }
213
+
214
+ .dwp-side-navigation__chevron--down {
215
+ transform: rotate(180deg);
216
+ }
217
+
218
+ .dwp-side-navigation__chevron::after {
219
+ content: "";
220
+ box-sizing: border-box;
221
+ display: block;
222
+ position: absolute;
223
+ bottom: 5px;
224
+ left: 6px;
225
+ width: 6px;
226
+ height: 6px;
227
+ transform: rotate(-45deg);
228
+ border-top: 2px solid;
229
+ border-right: 2px solid;
230
+ }
231
+
232
+ .dwp-side-navigation__list {
233
+ font-size: 19px;
234
+ line-height: 1.25;
235
+ margin-top: 0;
236
+ margin-bottom: 30px;
237
+ padding-left: 0;
238
+ list-style-type: none;
239
+ }
240
+
241
+ .dwp-side-navigation__list > li {
242
+ margin-bottom: var(--govuk-spacing-1, 5px);
243
+ }
244
+
245
+ .dwp-side-navigation__list--sub-item {
246
+ margin-top: var(--govuk-spacing-1, 5px);
247
+ }
248
+
249
+ .dwp-side-navigation__item {
250
+ box-sizing: border-box;
251
+ padding: var(--govuk-spacing-1, 5px) 0 0;
252
+ }
253
+
254
+ @media (max-width: 767px) {
255
+ .dwp-side-navigation__item {
256
+ padding: 0;
257
+ }
258
+ }
259
+
260
+ .dwp-side-navigation__item--selected {
261
+ margin: var(--govuk-spacing-2, 10px) 0 var(--govuk-spacing-1, 5px) -14px;
262
+ padding: var(--govuk-spacing-1, 5px) 0 var(--govuk-spacing-1, 5px)
263
+ var(--govuk-spacing-2, 10px);
264
+ border-left: 4px solid var(--govuk-link-colour, #1d70b8);
265
+ background-color: #f3f2f1;
266
+ }
267
+
268
+ @media (max-width: 767px) {
269
+ .dwp-side-navigation__item--selected {
270
+ margin-left: 0;
271
+ padding: 0 0 0 var(--govuk-spacing-2, 10px);
272
+ }
273
+ }
274
+
275
+ .dwp-side-navigation__item :last-child {
276
+ margin-bottom: 0;
277
+ }
278
+
279
+ .dwp-side-navigation__link {
280
+ font-size: 16px;
281
+ text-decoration: none;
282
+ color: var(--govuk-link-colour, #1d70b8);
283
+ }
284
+
285
+ .dwp-side-navigation__link:hover {
286
+ color: #003078;
287
+ text-decoration: underline;
288
+ }
289
+
290
+ .dwp-side-navigation__link:focus {
291
+ outline: 3px solid transparent;
292
+ color: #0b0c0c;
293
+ background-color: #ffdd00;
294
+ box-shadow:
295
+ 0 -2px #ffdd00,
296
+ 0 4px #0b0c0c;
297
+ text-decoration: none;
298
+ }
299
+
300
+ @media (max-width: 767px) {
301
+ .dwp-side-navigation__link {
302
+ display: inline-block;
303
+ padding: calc(var(--govuk-spacing-2, 10px) - 1px) 0;
304
+ }
305
+ }
306
+
307
+ .dwp-side-navigation__link--selected {
308
+ font-weight: bold;
309
+ }
310
+
311
+ .dwp-side-navigation__sub-item {
312
+ box-sizing: border-box;
313
+ padding: var(--govuk-spacing-1, 5px) 0 0;
314
+ }
315
+
316
+ @media (max-width: 767px) {
317
+ .dwp-side-navigation__sub-item {
318
+ padding: 0;
319
+ }
320
+ }
321
+
322
+ .dwp-side-navigation__sub-item::before {
323
+ content: "—";
324
+ color: #505a5f;
325
+ font-size: 16px;
326
+ font-weight: 700;
327
+ }
328
+
329
+ .dwp-side-navigation__sub-item:last-child {
330
+ padding-bottom: var(--govuk-spacing-1, 5px);
331
+ }
332
+
333
+ /* JavaScript enabled styles */
334
+ :global(.js-enabled) .dwp-side-navigation__button {
335
+ display: none;
336
+ }
337
+
338
+ @media (max-width: 767px) {
339
+ :global(.js-enabled) .dwp-side-navigation__button {
340
+ display: block;
341
+ }
342
+ :global(.js-enabled) .dwp-side-navigation--mobile {
343
+ display: none;
344
+ }
345
+ }
346
+ </style>
@@ -0,0 +1,25 @@
1
+ export type NavSubItem = {
2
+ id?: string;
3
+ text: string;
4
+ href: string;
5
+ };
6
+ export type NavItem = {
7
+ id?: string;
8
+ text: string;
9
+ href: string;
10
+ subItems?: NavSubItem[];
11
+ };
12
+ type $$ComponentProps = {
13
+ items: NavItem[];
14
+ ariaLabel?: string;
15
+ selectedItem?: string;
16
+ selectedSubItem?: string;
17
+ mobile?: {
18
+ disabled?: boolean;
19
+ showButtonText?: string;
20
+ hideButtonText?: string;
21
+ };
22
+ };
23
+ declare const SideNavigation: import("svelte").Component<$$ComponentProps, {}, "selectedItem" | "selectedSubItem">;
24
+ type SideNavigation = ReturnType<typeof SideNavigation>;
25
+ export default SideNavigation;