@communitiesuk/svelte-component-library 0.1.19-beta.2 → 0.1.19-beta.21

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 (43) hide show
  1. package/README.md +7 -0
  2. package/dist/components/data-vis/Histogram.svelte +282 -0
  3. package/dist/components/data-vis/Histogram.svelte.d.ts +75 -0
  4. package/dist/components/data-vis/axis/Axis.svelte +145 -34
  5. package/dist/components/data-vis/axis/Axis.svelte.d.ts +34 -30
  6. package/dist/components/data-vis/axis/Ticks.svelte +163 -60
  7. package/dist/components/data-vis/axis/Ticks.svelte.d.ts +26 -30
  8. package/dist/components/data-vis/line-chart/LineChart.svelte +51 -21
  9. package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +14 -6
  10. package/dist/components/data-vis/position-chart/PositionChart.svelte +255 -117
  11. package/dist/components/data-vis/position-chart/PositionChart.svelte.d.ts +28 -4
  12. package/dist/components/data-vis/position-chart/PositionChartAxis.svelte +39 -34
  13. package/dist/components/data-vis/position-chart/PositionChartAxis.svelte.d.ts +6 -2
  14. package/dist/components/layout/Footer.svelte +9 -0
  15. package/dist/components/layout/Footer.svelte.d.ts +1 -0
  16. package/dist/components/layout/PhaseBanner.svelte +10 -1
  17. package/dist/components/layout/PhaseBanner.svelte.d.ts +1 -0
  18. package/dist/components/layout/ServiceNavigation.svelte +19 -1
  19. package/dist/components/layout/ServiceNavigation.svelte.d.ts +2 -0
  20. package/dist/components/ui/BasicMultiSelect.svelte +185 -0
  21. package/dist/components/ui/BasicMultiSelect.svelte.d.ts +8 -0
  22. package/dist/components/ui/Button.svelte +1 -0
  23. package/dist/components/ui/Card.svelte +48 -60
  24. package/dist/components/ui/Card.svelte.d.ts +26 -12
  25. package/dist/components/ui/CardHeader.svelte +46 -0
  26. package/dist/components/ui/CardHeader.svelte.d.ts +21 -0
  27. package/dist/components/ui/ChartExporter.svelte +142 -0
  28. package/dist/components/ui/ChartExporter.svelte.d.ts +16 -0
  29. package/dist/components/ui/Details.svelte +10 -2
  30. package/dist/components/ui/Details.svelte.d.ts +2 -0
  31. package/dist/components/ui/Masthead.svelte +36 -6
  32. package/dist/components/ui/Masthead.svelte.d.ts +4 -0
  33. package/dist/components/ui/PostcodeOrAreaSearch.svelte +12 -0
  34. package/dist/components/ui/PostcodeOrAreaSearch.svelte.d.ts +4 -0
  35. package/dist/components/ui/RelatedContent.svelte +4 -1
  36. package/dist/components/ui/RelatedContent.svelte.d.ts +1 -0
  37. package/dist/components/ui/SearchAutocomplete.svelte +185 -34
  38. package/dist/components/ui/SearchAutocomplete.svelte.d.ts +5 -0
  39. package/dist/components/ui/Tabs.svelte +190 -18
  40. package/dist/components/ui/Tabs.svelte.d.ts +1 -0
  41. package/dist/index.d.ts +4 -0
  42. package/dist/index.js +4 -0
  43. package/package.json +4 -1
