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

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 +245 -0
  3. package/dist/components/data-vis/Histogram.svelte.d.ts +71 -0
  4. package/dist/components/data-vis/axis/Axis.svelte +140 -34
  5. package/dist/components/data-vis/axis/Axis.svelte.d.ts +34 -30
  6. package/dist/components/data-vis/axis/Ticks.svelte +155 -60
  7. package/dist/components/data-vis/axis/Ticks.svelte.d.ts +25 -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 +220 -112
  11. package/dist/components/data-vis/position-chart/PositionChart.svelte.d.ts +26 -4
  12. package/dist/components/data-vis/position-chart/PositionChartAxis.svelte +38 -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
@@ -51,6 +51,7 @@
51
51
  copyrightHref = "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/",
52
52
  rebrand = true,
53
53
  borderTopColor = "#00625E",
54
+ removeCopyrightPadding = false,
54
55
  } = $props<{
55
56
  sections?: FooterSection[];
56
57
  inlineLinks?: FooterItem[];
@@ -68,6 +69,7 @@
68
69
  copyrightHref?: string;
69
70
  rebrand?: boolean;
70
71
  borderTopColor?: string;
72
+ removeCopyrightPadding?: boolean;
71
73
  }>();
72
74
  </script>
73
75
 
@@ -218,6 +220,7 @@
218
220
  <a
219
221
  class={[
220
222
  "govuk-footer__link",
223
+ { "no-copyright-padding": removeCopyrightPadding },
221
224
  {
222
225
  "govuk-footer__copyright-logo": !copyrightLogoUrl && rebrand,
223
226
  },
@@ -234,3 +237,9 @@
234
237
  </div>
235
238
  </div>
236
239
  </footer>
240
+
241
+ <style>
242
+ .no-copyright-padding {
243
+ padding: 0;
244
+ }
245
+ </style>
@@ -27,6 +27,7 @@ type $$ComponentProps = {
27
27
  copyrightHref?: string;
28
28
  rebrand?: boolean;
29
29
  borderTopColor?: string;
30
+ removeCopyrightPadding?: boolean;
30
31
  };
31
32
  declare const Footer: import("svelte").Component<$$ComponentProps, {}, "">;
32
33
  type Footer = ReturnType<typeof Footer>;
@@ -5,15 +5,21 @@
5
5
  bannerText = "This is a new service. Help us improve it and ",
6
6
  linkText = "give your feedback by email",
7
7
  linkHref = "#",
8
+ bottomBorder = true,
8
9
  } = $props<{
9
10
  tagText?: string;
10
11
  bannerText?: string;
11
12
  linkText?: string;
12
13
  linkHref?: string;
14
+ bottomBorder?: boolean;
13
15
  }>();
14
16
  </script>
15
17
 
16
- <div class="govuk-phase-banner govuk-width-container">
18
+ <div
19
+ class="govuk-phase-banner govuk-width-container {bottomBorder
20
+ ? ''
21
+ : 'no-bottom-border'}"
22
+ >
17
23
  <p class="govuk-phase-banner__content">
18
24
  <strong class="govuk-tag govuk-phase-banner__content__tag">
19
25
  {tagText}
@@ -25,4 +31,7 @@
25
31
  </div>
26
32
 
27
33
  <style>
34
+ .no-bottom-border {
35
+ border-bottom: none;
36
+ }
28
37
  </style>
@@ -3,6 +3,7 @@ type $$ComponentProps = {
3
3
  bannerText?: string;
4
4
  linkText?: string;
5
5
  linkHref?: string;
6
+ bottomBorder?: boolean;
6
7
  };
7
8
  declare const PhaseBanner: import("svelte").Component<$$ComponentProps, {}, "">;
8
9
  type PhaseBanner = ReturnType<typeof PhaseBanner>;
@@ -17,11 +17,15 @@ Use the component with or without navigation items based on your needs. -->
17
17
  serviceUrl = "#",
18
18
  navigationItems = undefined,
19
19
  collapseOnDesktop = false,
