@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.
- package/README.md +188 -0
- package/dist/assets/css/govuk-frontend.min.css +2 -0
- package/dist/assets/css/govuk-frontend.min.css.map +1 -0
- package/dist/assets/fonts/bold-affa96571d-v2.woff +0 -0
- package/dist/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
- package/dist/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
- package/dist/assets/fonts/light-f591b13f7d-v2.woff +0 -0
- package/dist/assets/govuk_publishing_components/images/icon-autocomplete-search-suggestion.svg +4 -0
- package/dist/assets/govuk_publishing_components/images/icon-close.svg +1 -0
- package/dist/assets/images/favicon.ico +0 -0
- package/dist/assets/images/favicon.svg +1 -0
- package/dist/assets/images/govuk-crest-2x.png +0 -0
- package/dist/assets/images/govuk-crest.png +0 -0
- package/dist/assets/images/govuk-crest.svg +1 -0
- package/dist/assets/images/govuk-icon-180.png +0 -0
- package/dist/assets/images/govuk-icon-192.png +0 -0
- package/dist/assets/images/govuk-icon-512.png +0 -0
- package/dist/assets/images/govuk-icon-mask.svg +1 -0
- package/dist/assets/images/govuk-opengraph-image.png +0 -0
- package/dist/assets/images/homepage-illustration.svg +1 -0
- package/dist/assets/images/homepage.svg +44 -0
- package/dist/assets/images/masthead-illustration.svg +123 -0
- package/dist/assets/images/oflog_crest_black.png +0 -0
- package/dist/assets/images/oflog_crest_white.png +0 -0
- package/dist/assets/images/undraw_approved-wireframe_odf4.svg +1 -0
- package/dist/assets/images/undraw_collaborators_rgw4.svg +1 -0
- package/dist/assets/images/undraw_content-creator_vuqg.svg +1 -0
- package/dist/assets/images/undraw_online-media_opxh.svg +1 -0
- package/dist/assets/images/undraw_pull-request_zlsu.svg +1 -0
- package/dist/assets/images/undraw_reviewed-docs_g0cg.svg +1 -0
- package/dist/components/FilterPanel/codeBlocks.d.ts +3 -0
- package/dist/components/FilterPanel/codeBlocks.js +418 -0
- package/dist/components/content/InsetText.svelte +21 -0
- package/dist/components/content/InsetText.svelte.d.ts +7 -0
- package/dist/components/content/WarningText.svelte +27 -0
- package/dist/components/content/WarningText.svelte.d.ts +8 -0
- package/dist/components/data-vis/axis/Axis.svelte +51 -0
- package/dist/components/data-vis/axis/Axis.svelte.d.ts +33 -0
- package/dist/components/data-vis/axis/Ticks.svelte +113 -0
- package/dist/components/data-vis/axis/Ticks.svelte.d.ts +33 -0
- package/dist/components/data-vis/line-chart/Line.svelte +150 -0
- package/dist/components/data-vis/line-chart/Line.svelte.d.ts +85 -0
- package/dist/components/data-vis/line-chart/LineChart.svelte +249 -0
- package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +73 -0
- package/dist/components/data-vis/line-chart/Lines.svelte +138 -0
- package/dist/components/data-vis/line-chart/Lines.svelte.d.ts +57 -0
- package/dist/components/data-vis/line-chart/Marker.svelte +61 -0
- package/dist/components/data-vis/line-chart/Marker.svelte.d.ts +37 -0
- package/dist/components/data-vis/line-chart/SeriesLabel.svelte +67 -0
- package/dist/components/data-vis/line-chart/SeriesLabel.svelte.d.ts +43 -0
- package/dist/components/data-vis/line-chart/ValueLabel.svelte +50 -0
- package/dist/components/data-vis/line-chart/ValueLabel.svelte.d.ts +25 -0
- package/dist/components/data-vis/map/Map.svelte +392 -0
- package/dist/components/data-vis/map/Map.svelte.d.ts +47 -0
- package/dist/components/data-vis/map/MapLegend.svelte +41 -0
- package/dist/components/data-vis/map/MapLegend.svelte.d.ts +15 -0
- package/dist/components/data-vis/map/NonStandardControls.svelte +42 -0
- package/dist/components/data-vis/map/NonStandardControls.svelte.d.ts +13 -0
- package/dist/components/data-vis/map/Tooltip.svelte +41 -0
- package/dist/components/data-vis/map/Tooltip.svelte.d.ts +19 -0
- package/dist/components/data-vis/map/colorbrewer.d.ts +337 -0
- package/dist/components/data-vis/map/colorbrewer.js +1523 -0
- package/dist/components/data-vis/map/colors.d.ts +13 -0
- package/dist/components/data-vis/map/colors.js +65 -0
- package/dist/components/data-vis/map/dataJoin.d.ts +2 -0
- package/dist/components/data-vis/map/dataJoin.js +27 -0
- package/dist/components/data-vis/map/fullTopo.json +1 -0
- package/dist/components/data-vis/map/jenks.d.ts +1 -0
- package/dist/components/data-vis/map/jenks.js +51 -0
- package/dist/components/data-vis/map/lad2023.json +1 -0
- package/dist/components/data-vis/map/mapUtils.d.ts +5 -0
- package/dist/components/data-vis/map/mapUtils.js +86 -0
- package/dist/components/data-vis/map/topo.json +1 -0
- package/dist/components/data-vis/table/Table.svelte +247 -0
- package/dist/components/data-vis/table/Table.svelte.d.ts +19 -0
- package/dist/components/layout/Breadcrumbs.svelte +191 -0
- package/dist/components/layout/Breadcrumbs.svelte.d.ts +24 -0
- package/dist/components/layout/Footer.svelte +171 -0
- package/dist/components/layout/Footer.svelte.d.ts +30 -0
- package/dist/components/layout/Header.svelte +43 -0
- package/dist/components/layout/Header.svelte.d.ts +7 -0
- package/dist/components/layout/InternalHeader.svelte +628 -0
- package/dist/components/layout/InternalHeader.svelte.d.ts +15 -0
- package/dist/components/layout/PhaseBanner.svelte +28 -0
- package/dist/components/layout/PhaseBanner.svelte.d.ts +9 -0
- package/dist/components/layout/ServiceNavigation.svelte +143 -0
- package/dist/components/layout/ServiceNavigation.svelte.d.ts +13 -0
- package/dist/components/layout/SideNavigation.svelte +345 -0
- package/dist/components/layout/SideNavigation.svelte.d.ts +25 -0
- package/dist/components/layout/service-navigation-nested-mobile/HeaderNav.svelte +91 -0
- package/dist/components/layout/service-navigation-nested-mobile/HeaderNav.svelte.d.ts +15 -0
- package/dist/components/layout/service-navigation-nested-mobile/MobileNav.svelte +233 -0
- package/dist/components/layout/service-navigation-nested-mobile/MobileNav.svelte.d.ts +27 -0
- package/dist/components/layout/service-navigation-nested-mobile/ServiceNavigationNestedMobile.svelte +70 -0
- package/dist/components/layout/service-navigation-nested-mobile/ServiceNavigationNestedMobile.svelte.d.ts +11 -0
- package/dist/components/layout/service-navigation-nested-mobile/SideNav.svelte +276 -0
- package/dist/components/layout/service-navigation-nested-mobile/SideNav.svelte.d.ts +22 -0
- package/dist/components/ui/Accordion.svelte +244 -0
- package/dist/components/ui/Accordion.svelte.d.ts +23 -0
- package/dist/components/ui/Breadcrumbs.svelte +198 -0
- package/dist/components/ui/Breadcrumbs.svelte.d.ts +24 -0
- package/dist/components/ui/Button.svelte +96 -0
- package/dist/components/ui/Button.svelte.d.ts +17 -0
- package/dist/components/ui/CheckBox.svelte +198 -0
- package/dist/components/ui/CheckBox.svelte.d.ts +27 -0
- package/dist/components/ui/ContentsList.svelte +1117 -0
- package/dist/components/ui/ContentsList.svelte.d.ts +25 -0
- package/dist/components/ui/DateInput.svelte +255 -0
- package/dist/components/ui/DateInput.svelte.d.ts +59 -0
- package/dist/components/ui/Details.svelte +12 -0
- package/dist/components/ui/Details.svelte.d.ts +13 -0
- package/dist/components/ui/FilterPanel.svelte +588 -0
- package/dist/components/ui/FilterPanel.svelte.d.ts +74 -0
- package/dist/components/ui/Footer.svelte +171 -0
- package/dist/components/ui/Footer.svelte.d.ts +30 -0
- package/dist/components/ui/Header.svelte +43 -0
- package/dist/components/ui/Header.svelte.d.ts +7 -0
- package/dist/components/ui/Masthead.svelte +267 -0
- package/dist/components/ui/Masthead.svelte.d.ts +12 -0
- package/dist/components/ui/NavigationExample.svelte +117 -0
- package/dist/components/ui/NavigationExample.svelte.d.ts +3 -0
- package/dist/components/ui/NotificationBanner.svelte +93 -0
- package/dist/components/ui/NotificationBanner.svelte.d.ts +15 -0
- package/dist/components/ui/Radios.svelte +176 -0
- package/dist/components/ui/Radios.svelte.d.ts +28 -0
- package/dist/components/ui/RelatedContent.svelte +596 -0
- package/dist/components/ui/RelatedContent.svelte.d.ts +29 -0
- package/dist/components/ui/Search.svelte +499 -0
- package/dist/components/ui/Search.svelte.d.ts +32 -0
- package/dist/components/ui/SearchAutocomplete.svelte +655 -0
- package/dist/components/ui/SearchAutocomplete.svelte.d.ts +37 -0
- package/dist/components/ui/Select.svelte +116 -0
- package/dist/components/ui/Select.svelte.d.ts +22 -0
- package/dist/components/ui/ServiceNavigation.svelte +143 -0
- package/dist/components/ui/ServiceNavigation.svelte.d.ts +13 -0
- package/dist/components/ui/SideNavigation.svelte +346 -0
- package/dist/components/ui/SideNavigation.svelte.d.ts +25 -0
- package/dist/components/ui/Tabs.svelte +306 -0
- package/dist/components/ui/Tabs.svelte.d.ts +18 -0
- package/dist/components/ui/WhatsNew.svelte +155 -0
- package/dist/components/ui/WhatsNew.svelte.d.ts +29 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +44 -0
- package/dist/icons/DoubleChevronButton.svelte +62 -0
- package/dist/icons/DoubleChevronButton.svelte.d.ts +13 -0
- package/dist/icons/IconSearch.svelte +42 -0
- package/dist/icons/IconSearch.svelte.d.ts +6 -0
- package/dist/icons/SingleChevronButtonWithLabel.svelte +132 -0
- package/dist/icons/SingleChevronButtonWithLabel.svelte.d.ts +19 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +45 -0
- package/dist/main.css +1 -0
- package/dist/package-wrapping/BaseInformation.svelte +82 -0
- package/dist/package-wrapping/BaseInformation.svelte.d.ts +15 -0
- package/dist/package-wrapping/BaseNameAndStatus.svelte +108 -0
- package/dist/package-wrapping/BaseNameAndStatus.svelte.d.ts +10 -0
- package/dist/package-wrapping/CodeBlock.svelte +62 -0
- package/dist/package-wrapping/CodeBlock.svelte.d.ts +12 -0
- package/dist/package-wrapping/ComponentDemo.svelte +114 -0
- package/dist/package-wrapping/ComponentDemo.svelte.d.ts +25 -0
- package/dist/package-wrapping/ComponentDemoTEMP.svelte +305 -0
- package/dist/package-wrapping/ComponentDemoTEMP.svelte.d.ts +21 -0
- package/dist/package-wrapping/ComponentDetails.svelte +123 -0
- package/dist/package-wrapping/ComponentDetails.svelte.d.ts +13 -0
- package/dist/package-wrapping/DividerLine.svelte +21 -0
- package/dist/package-wrapping/DividerLine.svelte.d.ts +17 -0
- package/dist/package-wrapping/InputForParameter.svelte +205 -0
- package/dist/package-wrapping/InputForParameter.svelte.d.ts +13 -0
- package/dist/package-wrapping/InputForParameterUpdated.svelte +222 -0
- package/dist/package-wrapping/InputForParameterUpdated.svelte.d.ts +17 -0
- package/dist/package-wrapping/InputForParameterUpdatedTEMP.svelte +203 -0
- package/dist/package-wrapping/InputForParameterUpdatedTEMP.svelte.d.ts +17 -0
- package/dist/package-wrapping/ListOfComponentStatuses.svelte +19 -0
- package/dist/package-wrapping/ListOfComponentStatuses.svelte.d.ts +11 -0
- package/dist/package-wrapping/OverlayAndComponentContainer.svelte +426 -0
- package/dist/package-wrapping/OverlayAndComponentContainer.svelte.d.ts +33 -0
- package/dist/package-wrapping/ParametersSection.svelte +235 -0
- package/dist/package-wrapping/ParametersSection.svelte.d.ts +19 -0
- package/dist/package-wrapping/ParsingErrorToastsContainer.svelte +50 -0
- package/dist/package-wrapping/ParsingErrorToastsContainer.svelte.d.ts +15 -0
- package/dist/package-wrapping/Pill.svelte +54 -0
- package/dist/package-wrapping/Pill.svelte.d.ts +25 -0
- package/dist/package-wrapping/PlaygroundDetails.svelte +106 -0
- package/dist/package-wrapping/PlaygroundDetails.svelte.d.ts +13 -0
- package/dist/package-wrapping/ScreenSizeRadio.svelte +24 -0
- package/dist/package-wrapping/ScreenSizeRadio.svelte.d.ts +11 -0
- package/dist/package-wrapping/ScreenSizeRadioUpdated.svelte +23 -0
- package/dist/package-wrapping/ScreenSizeRadioUpdated.svelte.d.ts +11 -0
- package/dist/package-wrapping/SidebarContainer.svelte +103 -0
- package/dist/package-wrapping/SidebarContainer.svelte.d.ts +23 -0
- package/dist/package-wrapping/WrapperDetailsUpdate.svelte +40 -0
- package/dist/package-wrapping/WrapperDetailsUpdate.svelte.d.ts +15 -0
- package/dist/package-wrapping/templates/Template.svelte +100 -0
- package/dist/package-wrapping/templates/Template.svelte.d.ts +25 -0
- package/dist/templates/ComponentPageTemplate.svelte +1 -0
- package/dist/templates/ComponentPageTemplate.svelte.d.ts +26 -0
- package/dist/utils/data-transformations/convertCSV.d.ts +2 -0
- package/dist/utils/data-transformations/convertCSV.js +22 -0
- package/dist/utils/data-transformations/getValueFromParametersArray.d.ts +1 -0
- package/dist/utils/data-transformations/getValueFromParametersArray.js +9 -0
- package/dist/utils/layoutNavHelpers.d.ts +70 -0
- package/dist/utils/layoutNavHelpers.js +129 -0
- package/dist/utils/package-wrapping-specific/addIndexAndInitialValue.d.ts +1 -0
- package/dist/utils/package-wrapping-specific/addIndexAndInitialValue.js +21 -0
- package/dist/utils/package-wrapping-specific/createBindableParametersValuesArray.d.ts +1 -0
- package/dist/utils/package-wrapping-specific/createBindableParametersValuesArray.js +12 -0
- package/dist/utils/package-wrapping-specific/createParametersObject.d.ts +1 -0
- package/dist/utils/package-wrapping-specific/createParametersObject.js +29 -0
- package/dist/utils/package-wrapping-specific/defineDefaultEventHandler.d.ts +1 -0
- package/dist/utils/package-wrapping-specific/defineDefaultEventHandler.js +14 -0
- package/dist/utils/package-wrapping-specific/trackVisibleParameters.d.ts +1 -0
- package/dist/utils/package-wrapping-specific/trackVisibleParameters.js +29 -0
- package/dist/utils/syntax-highlighting/shikiHighlight.d.ts +7 -0
- package/dist/utils/syntax-highlighting/shikiHighlight.js +76 -0
- package/dist/utils/text-string-conversion/textStringConversion.d.ts +9 -0
- package/dist/utils/text-string-conversion/textStringConversion.js +86 -0
- package/package.json +113 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
import { SvelteSet } from "svelte/reactivity";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
sections = [],
|
|
9
|
+
hideAllSections = "Hide all sections",
|
|
10
|
+
hideSection = "Hide",
|
|
11
|
+
hideSectionAriaLabel = "Hide this section",
|
|
12
|
+
showAllSections = "Show all sections",
|
|
13
|
+
showSection = "Show",
|
|
14
|
+
showSectionAriaLabel = "Show this section",
|
|
15
|
+
allSectionToggle = true,
|
|
16
|
+
minSectionsAllSectionToggle = 2,
|
|
17
|
+
rememberIsExpandedState = true,
|
|
18
|
+
headingLevel = "h4",
|
|
19
|
+
}: {
|
|
20
|
+
sections: {
|
|
21
|
+
heading: string;
|
|
22
|
+
summary?: string;
|
|
23
|
+
content: string | Snippet;
|
|
24
|
+
id: string;
|
|
25
|
+
expanded?: boolean;
|
|
26
|
+
}[];
|
|
27
|
+
hideAllSections?: string;
|
|
28
|
+
hideSection?: string;
|
|
29
|
+
hideSectionAriaLabel?: string;
|
|
30
|
+
showAllSections?: string;
|
|
31
|
+
showSection?: string;
|
|
32
|
+
showSectionAriaLabel?: string;
|
|
33
|
+
allSectionToggle?: boolean;
|
|
34
|
+
minSectionsAllSectionToggle?: number;
|
|
35
|
+
rememberIsExpandedState?: boolean;
|
|
36
|
+
headingLevel?: string;
|
|
37
|
+
} = $props();
|
|
38
|
+
|
|
39
|
+
//Attempt to ensure that ids are unique by attaching extra characters
|
|
40
|
+
let uniqueSections = $derived(
|
|
41
|
+
sections.map((section) => {
|
|
42
|
+
return {
|
|
43
|
+
...section,
|
|
44
|
+
uniqueid:
|
|
45
|
+
section.id +
|
|
46
|
+
section.heading.slice(1, 3) +
|
|
47
|
+
(section?.summary?.slice(0, 2) ?? ""),
|
|
48
|
+
};
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
let expandedSections = $derived(
|
|
53
|
+
new SvelteSet(
|
|
54
|
+
uniqueSections
|
|
55
|
+
.filter((section) => section.expanded)
|
|
56
|
+
.map((section) => section.uniqueid),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
let allExpanded = $derived(expandedSections.size === sections.length);
|
|
61
|
+
|
|
62
|
+
let ariaLiveValue: "polite" | "off" | "assertive" | null | undefined =
|
|
63
|
+
$state("polite");
|
|
64
|
+
|
|
65
|
+
// Event handlers
|
|
66
|
+
|
|
67
|
+
function toggleSection(uniqueid: string) {
|
|
68
|
+
if (expandedSections.has(uniqueid)) {
|
|
69
|
+
expandedSections.delete(uniqueid);
|
|
70
|
+
} else {
|
|
71
|
+
expandedSections.add(uniqueid);
|
|
72
|
+
}
|
|
73
|
+
//Announce the contents change when an accoridion section is expanded
|
|
74
|
+
ariaLiveValue = "polite";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toggleAll() {
|
|
78
|
+
if (!allExpanded) {
|
|
79
|
+
uniqueSections.forEach((section) =>
|
|
80
|
+
expandedSections.add(section.uniqueid),
|
|
81
|
+
);
|
|
82
|
+
} else {
|
|
83
|
+
expandedSections.clear();
|
|
84
|
+
}
|
|
85
|
+
//Don't announce all of the changes when we open all sections - this gets noisy and the content isn't associated with the label
|
|
86
|
+
ariaLiveValue = "off";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Only use session storage logic if rememberIsExpandedState is true
|
|
90
|
+
onMount(() => {
|
|
91
|
+
if (rememberIsExpandedState) {
|
|
92
|
+
uniqueSections.forEach((section) => {
|
|
93
|
+
// If the section is explicitly expanded, respect that.
|
|
94
|
+
// Otherwise, try to restore from session storage.
|
|
95
|
+
if (section.expanded) {
|
|
96
|
+
expandedSections.add(section.uniqueid);
|
|
97
|
+
} else {
|
|
98
|
+
const stored = sessionStorage.getItem(section.uniqueid);
|
|
99
|
+
if (stored === "true") {
|
|
100
|
+
expandedSections.add(section.uniqueid);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
// If rememberIsExpandedState is false, just respect the initial `section.expanded` values
|
|
106
|
+
uniqueSections.forEach((section) => {
|
|
107
|
+
if (section.expanded) {
|
|
108
|
+
expandedSections.add(section.uniqueid);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Effect to update sessionStorage when uniqueSections change
|
|
115
|
+
$effect(() => {
|
|
116
|
+
if (rememberIsExpandedState) {
|
|
117
|
+
uniqueSections.forEach((section) => {
|
|
118
|
+
sessionStorage.setItem(
|
|
119
|
+
section.uniqueid,
|
|
120
|
+
expandedSections.has(section.uniqueid).toString(),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<div
|
|
128
|
+
class="govuk-accordion"
|
|
129
|
+
data-module="govuk-accordion"
|
|
130
|
+
id="accordion-default"
|
|
131
|
+
>
|
|
132
|
+
<div
|
|
133
|
+
class="govuk-accordion__controls"
|
|
134
|
+
hidden={!allSectionToggle ||
|
|
135
|
+
uniqueSections.length < minSectionsAllSectionToggle}
|
|
136
|
+
>
|
|
137
|
+
<button
|
|
138
|
+
type="button"
|
|
139
|
+
class="govuk-accordion__show-all"
|
|
140
|
+
aria-expanded={allExpanded}
|
|
141
|
+
onclick={toggleAll}
|
|
142
|
+
>
|
|
143
|
+
<span class="govuk-accordion__show-all-text">
|
|
144
|
+
{allExpanded ? hideAllSections : showAllSections}
|
|
145
|
+
</span>
|
|
146
|
+
<span
|
|
147
|
+
class="govuk-accordion-nav__chevron"
|
|
148
|
+
class:govuk-accordion-nav__chevron--down={!allExpanded}
|
|
149
|
+
></span>
|
|
150
|
+
</button>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
{#snippet headerContent(section, isExpanded)}
|
|
154
|
+
<button
|
|
155
|
+
type="button"
|
|
156
|
+
aria-controls="{section.uniqueid}-content"
|
|
157
|
+
id="{section.uniqueid}-button"
|
|
158
|
+
class="govuk-accordion__section-button"
|
|
159
|
+
aria-expanded={isExpanded}
|
|
160
|
+
onclick={() => toggleSection(section.uniqueid)}
|
|
161
|
+
aria-label="{section.heading}, {section.summary
|
|
162
|
+
? section.summary + ','
|
|
163
|
+
: ''} {isExpanded ? hideSectionAriaLabel : showSectionAriaLabel}"
|
|
164
|
+
>
|
|
165
|
+
<span class="govuk-accordion__section-heading-text">
|
|
166
|
+
<span class="govuk-accordion__section-heading-text-focus"
|
|
167
|
+
>{section.heading}</span
|
|
168
|
+
>
|
|
169
|
+
</span>
|
|
170
|
+
|
|
171
|
+
{#if section.summary}
|
|
172
|
+
<span
|
|
173
|
+
class="govuk-visually-hidden govuk-accordion__section-heading-divider"
|
|
174
|
+
>,
|
|
175
|
+
</span>
|
|
176
|
+
<span class="govuk-accordion__section-summary govuk-body">
|
|
177
|
+
<span class="govuk-accordion__section-summary-focus"
|
|
178
|
+
>{section.summary}</span
|
|
179
|
+
>
|
|
180
|
+
</span>
|
|
181
|
+
{/if}
|
|
182
|
+
|
|
183
|
+
<span class="govuk-accordion__section-toggle" data-nosnippet>
|
|
184
|
+
<span class="govuk-accordion__section-toggle-focus">
|
|
185
|
+
<span
|
|
186
|
+
class="govuk-accordion-nav__chevron"
|
|
187
|
+
class:govuk-accordion-nav__chevron--down={!isExpanded}
|
|
188
|
+
></span>
|
|
189
|
+
<span class="govuk-accordion__section-toggle-text">
|
|
190
|
+
{isExpanded ? hideSection : showSection}
|
|
191
|
+
</span>
|
|
192
|
+
</span>
|
|
193
|
+
</span>
|
|
194
|
+
</button>
|
|
195
|
+
{/snippet}
|
|
196
|
+
|
|
197
|
+
{#each uniqueSections as section}
|
|
198
|
+
{@const isExpanded = expandedSections.has(section.uniqueid)}
|
|
199
|
+
<div
|
|
200
|
+
class="govuk-accordion__section"
|
|
201
|
+
class:govuk-accordion__section--expanded={isExpanded}
|
|
202
|
+
>
|
|
203
|
+
<div class="govuk-accordion__section-header">
|
|
204
|
+
{#if headingLevel.toLowerCase() == "h2"}
|
|
205
|
+
<h2 class="govuk-accordion__section-heading">
|
|
206
|
+
{@render headerContent(section, isExpanded)}
|
|
207
|
+
</h2>
|
|
208
|
+
{:else if headingLevel.toLowerCase() == "h3"}
|
|
209
|
+
<h3 class="govuk-accordion__section-heading">
|
|
210
|
+
{@render headerContent(section, isExpanded)}
|
|
211
|
+
</h3>
|
|
212
|
+
{:else if headingLevel.toLowerCase() == "h4"}
|
|
213
|
+
<h4 class="govuk-accordion__section-heading">
|
|
214
|
+
{@render headerContent(section, isExpanded)}
|
|
215
|
+
</h4>
|
|
216
|
+
{:else if headingLevel.toLowerCase() == "h5"}
|
|
217
|
+
<h5 class="govuk-accordion__section-heading">
|
|
218
|
+
{@render headerContent(section, isExpanded)}
|
|
219
|
+
</h5>
|
|
220
|
+
{:else if headingLevel.toLowerCase() == "h6"}
|
|
221
|
+
<h6 class="govuk-accordion__section-heading">
|
|
222
|
+
{@render headerContent(section, isExpanded)}
|
|
223
|
+
</h6>
|
|
224
|
+
{/if}
|
|
225
|
+
</div>
|
|
226
|
+
<div
|
|
227
|
+
id="{section.uniqueid}-content"
|
|
228
|
+
class="govuk-accordion__section-content"
|
|
229
|
+
aria-live={ariaLiveValue}
|
|
230
|
+
hidden={!isExpanded}
|
|
231
|
+
role={uniqueSections.length < 6 ? "region" : ""}
|
|
232
|
+
aria-labelledby={uniqueSections.length < 6
|
|
233
|
+
? section.uniqueid + "-button"
|
|
234
|
+
: ""}
|
|
235
|
+
>
|
|
236
|
+
{#if typeof section.content === "string"}
|
|
237
|
+
<p class="govuk-body">{section.content}</p>
|
|
238
|
+
{:else}
|
|
239
|
+
{@render section.content()}
|
|
240
|
+
{/if}
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
{/each}
|
|
244
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
sections: {
|
|
4
|
+
heading: string;
|
|
5
|
+
summary?: string;
|
|
6
|
+
content: string | Snippet;
|
|
7
|
+
id: string;
|
|
8
|
+
expanded?: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
hideAllSections?: string;
|
|
11
|
+
hideSection?: string;
|
|
12
|
+
hideSectionAriaLabel?: string;
|
|
13
|
+
showAllSections?: string;
|
|
14
|
+
showSection?: string;
|
|
15
|
+
showSectionAriaLabel?: string;
|
|
16
|
+
allSectionToggle?: boolean;
|
|
17
|
+
minSectionsAllSectionToggle?: number;
|
|
18
|
+
rememberIsExpandedState?: boolean;
|
|
19
|
+
headingLevel?: string;
|
|
20
|
+
};
|
|
21
|
+
declare const Accordion: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
22
|
+
type Accordion = ReturnType<typeof Accordion>;
|
|
23
|
+
export default Accordion;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { page } from "$app/stores";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Breadcrumbs component
|
|
7
|
+
*
|
|
8
|
+
* Use this component to display a navigation path to the current page.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Automatically generates breadcrumbs based on the current route
|
|
12
|
+
* - Set `collapseOnMobile` to true to show only the first and last items on mobile devices
|
|
13
|
+
* - Set `inverse` to true to show white links on dark backgrounds (ensure contrast ratio of 4.5:1)
|
|
14
|
+
* - Optionally provide custom items array to override automatic breadcrumb generation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Define the BreadcrumbItem type
|
|
18
|
+
export type BreadcrumbItem = {
|
|
19
|
+
text: string;
|
|
20
|
+
href: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Component props
|
|
24
|
+
let {
|
|
25
|
+
items = undefined,
|
|
26
|
+
collapseOnMobile = false,
|
|
27
|
+
inverse = false,
|
|
28
|
+
ariaLabel = "Breadcrumb",
|
|
29
|
+
} = $props<{
|
|
30
|
+
items?: BreadcrumbItem[];
|
|
31
|
+
collapseOnMobile?: boolean;
|
|
32
|
+
inverse?: boolean;
|
|
33
|
+
ariaLabel?: string;
|
|
34
|
+
}>();
|
|
35
|
+
|
|
36
|
+
// Load all page modules for route detection
|
|
37
|
+
const routeModules = $state<Record<string, any>>({});
|
|
38
|
+
|
|
39
|
+
onMount(async () => {
|
|
40
|
+
try {
|
|
41
|
+
// Use Vite's glob import to get all page components
|
|
42
|
+
const modules = import.meta.glob("/src/routes/**/+page.svelte", {
|
|
43
|
+
eager: true,
|
|
44
|
+
});
|
|
45
|
+
Object.assign(routeModules, modules);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.warn("Failed to load route modules:", error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Add support detection
|
|
52
|
+
let isSupported = $state(false);
|
|
53
|
+
onMount(() => {
|
|
54
|
+
isSupported =
|
|
55
|
+
document.body?.classList.contains("govuk-frontend-supported") ?? false;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// State variable to hold the current breadcrumb items
|
|
59
|
+
let breadcrumbItems = $state<BreadcrumbItem[]>([]);
|
|
60
|
+
|
|
61
|
+
// Effect to update breadcrumb items when dependencies change
|
|
62
|
+
$effect(() => {
|
|
63
|
+
breadcrumbItems = items || generateBreadcrumbItems($page, routeModules);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Generate breadcrumb items from the current route
|
|
67
|
+
function generateBreadcrumbItems(page, modules): BreadcrumbItem[] {
|
|
68
|
+
const path = page.url.pathname;
|
|
69
|
+
const pathSegments = path.split("/").filter((segment) => segment !== "");
|
|
70
|
+
|
|
71
|
+
// Always include home page
|
|
72
|
+
const items: BreadcrumbItem[] = [{ text: "Home", href: "/" }];
|
|
73
|
+
|
|
74
|
+
// Build up paths for each breadcrumb
|
|
75
|
+
let currentPath = "";
|
|
76
|
+
|
|
77
|
+
for (let i = 0; i < pathSegments.length; i++) {
|
|
78
|
+
currentPath += `/${pathSegments[i]}`;
|
|
79
|
+
|
|
80
|
+
// Check if this path has a corresponding +page.svelte file
|
|
81
|
+
const isValidRoute = isPathValid(currentPath, modules);
|
|
82
|
+
|
|
83
|
+
// Add breadcrumb if it's a valid route or the current page
|
|
84
|
+
if (isValidRoute || i === pathSegments.length - 1) {
|
|
85
|
+
// Try to get custom title from module exports
|
|
86
|
+
const customTitle = getCustomTitle(currentPath, modules, page.data);
|
|
87
|
+
|
|
88
|
+
// Format text (convert slug to readable text)
|
|
89
|
+
const text = customTitle || formatBreadcrumbText(pathSegments[i]);
|
|
90
|
+
|
|
91
|
+
items.push({
|
|
92
|
+
text: text,
|
|
93
|
+
href: currentPath,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return items;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Check if a path has a corresponding page component
|
|
102
|
+
function isPathValid(path: string, modules: Record<string, any>): boolean {
|
|
103
|
+
// For the root path
|
|
104
|
+
if (path === "/") return true;
|
|
105
|
+
|
|
106
|
+
// Normalize the path to check against module paths
|
|
107
|
+
const modulePath = `/src/routes${path}/+page.svelte`;
|
|
108
|
+
const dynamicModulePaths = Object.keys(modules).filter((m) => {
|
|
109
|
+
// Convert dynamic route patterns like [id] to regex pattern that matches :id or actual values
|
|
110
|
+
const pattern = m.replace(/\[([^\]]+)\]/g, "([^/]+)");
|
|
111
|
+
const regex = new RegExp(
|
|
112
|
+
`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`,
|
|
113
|
+
);
|
|
114
|
+
return regex.test(modulePath);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return dynamicModulePaths.length > 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Try to get custom title from module exports
|
|
121
|
+
function getCustomTitle(
|
|
122
|
+
path: string,
|
|
123
|
+
modules: Record<string, any>,
|
|
124
|
+
pageData: any,
|
|
125
|
+
): string | null {
|
|
126
|
+
const modulePath = `/src/routes${path}/+page.svelte`;
|
|
127
|
+
|
|
128
|
+
// Check for exact match first
|
|
129
|
+
if (modules[modulePath]) {
|
|
130
|
+
// Check if module exports pageTitle
|
|
131
|
+
if (modules[modulePath].pageTitle) {
|
|
132
|
+
return modules[modulePath].pageTitle;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Check if module exports getPageTitle function
|
|
136
|
+
if (typeof modules[modulePath].getPageTitle === "function") {
|
|
137
|
+
return modules[modulePath].getPageTitle(pageData);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Check for dynamic routes
|
|
142
|
+
const dynamicModulePath = Object.keys(modules).find((m) => {
|
|
143
|
+
const pattern = m.replace(/\[([^\]]+)\]/g, "([^/]+)");
|
|
144
|
+
const regex = new RegExp(
|
|
145
|
+
`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`,
|
|
146
|
+
);
|
|
147
|
+
return regex.test(modulePath);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (dynamicModulePath && modules[dynamicModulePath]) {
|
|
151
|
+
if (modules[dynamicModulePath].pageTitle) {
|
|
152
|
+
return modules[dynamicModulePath].pageTitle;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (typeof modules[dynamicModulePath].getPageTitle === "function") {
|
|
156
|
+
return modules[dynamicModulePath].getPageTitle(pageData);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Converts route segments to human-readable text
|
|
165
|
+
*/
|
|
166
|
+
function formatBreadcrumbText(text: string): string {
|
|
167
|
+
// Handle special cases
|
|
168
|
+
if (text === "ui") return "UI Components";
|
|
169
|
+
if (text === "data-vis") return "Data Visualization";
|
|
170
|
+
if (text === "content") return "Content Components";
|
|
171
|
+
if (text === "layout") return "Layout Components";
|
|
172
|
+
if (text === "user-guide") return "User Guide";
|
|
173
|
+
if (text === "playground") return "Playground";
|
|
174
|
+
if (text === "components") return "Components";
|
|
175
|
+
if (text === "local-lib") return "Local Library";
|
|
176
|
+
|
|
177
|
+
// Default: capitalize and replace hyphens with spaces
|
|
178
|
+
return text
|
|
179
|
+
.split("-")
|
|
180
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
181
|
+
.join(" ");
|
|
182
|
+
}
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<nav
|
|
186
|
+
class="govuk-breadcrumbs
|
|
187
|
+
{collapseOnMobile ? 'govuk-breadcrumbs--collapse-on-mobile' : ''}
|
|
188
|
+
{inverse ? 'govuk-breadcrumbs--inverse' : ''}"
|
|
189
|
+
aria-label={ariaLabel}
|
|
190
|
+
>
|
|
191
|
+
<ol class="govuk-breadcrumbs__list">
|
|
192
|
+
{#each breadcrumbItems as item}
|
|
193
|
+
<li class="govuk-breadcrumbs__list-item">
|
|
194
|
+
<a class="govuk-breadcrumbs__link" href={item.href}>{item.text}</a>
|
|
195
|
+
</li>
|
|
196
|
+
{/each}
|
|
197
|
+
</ol>
|
|
198
|
+
</nav>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Breadcrumbs component
|
|
3
|
+
*
|
|
4
|
+
* Use this component to display a navigation path to the current page.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Automatically generates breadcrumbs based on the current route
|
|
8
|
+
* - Set `collapseOnMobile` to true to show only the first and last items on mobile devices
|
|
9
|
+
* - Set `inverse` to true to show white links on dark backgrounds (ensure contrast ratio of 4.5:1)
|
|
10
|
+
* - Optionally provide custom items array to override automatic breadcrumb generation
|
|
11
|
+
*/
|
|
12
|
+
export type BreadcrumbItem = {
|
|
13
|
+
text: string;
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
type $$ComponentProps = {
|
|
17
|
+
items?: BreadcrumbItem[];
|
|
18
|
+
collapseOnMobile?: boolean;
|
|
19
|
+
inverse?: boolean;
|
|
20
|
+
ariaLabel?: string;
|
|
21
|
+
};
|
|
22
|
+
declare const Breadcrumbs: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
23
|
+
type Breadcrumbs = ReturnType<typeof Breadcrumbs>;
|
|
24
|
+
export default Breadcrumbs;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
let {
|
|
3
|
+
textContent = undefined,
|
|
4
|
+
buttonType,
|
|
5
|
+
componentNameProp = undefined,
|
|
6
|
+
onClickFunction = undefined,
|
|
7
|
+
} = $props();
|
|
8
|
+
|
|
9
|
+
let buttonClass = $derived(
|
|
10
|
+
buttonType === "default"
|
|
11
|
+
? "govuk-button"
|
|
12
|
+
: buttonType === "secondary"
|
|
13
|
+
? "govuk-button govuk-button--secondary"
|
|
14
|
+
: buttonType === "warning"
|
|
15
|
+
? "govuk-button govuk-button--warning"
|
|
16
|
+
: buttonType === "dark background"
|
|
17
|
+
? "govuk-button govuk-button--inverse"
|
|
18
|
+
: undefined,
|
|
19
|
+
);
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<div class="p-4">
|
|
23
|
+
{#if buttonType === "start"}
|
|
24
|
+
<a
|
|
25
|
+
href="#"
|
|
26
|
+
role="button"
|
|
27
|
+
draggable="false"
|
|
28
|
+
class="govuk-button govuk-button--start"
|
|
29
|
+
data-module="govuk-button"
|
|
30
|
+
onclick={onClickFunction}
|
|
31
|
+
>
|
|
32
|
+
{textContent}
|
|
33
|
+
<svg
|
|
34
|
+
class="govuk-button__start-icon"
|
|
35
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
36
|
+
width="17.5"
|
|
37
|
+
height="19"
|
|
38
|
+
viewBox="0 0 33 40"
|
|
39
|
+
aria-hidden="true"
|
|
40
|
+
focusable="false"
|
|
41
|
+
>
|
|
42
|
+
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
|
|
43
|
+
</svg>
|
|
44
|
+
</a>
|
|
45
|
+
{:else if buttonType === "disabled"}
|
|
46
|
+
<button
|
|
47
|
+
type="submit"
|
|
48
|
+
disabled
|
|
49
|
+
aria-disabled="true"
|
|
50
|
+
class="govuk-button"
|
|
51
|
+
data-module="govuk-button"
|
|
52
|
+
onclick={onClickFunction}
|
|
53
|
+
>
|
|
54
|
+
{textContent}
|
|
55
|
+
</button>
|
|
56
|
+
{:else if buttonType === "table header"}
|
|
57
|
+
<button type="button" class="text-header" onclick={onClickFunction}>
|
|
58
|
+
{textContent}
|
|
59
|
+
<svg
|
|
60
|
+
width="22"
|
|
61
|
+
height="22"
|
|
62
|
+
focusable="false"
|
|
63
|
+
aria-hidden="true"
|
|
64
|
+
role="img"
|
|
65
|
+
viewBox="0 0 22 22"
|
|
66
|
+
fill="none"
|
|
67
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
68
|
+
>
|
|
69
|
+
<path
|
|
70
|
+
d="M8.1875 9.5L10.9609 3.95703L13.7344 9.5H8.1875Z"
|
|
71
|
+
fill="currentColor"
|
|
72
|
+
></path>
|
|
73
|
+
<path
|
|
74
|
+
d="M13.7344 12.0781L10.9609 17.6211L8.1875 12.0781H13.7344Z"
|
|
75
|
+
fill="currentColor"
|
|
76
|
+
></path>
|
|
77
|
+
</svg>
|
|
78
|
+
</button>
|
|
79
|
+
{:else}
|
|
80
|
+
<button
|
|
81
|
+
type="submit"
|
|
82
|
+
class={buttonClass}
|
|
83
|
+
data-module="govuk-button"
|
|
84
|
+
onclick={onClickFunction}
|
|
85
|
+
>
|
|
86
|
+
{textContent}
|
|
87
|
+
</button>
|
|
88
|
+
{/if}
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
<style>
|
|
92
|
+
.text-header {
|
|
93
|
+
display: flex;
|
|
94
|
+
color: #005ea5;
|
|
95
|
+
}
|
|
96
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default Button;
|
|
2
|
+
type Button = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Button: import("svelte").Component<{
|
|
7
|
+
textContent?: any;
|
|
8
|
+
buttonType: any;
|
|
9
|
+
componentNameProp?: any;
|
|
10
|
+
onClickFunction?: any;
|
|
11
|
+
}, {}, "">;
|
|
12
|
+
type $$ComponentProps = {
|
|
13
|
+
textContent?: any;
|
|
14
|
+
buttonType: any;
|
|
15
|
+
componentNameProp?: any;
|
|
16
|
+
onClickFunction?: any;
|
|
17
|
+
};
|