@@ -0,0 +1,46 @@
1
+ <script>
2
+ let {
3
+ text = "Card header",
4
+ textSize = "1.5rem",
5
+ textColor = "#1D70B8",
6
+ backgroundColor = "white",
7
+ href = undefined,
8
+ subtitle = undefined,
9
+ } = $props();
10
+ </script>
11
+
12
+ <a
13
+ class="link govuk-heading-m"
14
+ {href}
15
+ style="font-size: {textSize}; color: {textColor}; background-color: {backgroundColor}; margin: {subtitle ??
16
+ 0}"
17
+ >
18
+ {text}
19
+ <svg
20
+ xmlns="http://www.w3.org/2000/svg"
21
+ width="1em"
22
+ height="1em"
23
+ viewBox="0 0 10 17"
24
+ aria-hidden="true"
25
+ >
26
+ <path
27
+ d="M6.21622 8.5L0 2.36667L1.89189 0.5L10 8.5L1.89189 16.5L0 14.6333L6.21622 8.5Z"
28
+ fill="currentColor"
29
+ ></path>
30
+ </svg>
31
+ </a>
32
+ {#if subtitle !== undefined}
33
+ <p>{subtitle}</p>{/if}
34
+
35
+ <style>
36
+ .link {
37
+ display: flex;
38
+ justify-content: space-between;
39
+ align-items: center;
40
+ width: 100%;
41
+ gap: 0.5rem;
42
+ }
43
+ p {
44
+ color: #666;
45
+ }
46
+ </style>
@@ -0,0 +1,21 @@
1
+ export default CardHeader;
2
+ type CardHeader = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const CardHeader: import("svelte").Component<{
7
+ text?: string;
8
+ textSize?: string;
9
+ textColor?: string;
10
+ backgroundColor?: string;
11
+ href?: any;
12
+ subtitle?: any;
13
+ }, {}, "">;
14
+ type $$ComponentProps = {
15
+ text?: string;
16
+ textSize?: string;
17
+ textColor?: string;
18
+ backgroundColor?: string;
19
+ href?: any;
20
+ subtitle?: any;
21
+ };
@@ -0,0 +1,142 @@
1
+ <script lang="ts">
2
+ // src/lib/utils/exportChartPNG.ts
3
+ export async function exportChartPNG(
4
+ node: HTMLElement,
5
+ {
6
+ fileName = "chart.png",
7
+ margin = 16,
8
+ backgroundColor = "#ffffff",
9
+ pixelRatio = Math.max(2, window.devicePixelRatio || 1),
10
+ filter,
11
+ }: {
12
+ fileName?: string;
13
+ margin?: number; // padding applied during export to avoid edges clipping
14
+ backgroundColor?: string;
15
+ pixelRatio?: number;
16
+ filter?: (node: Element) => boolean;
17
+ },
18
+ ): Promise<string> {
19
+ const { toPng } = await import("html-to-image");
20
+
21
+ // Wait for web fonts to settle (prevents text reflow/misalignment)
22
+ if ((document as any).fonts?.ready) {
23
+ try {
24
+ await (document as any).fonts.ready;
25
+ } catch {
26
+ /* ignore */
27
+ }
28
+ }
29
+
30
+ // Measure the true content size (includes overflow)
31
+ const exportWidth = Math.ceil(node.scrollWidth + margin * 2);
32
+ const exportHeight = Math.ceil(node.scrollHeight + margin * 2);
33
+
34
+ const dataUrl = await toPng(node, {
35
+ cacheBust: false,
36
+ backgroundColor,
37
+ pixelRatio,
38
+ width: exportWidth,
39
+ height: exportHeight,
40
+ style: {
41
+ // Apply padding inside the cloned element
42
+ padding: `${margin}px`,
43
+ boxSizing: "border-box",
44
+ // Ensure no clipping
45
+ overflow: "visible",
46
+ },
47
+ filter,
48
+ });
49
+
50
+ const name = fileName.toLowerCase().endsWith(".png")
51
+ ? fileName
52
+ : `${fileName}.png`;
53
+ const link = document.createElement("a");
54
+ link.download = name;
55
+ link.href = dataUrl;
56
+ link.click();
57
+
58
+ return dataUrl;
59
+ }
60
+
61
+ // Props
62
+ let {
63
+ node = null,
64
+ fileName = "chart",
65
+ }: { node: HTMLElement | null; fileName?: string } = $props();
66
+
67
+ // Local state for optional external triggering
68
+ let isExporting = $state(false);
69
+
70
+ async function exportNow() {
71
+ if (!node) return;
72
+
73
+ isExporting = true;
74
+
75
+ // Measure width to force correct clone sizing
76
+ const rect = node.getBoundingClientRect();
77
+ const measuredWidth = Math.ceil(rect.width);
78
+
79
+ // ------- Clone -------
80
+ const clone = node.cloneNode(true) as HTMLElement;
81
+ Object.assign(clone.style, {
82
+ boxSizing: "border-box",
83
+ width: `${measuredWidth}px`,
84
+ height: "auto",
85
+ transform: "none",
86
+ overflow: "visible",
87
+ fontFamily: "GDS Transport",
88
+ });
89
+
90
+ // ------- Hide tooltips (optional) -------
91
+ const hideSelectors = ['[role="tooltip"]'];
92
+ clone
93
+ .querySelectorAll<HTMLElement>(hideSelectors.join(","))
94
+ .forEach((el) => {
95
+ el.style.display = "none";
96
+ });
97
+
98
+ // ------- Sandbox offscreen -------
99
+ const sandbox = document.createElement("div");
100
+ Object.assign(sandbox.style, {
101
+ position: "fixed",
102
+ left: "-10000px",
103
+ top: "0",
104
+ pointerEvents: "none",
105
+ });
106
+
107
+ sandbox.appendChild(clone);
108
+ document.body.appendChild(sandbox);
109
+
110
+ try {
111
+ await exportChartPNG(clone, {
112
+ fileName,
113
+ margin: 16,
114
+ backgroundColor: "#ffffff",
115
+ pixelRatio: Math.max(2, window.devicePixelRatio || 1),
116
+ filter: (el: Element) => {
117
+ if (!(el instanceof HTMLElement)) return true;
118
+
119
+ // Exclude tooltips only
120
+ if (el.matches(hideSelectors.join(","))) return false;
121
+
122
+ return true;
123
+ },
124
+ });
125
+ } finally {
126
+ sandbox.remove();
127
+ isExporting = false;
128
+ }
129
+ }
130
+
131
+ // We export the function so parent can trigger it manually
132
+ export { exportNow };
133
+ </script>
134
+
135
+ <!-- Default button (can be hidden if user triggers manually) -->
136
+ <button
137
+ class="govuk-button govuk-button--secondary"
138
+ on:click={exportNow}
139
+ disabled={isExporting}
140
+ >
141
+ {isExporting ? "Exporting…" : "Download this chart"}
142
+ </button>
@@ -0,0 +1,16 @@
1
+ type $$ComponentProps = {
2
+ node: HTMLElement | null;
3
+ fileName?: string;
4
+ };
5
+ declare const ChartExporter: import("svelte").Component<$$ComponentProps, {
6
+ exportChartPNG: (node: HTMLElement, { fileName, margin, backgroundColor, pixelRatio, filter, }: {
7
+ fileName?: string;
8
+ margin?: number;
9
+ backgroundColor?: string;
10
+ pixelRatio?: number;
11
+ filter?: (node: Element) => boolean;
12
+ }) => Promise<string>;
13
+ exportNow: () => Promise<void>;
14
+ }, "">;
15
+ type ChartExporter = ReturnType<typeof ChartExporter>;
16
+ export default ChartExporter;
@@ -1,5 +1,5 @@
1
1
  <script>
2
- let { summaryText, detailedText } = $props();
2
+ let { summaryText, detailedText, renderStringAsHTML = false } = $props();
3
3
  </script>
4
4
 
5
5
  <details class="govuk-details">
@@ -7,6 +7,14 @@
7
7
  <span class="govuk-details__summary-text">{summaryText}</span>
8
8
  </summary>
9
9
  <div class="govuk-details__text">
10
- {detailedText}
10
+ {#if typeof detailedText === "string"}
11
+ {#if renderStringAsHTML}
12
+ {@html detailedText}
13
+ {:else}
14
+ {detailedText}
15
+ {/if}
16
+ {:else if detailedText}
17
+ {@render detailedText()}
18
+ {/if}
11
19
  </div>
12
20
  </details>
@@ -6,8 +6,10 @@ type Details = {
6
6
  declare const Details: import("svelte").Component<{
7
7
  summaryText: any;
8
8
  detailedText: any;
9
+ renderStringAsHTML?: boolean;
9
10
  }, {}, "">;
10
11
  type $$ComponentProps = {
11
12
  summaryText: any;
12
13
  detailedText: any;
14
+ renderStringAsHTML?: boolean;
13
15
  };
@@ -12,6 +12,10 @@
12
12
  imageAlt = "",
13
13
  backgroundColor = "#1d70b8", // GOV.UK blue by default
14
14
  textColor = "#FFFFFF",
15
+ imgMarginTop = "15px",
16
+ paddingTop = "30px",
17
+ titlePaddingTop = false,
18
+ paddingBottom = "30px",
15
19
  } = $props<{
16
20
  title?: string;
17
21
  description?: string;
@@ -22,16 +26,24 @@
22
26
  imageAlt?: string;
23
27
  backgroundColor?: string;
24
28
  textColor?: string;
29
+ imgMarginTop?: string;
30
+ paddingTop?: string;
31
+ titlePaddingTop?: boolean;
32
+ paddingBottom?: string;
25
33
  }>();
26
34
  </script>
27
35
 
28
36
  <div
29
37
  class="app-masthead"
30
- style="background-color: {backgroundColor}; border-bottom-color: {backgroundColor}; --masthead-text-color: {textColor};"
38
+ style="background-color: {backgroundColor}; border-bottom-color: {backgroundColor}; --masthead-text-color: {textColor}; --padding-top: {paddingTop}; --padding-bottom: {paddingBottom};"
31
39
  >
32
40
  <div class="govuk-width-container">
33
41
  <div class="govuk-grid-row">
34
- <div class="govuk-grid-column-two-thirds-from-desktop">
42
+ <div
43
+ class="govuk-grid-column-two-thirds-from-desktop {titlePaddingTop
44
+ ? 'custom-padding'
45
+ : ''}"
46
+ >
35
47
  <h1 class="govuk-heading-xl app-masthead__title">{@html title}</h1>
36
48
  <p class="app-masthead__description">{description}</p>
37
49
  {#if includeButton === true}
@@ -61,6 +73,7 @@
61
73
  <div class="govuk-grid-column-one-third-from-desktop">
62
74
  <img
63
75
  class="app-masthead__image"
76
+ style="--img-margin-top: {imgMarginTop}"
64
77
  src={imageSrc}
65
78
  alt={imageAlt}
66
79
  role="presentation"
@@ -88,8 +101,8 @@
88
101
  @media (min-width: 40.0625em) {
89
102
  .app-masthead.app-masthead {
90
103
  /* Responsive spacing unit 6: 30px on large screens */
91
- padding-top: 30px;
92
- padding-bottom: 30px;
104
+ padding-top: var(--padding-top);
105
+ padding-bottom: var(--padding-bottom);
93
106
  }
94
107
  }
95
108
 
@@ -128,12 +141,19 @@
128
141
  }
129
142
 
130
143
  /* @include govuk-media-query($from: desktop) - Desktop breakpoint is 769px */
131
- @media (min-width: 48.0625em) {
144
+ @media (min-width: 53em) {
132
145
  .app-masthead .app-masthead__image.app-masthead__image {
133
146
  display: block;
134
147
  width: 100%;
135
148
  /* margin-top: govuk-spacing(3); - Static spacing unit 3 is 15px */
136
- margin-top: 15px;
149
+ margin-top: var(--img-margin-top);
150
+ }
151
+ }
152
+
153
+ @media (max-width: 52.9375em) {
154
+ .govuk-grid-column-two-thirds-from-desktop {
155
+ width: 100%;
156
+ float: none;
137
157
  }
138
158
  }
139
159
 
@@ -276,4 +296,14 @@
276
296
  .app-masthead__description {
277
297
  color: var(--masthead-text-color);
278
298
  }
299
+
300
+ .custom-padding {
301
+ padding-top: 32px;
302
+ }
303
+
304
+ @media (max-width: 820px) {
305
+ .custom-padding {
306
+ padding-top: 16px;
307
+ }
308
+ }
279
309
  </style>
@@ -8,6 +8,10 @@ type $$ComponentProps = {
8
8
  imageAlt?: string;
9
9
  backgroundColor?: string;
10
10
  textColor?: string;
11
+ imgMarginTop?: string;
12
+ paddingTop?: string;
13
+ titlePaddingTop?: boolean;
14
+ paddingBottom?: string;
11
15
  };
12
16
  declare const Masthead: import("svelte").Component<$$ComponentProps, {}, "">;
13
17
  type Masthead = ReturnType<typeof Masthead>;
@@ -57,6 +57,10 @@
57
57
  homepage?: boolean;
58
58
  minLength?: number;
59
59
  required?: boolean;
60
+ autoselect?: boolean; // Auto-highlight first suggestion
61
+ hideHint?: boolean; // Hide the hint input element when autoselect is true
62
+ prefixMatchOnly?: boolean; // Only show suggestions that start with the query
63
+ autoFocusSubmitOnSelection?: boolean; // Auto-focus submit button when selection is confirmed
60
64
  [key: string]: any; // Allow other props
61
65
  };
62
66
 
@@ -83,6 +87,10 @@
83
87
  homepage = false,
84
88
  minLength = 2,
85
89
  required = false,
90
+ autoselect = true,
91
+ hideHint = false,
92
+ prefixMatchOnly = false,
93
+ autoFocusSubmitOnSelection = false,
86
94
  ...restProps
87
95
  }: Props = $props();
88
96
 
@@ -222,6 +230,10 @@
222
230
  homepage,
223
231
  minLength,
224
232
  required,
233
+ autoselect,
234
+ hideHint,
235
+ prefixMatchOnly,
236
+ autoFocusSubmitOnSelection,
225
237
  ...restProps,
226
238
  });