20
+ customiseServiceNameLink = false,
21
+ serviceNameLinkStyle = "govuk-link no-underline",
20
22
  } = $props<{
21
23
  serviceName?: string;
22
24
  serviceUrl?: string;
23
25
  navigationItems?: NavigationItem[];
24
26
  collapseOnDesktop?: boolean;
27
+ customiseServiceNameLink?: boolean;
28
+ serviceNameLinkStyle?: string;
25
29
  }>();
26
30
 
27
31
  // Reactive state declarations
@@ -94,7 +98,12 @@ Use the component with or without navigation items based on your needs. -->
94
98
  <div class="govuk-width-container">
95
99
  <div class="govuk-service-navigation__container">
96
100
  <span class="govuk-service-navigation__service-name">
97
- <a href={serviceUrl} class="govuk-service-navigation__link">
101
+ <a
102
+ href={serviceUrl}
103
+ class={customiseServiceNameLink
104
+ ? serviceNameLinkStyle
105
+ : "govuk-service-navigation__link"}
106
+ >
98
107
  {serviceName}
99
108
  </a>
100
109
  </span>
@@ -145,3 +154,12 @@ Use the component with or without navigation items based on your needs. -->
145
154
  </div>
146
155
  </div>
147
156
  </section>
157
+
158
+ <style>
159
+ .no-underline {
160
+ text-decoration: none;
161
+ }
162
+ .no-underline:hover {
163
+ text-decoration: underline;
164
+ }
165
+ </style>
@@ -8,6 +8,8 @@ type $$ComponentProps = {
8
8
  serviceUrl?: string;
9
9
  navigationItems?: NavigationItem[];
10
10
  collapseOnDesktop?: boolean;
11
+ customiseServiceNameLink?: boolean;
12
+ serviceNameLinkStyle?: string;
11
13
  };
12
14
  declare const ServiceNavigation: import("svelte").Component<$$ComponentProps, {}, "">;
13
15
  type ServiceNavigation = ReturnType<typeof ServiceNavigation>;
