@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,25 @@
|
|
|
1
|
+
export type ContentItem = {
|
|
2
|
+
href?: string;
|
|
3
|
+
text: string;
|
|
4
|
+
active?: boolean;
|
|
5
|
+
items?: ContentItem[];
|
|
6
|
+
};
|
|
7
|
+
type Props = {
|
|
8
|
+
contents: ContentItem[];
|
|
9
|
+
title?: string;
|
|
10
|
+
marginBottom?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
11
|
+
underlineLinks?: boolean;
|
|
12
|
+
formatNumbers?: boolean;
|
|
13
|
+
alternativeLineStyle?: boolean;
|
|
14
|
+
disableGa4?: boolean;
|
|
15
|
+
brand?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
classes?: string;
|
|
18
|
+
dataAttributes?: Record<string, string>;
|
|
19
|
+
aria?: Record<string, string>;
|
|
20
|
+
dir?: "rtl" | "ltr" | "auto" | "";
|
|
21
|
+
lang?: string;
|
|
22
|
+
};
|
|
23
|
+
declare const ContentsList: import("svelte").Component<Props, {}, "">;
|
|
24
|
+
type ContentsList = ReturnType<typeof ContentsList>;
|
|
25
|
+
export default ContentsList;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
4
|
+
|
|
5
|
+
interface FieldsetLegend {
|
|
6
|
+
text?: string;
|
|
7
|
+
isPageHeading?: boolean;
|
|
8
|
+
classes?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Fieldset {
|
|
12
|
+
legend?: FieldsetLegend;
|
|
13
|
+
role?: string;
|
|
14
|
+
describedBy?: string; // Will be automatically generated if not provided
|
|
15
|
+
classes?: string;
|
|
16
|
+
attributes?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Hint {
|
|
20
|
+
text?: string;
|
|
21
|
+
id?: string; // Will be automatically generated if not provided
|
|
22
|
+
classes?: string;
|
|
23
|
+
attributes?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface DateInputItem extends Omit<HTMLInputAttributes, "value"> {
|
|
27
|
+
id?: string; // Will be automatically generated if not provided
|
|
28
|
+
name: string; // e.g., 'day', 'month', 'year'
|
|
29
|
+
label?: string;
|
|
30
|
+
value?: string | number | undefined; // Make value optional
|
|
31
|
+
classes?: string; // Classes for the input element itself
|
|
32
|
+
itemClasses?: string; // Classes for the govuk-date-input__item container
|
|
33
|
+
inputmode?: HTMLInputAttributes["inputmode"]; // Use stricter type
|
|
34
|
+
autocomplete?: HTMLInputAttributes["autocomplete"]; // Use stricter type
|
|
35
|
+
pattern?: string; // e.g., '[0-9]*'
|
|
36
|
+
attributes?: Record<string, unknown>; // Attributes for the input element
|
|
37
|
+
hasError?: boolean; // Flag to indicate if this specific input has an error
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface FormGroup {
|
|
41
|
+
classes?: string;
|
|
42
|
+
attributes?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --- Component Props ---
|
|
46
|
+
let {
|
|
47
|
+
id, // Required: Base ID for the component and its parts
|
|
48
|
+
namePrefix = "", // Optional prefix for input names
|
|
49
|
+
items = [], // Required: Array for day, month, year inputs
|
|
50
|
+
fieldset = {} as Fieldset,
|
|
51
|
+
hint = {} as Hint,
|
|
52
|
+
errorMessage = undefined as string | undefined | null, // Changed type to string | undefined | null
|
|
53
|
+
formGroup = {} as FormGroup,
|
|
54
|
+
classes = "", // Classes for the main govuk-date-input container
|
|
55
|
+
attributes = {} as Record<string, unknown>,
|
|
56
|
+
legendSize, // Destructure without default
|
|
57
|
+
dayValue = $bindable<string | number | undefined>(undefined),
|
|
58
|
+
monthValue = $bindable<string | number | undefined>(undefined),
|
|
59
|
+
yearValue = $bindable<string | number | undefined>(undefined),
|
|
60
|
+
// Client-side validation function
|
|
61
|
+
validate = undefined as
|
|
62
|
+
| ((values: {
|
|
63
|
+
day?: string | number | undefined;
|
|
64
|
+
month?: string | number | undefined;
|
|
65
|
+
year?: string | number | undefined;
|
|
66
|
+
}) => string | undefined)
|
|
67
|
+
| undefined,
|
|
68
|
+
}: {
|
|
69
|
+
id: string;
|
|
70
|
+
namePrefix?: string;
|
|
71
|
+
items: DateInputItem[];
|
|
72
|
+
fieldset?: Fieldset;
|
|
73
|
+
hint?: Hint;
|
|
74
|
+
errorMessage?: string | undefined | null; // Changed type here as well
|
|
75
|
+
formGroup?: FormGroup;
|
|
76
|
+
classes?: string;
|
|
77
|
+
attributes?: Record<string, unknown>;
|
|
78
|
+
legendSize?: "l" | "m" | "s" | undefined; // Type is optional
|
|
79
|
+
dayValue?: string | number | undefined;
|
|
80
|
+
monthValue?: string | number | undefined;
|
|
81
|
+
yearValue?: string | number | undefined;
|
|
82
|
+
validate?: (values: {
|
|
83
|
+
day?: string | number | undefined;
|
|
84
|
+
month?: string | number | undefined;
|
|
85
|
+
year?: string | number | undefined;
|
|
86
|
+
}) => string | undefined; // Added validate prop type
|
|
87
|
+
} = $props();
|
|
88
|
+
|
|
89
|
+
// console.log(`DateInput (${id}): received legendSize =`, legendSize); // Remove console.log
|
|
90
|
+
|
|
91
|
+
// --- Derived State ---
|
|
92
|
+
// Server/manual error check
|
|
93
|
+
let serverErrorPresent = $derived(
|
|
94
|
+
typeof errorMessage === "string" && errorMessage.trim() !== "",
|
|
95
|
+
);
|
|
96
|
+
// Client-side validation
|
|
97
|
+
let validationError = $derived(
|
|
98
|
+
validate
|
|
99
|
+
? validate({ day: dayValue, month: monthValue, year: yearValue })
|
|
100
|
+
: undefined,
|
|
101
|
+
);
|
|
102
|
+
// Combined error state
|
|
103
|
+
let hasAnyError = $derived(!!validationError || serverErrorPresent);
|
|
104
|
+
let displayedError = $derived(validationError ?? errorMessage); // Prioritize client error
|
|
105
|
+
|
|
106
|
+
// Use optional chaining and nullish coalescing (??)
|
|
107
|
+
let hintId = $derived(hint?.id ?? (hint?.text ? `${id}-hint` : undefined));
|
|
108
|
+
// Update errorId derivation based on combined state
|
|
109
|
+
let errorId = $derived(hasAnyError ? `${id}-error` : undefined);
|
|
110
|
+
|
|
111
|
+
// Use optional chaining
|
|
112
|
+
let describedBy = $derived(
|
|
113
|
+
fieldset?.describedBy ?? // Check fieldset first
|
|
114
|
+
([hintId, errorId].filter(Boolean).join(" ") || undefined),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
function getItemName(item: DateInputItem): string {
|
|
118
|
+
return namePrefix ? `${namePrefix}[${item.name}]` : item.name;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getItemId(item: DateInputItem): string {
|
|
122
|
+
return item?.id || `${id}-${item.name}`;
|
|
123
|
+
}
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<div
|
|
127
|
+
class="govuk-form-group {formGroup?.classes ?? ''} {hasAnyError
|
|
128
|
+
? 'govuk-form-group--error'
|
|
129
|
+
: ''}"
|
|
130
|
+
{...formGroup?.attributes}
|
|
131
|
+
>
|
|
132
|
+
<fieldset
|
|
133
|
+
class="govuk-fieldset {fieldset?.classes ?? ''}"
|
|
134
|
+
role={fieldset?.role ?? "group"}
|
|
135
|
+
aria-describedby={describedBy}
|
|
136
|
+
{...fieldset?.attributes}
|
|
137
|
+
>
|
|
138
|
+
{#if fieldset?.legend}
|
|
139
|
+
<legend
|
|
140
|
+
class="govuk-fieldset__legend {fieldset.legend.classes ??
|
|
141
|
+
''} {legendSize ? `govuk-fieldset__legend--${legendSize}` : ''}"
|
|
142
|
+
>
|
|
143
|
+
{#if fieldset.legend.isPageHeading}
|
|
144
|
+
<h1 class="govuk-fieldset__heading">
|
|
145
|
+
{fieldset.legend.text}
|
|
146
|
+
</h1>
|
|
147
|
+
{:else}
|
|
148
|
+
{fieldset.legend.text}
|
|
149
|
+
{/if}
|
|
150
|
+
</legend>
|
|
151
|
+
{/if}
|
|
152
|
+
|
|
153
|
+
{#if hint?.text}
|
|
154
|
+
<div
|
|
155
|
+
id={hintId}
|
|
156
|
+
class="govuk-hint {hint.classes ?? ''}"
|
|
157
|
+
{...hint.attributes}
|
|
158
|
+
>
|
|
159
|
+
{hint.text}
|
|
160
|
+
</div>
|
|
161
|
+
{/if}
|
|
162
|
+
|
|
163
|
+
{#if hasAnyError}
|
|
164
|
+
<p id={errorId} class="govuk-error-message">
|
|
165
|
+
<span class="govuk-visually-hidden">Error:</span>
|
|
166
|
+
{displayedError}
|
|
167
|
+
</p>
|
|
168
|
+
{/if}
|
|
169
|
+
|
|
170
|
+
<div class="govuk-date-input {classes}" {id} {...attributes}>
|
|
171
|
+
{#each items as item (item.name)}
|
|
172
|
+
{@const inputId = getItemId(item)}
|
|
173
|
+
{@const inputName = getItemName(item)}
|
|
174
|
+
|
|
175
|
+
{@const handleInput = (event: Event) => {
|
|
176
|
+
const target = event.target as HTMLInputElement;
|
|
177
|
+
const newValue = target.value;
|
|
178
|
+
if (item.name === "day") {
|
|
179
|
+
dayValue = newValue;
|
|
180
|
+
} else if (item.name === "month") {
|
|
181
|
+
monthValue = newValue;
|
|
182
|
+
} else if (item.name === "year") {
|
|
183
|
+
yearValue = newValue;
|
|
184
|
+
}
|
|
185
|
+
}}
|
|
186
|
+
|
|
187
|
+
{@const getCurrentValue = () => {
|
|
188
|
+
switch (item.name) {
|
|
189
|
+
case "day":
|
|
190
|
+
return dayValue;
|
|
191
|
+
case "month":
|
|
192
|
+
return monthValue;
|
|
193
|
+
case "year":
|
|
194
|
+
return yearValue;
|
|
195
|
+
default:
|
|
196
|
+
return item.value; // Fallback to item.value if provided and no bindable prop matches
|
|
197
|
+
}
|
|
198
|
+
}}
|
|
199
|
+
|
|
200
|
+
{@const inputClasses = (() => {
|
|
201
|
+
let classList = ["govuk-input", "govuk-date-input__input"];
|
|
202
|
+
const providedClasses = item.classes || "";
|
|
203
|
+
|
|
204
|
+
// Check if a specific width is provided via item.classes
|
|
205
|
+
if (!providedClasses.includes("govuk-input--width-")) {
|
|
206
|
+
// Apply default width if none is provided
|
|
207
|
+
if (item.name === "year") {
|
|
208
|
+
classList.push("govuk-input--width-4");
|
|
209
|
+
} else if (item.name === "day" || item.name === "month") {
|
|
210
|
+
classList.push("govuk-input--width-2");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Add provided classes (they might override defaults or add others)
|
|
215
|
+
if (providedClasses) {
|
|
216
|
+
classList.push(providedClasses);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Add error class conditionally (based on server error + item flag)
|
|
220
|
+
if (serverErrorPresent && item.hasError) {
|
|
221
|
+
classList.push("govuk-input--error");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Join classes, removing potential duplicate spaces
|
|
225
|
+
return classList.join(" ").trim().replace(/\s+/g, " ");
|
|
226
|
+
})()}
|
|
227
|
+
|
|
228
|
+
<div class="govuk-date-input__item {item.itemClasses || ''}">
|
|
229
|
+
<div class="govuk-form-group">
|
|
230
|
+
<label class="govuk-label govuk-date-input__label" for={inputId}>
|
|
231
|
+
{item.label ||
|
|
232
|
+
item.name.charAt(0).toUpperCase() + item.name.slice(1)}
|
|
233
|
+
</label>
|
|
234
|
+
<input
|
|
235
|
+
class={inputClasses}
|
|
236
|
+
id={inputId}
|
|
237
|
+
name={inputName}
|
|
238
|
+
type={item.type || "text"}
|
|
239
|
+
value={getCurrentValue()}
|
|
240
|
+
oninput={handleInput}
|
|
241
|
+
inputmode={item.inputmode || "numeric"}
|
|
242
|
+
autocomplete={item.autocomplete}
|
|
243
|
+
pattern={item.pattern || "[0-9]*"}
|
|
244
|
+
{...item.attributes}
|
|
245
|
+
aria-describedby={hasAnyError ? errorId : undefined}
|
|
246
|
+
/>
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
{/each}
|
|
250
|
+
</div>
|
|
251
|
+
</fieldset>
|
|
252
|
+
</div>
|
|
253
|
+
|
|
254
|
+
<style>
|
|
255
|
+
</style>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
2
|
+
interface FieldsetLegend {
|
|
3
|
+
text?: string;
|
|
4
|
+
isPageHeading?: boolean;
|
|
5
|
+
classes?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Fieldset {
|
|
8
|
+
legend?: FieldsetLegend;
|
|
9
|
+
role?: string;
|
|
10
|
+
describedBy?: string;
|
|
11
|
+
classes?: string;
|
|
12
|
+
attributes?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
interface Hint {
|
|
15
|
+
text?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
classes?: string;
|
|
18
|
+
attributes?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
interface DateInputItem extends Omit<HTMLInputAttributes, "value"> {
|
|
21
|
+
id?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
value?: string | number | undefined;
|
|
25
|
+
classes?: string;
|
|
26
|
+
itemClasses?: string;
|
|
27
|
+
inputmode?: HTMLInputAttributes["inputmode"];
|
|
28
|
+
autocomplete?: HTMLInputAttributes["autocomplete"];
|
|
29
|
+
pattern?: string;
|
|
30
|
+
attributes?: Record<string, unknown>;
|
|
31
|
+
hasError?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface FormGroup {
|
|
34
|
+
classes?: string;
|
|
35
|
+
attributes?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
type $$ComponentProps = {
|
|
38
|
+
id: string;
|
|
39
|
+
namePrefix?: string;
|
|
40
|
+
items: DateInputItem[];
|
|
41
|
+
fieldset?: Fieldset;
|
|
42
|
+
hint?: Hint;
|
|
43
|
+
errorMessage?: string | undefined | null;
|
|
44
|
+
formGroup?: FormGroup;
|
|
45
|
+
classes?: string;
|
|
46
|
+
attributes?: Record<string, unknown>;
|
|
47
|
+
legendSize?: "l" | "m" | "s" | undefined;
|
|
48
|
+
dayValue?: string | number | undefined;
|
|
49
|
+
monthValue?: string | number | undefined;
|
|
50
|
+
yearValue?: string | number | undefined;
|
|
51
|
+
validate?: (values: {
|
|
52
|
+
day?: string | number | undefined;
|
|
53
|
+
month?: string | number | undefined;
|
|
54
|
+
year?: string | number | undefined;
|
|
55
|
+
}) => string | undefined;
|
|
56
|
+
};
|
|
57
|
+
declare const DateInput: import("svelte").Component<$$ComponentProps, {}, "dayValue" | "monthValue" | "yearValue">;
|
|
58
|
+
type DateInput = ReturnType<typeof DateInput>;
|
|
59
|
+
export default DateInput;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
let { summaryText, detailedText } = $props();
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<details class="govuk-details">
|
|
6
|
+
<summary class="govuk-details__summary">
|
|
7
|
+
<span class="govuk-details__summary-text">{summaryText}</span>
|
|
8
|
+
</summary>
|
|
9
|
+
<div class="govuk-details__text">
|
|
10
|
+
{detailedText}
|
|
11
|
+
</div>
|
|
12
|
+
</details>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default Details;
|
|
2
|
+
type Details = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Details: import("svelte").Component<{
|
|
7
|
+
summaryText: any;
|
|
8
|
+
detailedText: any;
|
|
9
|
+
}, {}, "">;
|
|
10
|
+
type $$ComponentProps = {
|
|
11
|
+
summaryText: any;
|
|
12
|
+
detailedText: any;
|
|
13
|
+
};
|