227
239
  </script>
@@ -31,6 +31,10 @@ type Props = {
31
31
  homepage?: boolean;
32
32
  minLength?: number;
33
33
  required?: boolean;
34
+ autoselect?: boolean;
35
+ hideHint?: boolean;
36
+ prefixMatchOnly?: boolean;
37
+ autoFocusSubmitOnSelection?: boolean;
34
38
  [key: string]: any;
35
39
  };
36
40
  declare const PostcodeOrAreaSearch: import("svelte").Component<Props, {}, "selectedValue">;
@@ -30,11 +30,13 @@
30
30
  headingLevel = 2 as 1 | 2 | 3 | 4 | 5 | 6, // Main heading level (used by first 'main' section)
31
31
  listTruncateThreshold = 5, // Default threshold, can be overridden per section
32
32
  disableGa4 = false,
33
+ marginBottom = "60px",
33
34
  } = $props<{
34
35
  sections?: RelatedContentSection[];
35
36
  headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
36
37
  listTruncateThreshold?: number; // Default threshold
37
38
  disableGa4?: boolean;
39
+ marginBottom?: string;
38
40
  }>();
39
41
 
40
42
  // Helper to check if a link is external
@@ -229,6 +231,7 @@
229
231
  class="gem-c-related-navigation govuk-!-display-none-print {hasJavaScript
230
232
  ? 'govuk-frontend-supported'
231
233
  : ''}"
234
+ style="margin-bottom: {marginBottom};"
232
235
  role="complementary"
233
236
  >
234
237
  {#if mainSection && mainSection.title}
@@ -304,7 +307,7 @@
304
307
  <style>
305
308
  .gem-c-related-navigation {
306
309
  border-top: 2px solid #1d70b8;
307
- margin-bottom: 60px;
310
+ /* margin-bottom: 60px; */
308
311
  color: #0b0c0c;
309
312
  }
310
313
 
@@ -24,6 +24,7 @@ type $$ComponentProps = {
24
24
  headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
25
25
  listTruncateThreshold?: number;
26
26
  disableGa4?: boolean;
27
+ marginBottom?: string;
27
28
  };
28
29
  declare const RelatedContent: import("svelte").Component<$$ComponentProps, {}, "">;
29
30
  type RelatedContent = ReturnType<typeof RelatedContent>;