@@ -0,0 +1,185 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { browser } from "$app/environment";
4
+
5
+ type Option = { id: string | number; label: string };
6
+ type SelectedWithColor = Option & { color: string };
7
+
8
+ // ---------- Props ----------
9
+ let {
10
+ options = [],
11
+ selectedWithColors = $bindable<SelectedWithColor[]>([]),
12
+ colorArray = ["#808080"],
13
+ placeholder = "Select...",
14
+ } = $props();
15
+
16
+ let showDropdown = $state(false);
17
+ let search = $state("");
18
+
19
+ // ---------- Assign colours to incoming items ----------
20
+ $effect(() => {
21
+ if (!Array.isArray(selectedWithColors)) return;
22
+ if (!colorArray.length) return;
23
+
24
+ const used = new Set(
25
+ selectedWithColors.map((s) => s.color).filter(Boolean),
26
+ );
27
+ let changed = false;
28
+
29
+ const updated = selectedWithColors.map((item) => {
30
+ if (item.color) return item;
31
+ const color = colorArray.find((c) => !used.has(c)) ?? colorArray[0];
32
+ used.add(color);
33
+ changed = true;
34
+ return { ...item, color };
35
+ });
36
+
37
+ if (changed) selectedWithColors = updated;
38
+ });
39
+
40
+ // ---------- Compute filtered options ----------
41
+ const filteredOptions = $derived(
42
+ options.filter(
43
+ (o) =>
44
+ !selectedWithColors.some((s) => s.id === o.id) &&
45
+ o.label.toLowerCase().includes(search.toLowerCase()),
46
+ ),
47
+ );
48
+
49
+ // ---------- Helpers ----------
50
+ function getFirstAvailableColor() {
51
+ const used = new Set(selectedWithColors.map((s) => s.color));
52
+ return colorArray.find((c) => !used.has(c)) ?? colorArray[0];
53
+ }
54
+
55
+ function select(option: Option) {
56
+ const color = getFirstAvailableColor();
57
+ selectedWithColors = [...selectedWithColors, { ...option, color }];
58
+ search = "";
59
+ }
60
+
61
+ function remove(item: SelectedWithColor) {
62
+ selectedWithColors = selectedWithColors.filter((s) => s.id !== item.id);
63
+ }
64
+
65
+ // Close dropdown on outside click — browser only
66
+ let container: HTMLDivElement | null = null;
67
+
68
+ onMount(() => {
69
+ if (!browser) return;
70
+
71
+ function handleOutside(e: MouseEvent) {
72
+ if (container && !container.contains(e.target as Node)) {
73
+ showDropdown = false;
74
+ }
75
+ }
76
+
77
+ document.addEventListener("mousedown", handleOutside);
78
+ return () => document.removeEventListener("mousedown", handleOutside);
79
+ });
80
+ </script>
81
+
82
+ <!-- ---------- TEMPLATE ---------- -->
83
+ <div class="container" bind:this={container}>
84
+ <div class="box" on:click={() => (showDropdown = true)}>
85
+ <input
86
+ {placeholder}
87
+ bind:value={search}
88
+ on:input={() => (showDropdown = true)}
89
+ />
90
+
91
+ <div class="tags">
92
+ {#each selectedWithColors as item (item.id)}
93
+ <span class="tag">
94
+ <span class="dot" style={`background:${item.color}`}></span>
95
+ {item.label}
96
+ <button on:click|stopPropagation={() => remove(item)}>×</button>
97
+ </span>
98
+ {/each}
99
+ </div>
100
+ </div>
101
+
102
+ {#if showDropdown}
103
+ <ul class="dropdown">
104
+ {#each filteredOptions as o (o.id)}
105
+ <li on:click={() => select(o)}>{o.label}</li>
106
+ {/each}
107
+
108
+ {#if filteredOptions.length === 0}
109
+ <li class="no">No results</li>
110
+ {/if}
111
+ </ul>
112
+ {/if}
113
+ </div>
114
+
115
+ <style>
116
+ .container {
117
+ position: relative;
118
+ width: 100%;
119
+ }
120
+
121
+ .box {
122
+ border: 1px solid #ccc;
123
+ padding: 8px;
124
+ border-radius: 6px;
125
+ cursor: pointer;
126
+ }
127
+
128
+ input {
129
+ width: 100%;
130
+ font-size: 16px;
131
+ border: none;
132
+ outline: none;
133
+ }
134
+
135
+ .tags {
136
+ margin-top: 6px;
137
+ display: flex;
138
+ flex-wrap: wrap;
139
+ gap: 4px;
140
+ }
141
+
142
+ .tag {
143
+ background: #f3f2f1;
144
+ padding: 2px 6px;
145
+ border-radius: 4px;
146
+ display: inline-flex;
147
+ align-items: center;
148
+ gap: 6px;
149
+ }
150
+
151
+ .dot {
152
+ width: 10px;
153
+ height: 10px;
154
+ border-radius: 50%;
155
+ border: 1px solid #999;
156
+ }
157
+
158
+ .dropdown {
159
+ position: absolute;
160
+ background: white;
161
+ width: 100%;
162
+ border: 1px solid #ccc;
163
+ border-radius: 6px;
164
+ margin-top: 4px;
165
+ z-index: 10;
166
+ max-height: 200px;
167
+ overflow-y: auto;
168
+ padding: 0;
169
+ list-style: none;
170
+ }
171
+
172
+ .dropdown li {
173
+ padding: 8px;
174
+ cursor: pointer;
175
+ }
176
+
177
+ .dropdown li:hover {
178
+ background: #eef4ff;
179
+ }
180
+
181
+ .no {
182
+ color: #777;
183
+ padding: 8px;
184
+ }
185
+ </style>
@@ -0,0 +1,8 @@
1
+ declare const BasicMultiSelect: import("svelte").Component<{
2
+ options?: any[];
3
+ selectedWithColors?: any[];
4
+ colorArray?: any[];
5
+ placeholder?: string;
6
+ }, {}, "selectedWithColors">;
7
+ type BasicMultiSelect = ReturnType<typeof BasicMultiSelect>;
8
+ export default BasicMultiSelect;
@@ -177,6 +177,7 @@
177
177
  }
178
178
 
179
179
  .more-info-button {
180
+ display: flex;
180
181
  flex: none;
181
182
  font-size: 1.25rem;
182
183
  padding-top: 2px;
@@ -1,101 +1,89 @@
1
1
  <script>
2
+ import CardHeader from "./CardHeader.svelte";
3
+
2
4
  let {
3
- linkCard = true,
4
- linkText = undefined,
5
- linkTextColor = "#1D70B8",
5
+ headerIsLink = true,
6
+ headerText = "Card header",
7
+ headerTextSize = "1.5rem",
8
+ headerTextColor = "#1D70B8",
9
+ headerBackgroundColor = "white",
6
10
  href = undefined,
7
- callToActionBackgroundColor = "white",
8
- bodyText = undefined,
11
+ onlyTextInBody = true,
12
+ bodyText = "Text in the body of the card",
13
+ headerSnippet = undefined,
14
+ bodySnippet = undefined,
15
+ children = undefined,
9
16
  bodyTextColor = "#0B0C0C",
10
17
  bodyBackgroundColor = "#FBFCFD",
11
18
  bodyTopBorderColor = "#F4F8FB",
12
19
  bodyBottomBorderColor = "#c3d9e9",
13
20
  selectedValue = $bindable(),
14
- cardSnippet = undefined,
21
+ display = "flex",
22
+ gridPosition = undefined,
23
+ subtitle = undefined,
15
24
  } = $props();
16
25
  </script>
17
26
 
18
- <div class="card">
27
+ <div class="card" style="display: {display}">
19
28
  <div
20
- class="call-to-action"
21
- style="background-color: {callToActionBackgroundColor};"
29
+ class="header-div"
30
+ style="background-color: {headerBackgroundColor}; grid-row: {gridPosition?.[0]
31
+ ?.row ?? null}; grid-column: {gridPosition?.[0]?.col ?? null};"
22
32
  >
23
- {#if linkCard}
24
- <a class="link" {href}>
25
- <h3
26
- class="govuk-link link-heading govuk-heading-m"
27
- style="--link-text-color: {linkTextColor}"
28
- >
29
- {linkText}
30
- </h3>
31
- <svg
32
- xmlns="http://www.w3.org/2000/svg"
33
- width="10"
34
- height="17"
35
- viewBox="0 0 10 17"
36
- fill="none"
37
- >
38
- <path
39
- d="M6.21622 8.5L0 2.36667L1.89189 0.5L10 8.5L1.89189 16.5L0 14.6333L6.21622 8.5Z"
40
- fill={linkTextColor}
41
- ></path>
42
- </svg>
43
- </a>
33
+ {#if headerIsLink}
34
+ <CardHeader
35
+ text={headerText}
36
+ textSize={headerTextSize}
37
+ textColor={headerTextColor}
38
+ backgroundColor={headerBackgroundColor}
39
+ {href}
40
+ {subtitle}
41
+ ></CardHeader>
44
42
  {:else}
45
- {@render cardSnippet()}
43
+ {@render headerSnippet?.()}
46
44
  {/if}
47
45
  </div>
48
46
 
49
47
  <div
50
48
  class="body-div"
51
- style="--body-bg-color: {bodyBackgroundColor}; --body-bottom-border-color: {bodyBottomBorderColor}; --body-top-border-color: {bodyTopBorderColor};"
49
+ style="--body-bg-color: {bodyBackgroundColor}; --body-bottom-border-color: {bodyBottomBorderColor}; --body-top-border-color: {bodyTopBorderColor}; grid-row: {gridPosition?.[1]
50
+ ?.row ?? null}; grid-column: {gridPosition?.[1]?.col ?? null};"
52
51
  >
53
- <p class="govuk-body body-text" style="--body-text-color: {bodyTextColor};">
54
- {bodyText}
55
- </p>
52
+ {#if onlyTextInBody}
53
+ <p
54
+ class="govuk-body body-text"
55
+ style="--body-text-color: {bodyTextColor};"
56
+ >
57
+ {bodyText}
58
+ </p>
59
+ {:else if children}
60
+ {@render children?.()}
61
+ {:else}
62
+ {@render bodySnippet?.()}
63
+ {/if}
56
64
  </div>
57
65
  </div>
58
66
 
59
67
  <style>
60
68
  .card {
61
- display: flex;
62
69
  flex-direction: column;
70
+ min-width: 0;
63
71
  }
64
72
 
65
- .call-to-action {
66
- padding: 15px 20px;
67
- }
68
-
69
- .link {
70
- display: flex;
71
- align-items: center;
72
- justify-content: space-between;
73
- width: 100%;
74
- }
75
-
76
- .link-heading {
77
- color: var(--link-text-color);
73
+ .header-div {
74
+ padding: 20px;
75
+ flex: 1;
78
76
  }
79
77
 
80
78
  .body-div {
81
79
  background-color: var(--body-bg-color);
82
80
  border-bottom: 1px solid var(--body-bottom-border-color);
83
81
  border-top: 1px solid var(--body-top-border-color);
84
- padding: 10px 20px 15px 20px;
82
+ padding: 15px 20px;
85
83
  flex: 1;
86
84
  }
87
85
 
88
86
  .body-text {
89
87
  color: var(--body-text-color);
90
88
  }
91
-
92
- .govuk-heading-m {
93
- /* overwriting margin and line-height to make link centered vertically */
94
- margin: 0;
95
- line-height: 1;
96
- }
97
-
98
- a {
99
- color: #1d70b8;
100
- }
101
89
  </style>
@@ -4,30 +4,44 @@ type Card = {
4
4
  $set?(props: Partial<$$ComponentProps>): void;
5
5
  };
6
6
  declare const Card: import("svelte").Component<{
7
- linkCard?: boolean;
8
- linkText?: any;
9
- linkTextColor?: string;
7
+ headerIsLink?: boolean;
8
+ headerText?: string;
9
+ headerTextSize?: string;
10
+ headerTextColor?: string;
11
+ headerBackgroundColor?: string;
10
12
  href?: any;
11
- callToActionBackgroundColor?: string;
12
- bodyText?: any;
13
+ onlyTextInBody?: boolean;
14
+ bodyText?: string;
15
+ headerSnippet?: any;
16
+ bodySnippet?: any;
17
+ children?: any;
13
18
  bodyTextColor?: string;
14
19
  bodyBackgroundColor?: string;
15
20
  bodyTopBorderColor?: string;
16
21
  bodyBottomBorderColor?: string;
17
22
  selectedValue?: any;
18
- cardSnippet?: any;
23
+ display?: string;
24
+ gridPosition?: any;
25
+ subtitle?: any;
19
26
  }, {}, "selectedValue">;
20
27
  type $$ComponentProps = {
21
- linkCard?: boolean;
22
- linkText?: any;
23
- linkTextColor?: string;
28
+ headerIsLink?: boolean;
29
+ headerText?: string;
30
+ headerTextSize?: string;
31
+ headerTextColor?: string;
32
+ headerBackgroundColor?: string;
24
33
  href?: any;
25
- callToActionBackgroundColor?: string;
26
- bodyText?: any;
34
+ onlyTextInBody?: boolean;
35
+ bodyText?: string;
36
+ headerSnippet?: any;
37
+ bodySnippet?: any;
38
+ children?: any;
27
39
  bodyTextColor?: string;
28
40
  bodyBackgroundColor?: string;
29
41
  bodyTopBorderColor?: string;
30
42
  bodyBottomBorderColor?: string;
31
43
  selectedValue?: any;
32
- cardSnippet?: any;
44
+ display?: string;
45
+ gridPosition?: any;
46
+ subtitle?: any;
33
47
  };
@@ -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
+ };