@scottish-government/designsystem-react 0.12.1 → 0.13.0
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/.storybook/main.ts +6 -6
- package/.storybook/sgdsArgTypes.ts +84 -43
- package/CHANGELOG.md +26 -0
- package/eslint.config.mjs +32 -0
- package/package.json +8 -3
- package/src/common/AbstractNotificationBanner/AbstractNotificationBanner.tsx +5 -4
- package/src/common/AbstractNotificationBanner/types.ts +15 -0
- package/src/common/ActionLink/ActionLink.tsx +3 -1
- package/src/common/ActionLink/types.ts +8 -0
- package/src/common/ConditionalWrapper/ConditionalWrapper.tsx +10 -2
- package/src/common/ConditionalWrapper/types.ts +4 -0
- package/src/common/FileIcon/FileIcon.tsx +2 -1
- package/src/common/FileIcon/types.ts +7 -0
- package/src/common/HintText/HintText.test.tsx +3 -15
- package/src/common/HintText/HintText.tsx +4 -4
- package/src/common/HintText/types.ts +4 -0
- package/src/common/Icon/Icon.tsx +2 -1
- package/src/common/Icon/types.ts +9 -0
- package/src/common/ScreenReaderText/ScreenReaderText.tsx +1 -1
- package/src/common/WrapperTag/WrapperTag.tsx +5 -3
- package/src/common/WrapperTag/types.ts +3 -0
- package/src/components/Accordion/Accordion.Item.stories.tsx +1 -5
- package/src/components/Accordion/Accordion.stories.tsx +5 -5
- package/src/components/Accordion/Accordion.tsx +5 -4
- package/src/components/Accordion/types.ts +13 -0
- package/src/components/AspectBox/AspectBox.stories.tsx +1 -2
- package/src/components/AspectBox/AspectBox.tsx +5 -4
- package/src/components/AspectBox/types.ts +3 -0
- package/src/components/BackToTop/BackToTop.tsx +3 -2
- package/src/components/BackToTop/types.ts +3 -0
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +4 -2
- package/src/components/Breadcrumbs/types.ts +6 -0
- package/src/components/Button/Button.tsx +2 -1
- package/src/components/Button/ButtonGroup.tsx +3 -1
- package/src/components/Button/types.ts +21 -0
- package/src/components/CategoryItem/CategoryItem.tsx +7 -4
- package/src/components/CategoryItem/types.ts +10 -0
- package/src/components/CategoryList/CategoryList.tsx +4 -2
- package/src/components/CategoryList/types.ts +5 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +3 -3
- package/src/components/Checkbox/Checkbox.tsx +5 -4
- package/src/components/Checkbox/CheckboxGroup.tsx +3 -3
- package/src/components/Checkbox/types.ts +9 -0
- package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +2 -1
- package/src/components/ConfirmationMessage/types.ts +7 -0
- package/src/components/ContentsNav/ContentsNav.stories.tsx +5 -1
- package/src/components/ContentsNav/ContentsNav.tsx +3 -2
- package/src/components/ContentsNav/types.ts +11 -0
- package/src/components/CookieBanner/CookieBanner.Buttons.stories.tsx +3 -3
- package/src/components/CookieBanner/CookieBanner.stories.tsx +6 -6
- package/src/components/CookieBanner/CookieBanner.test.tsx +6 -0
- package/src/components/CookieBanner/CookieBanner.tsx +13 -3
- package/src/components/DatePicker/DatePicker.test.tsx +0 -5
- package/src/components/DatePicker/DatePicker.tsx +3 -2
- package/src/components/DatePicker/types.ts +20 -0
- package/src/components/Details/Details.stories.tsx +1 -1
- package/src/components/Details/Details.tsx +3 -1
- package/src/components/Details/types.ts +4 -0
- package/src/components/ErrorMessage/ErrorMessage.tsx +3 -1
- package/src/components/ErrorMessage/types.ts +3 -0
- package/src/components/ErrorSummary/ErrorSummary.test.tsx +1 -1
- package/src/components/ErrorSummary/ErrorSummary.tsx +3 -2
- package/src/components/ErrorSummary/types.ts +11 -0
- package/src/components/FileDownload/FileDownload.tsx +2 -1
- package/src/components/FileDownload/types.ts +11 -0
- package/src/components/HideThisPage/HideThisPage.tsx +3 -2
- package/src/components/HideThisPage/types.ts +3 -0
- package/src/components/InsetText/InsetText.tsx +1 -1
- package/src/components/NotificationBanner/NotificationBanner.stories.tsx +2 -2
- package/src/components/NotificationBanner/NotificationBanner.tsx +5 -4
- package/src/components/NotificationPanel/NotificationPanel.tsx +2 -1
- package/src/components/NotificationPanel/types.ts +7 -0
- package/src/components/PageHeader/PageHeader.tsx +3 -1
- package/src/components/PageHeader/types.ts +5 -0
- package/src/components/PageMetadata/PageMetadata.stories.tsx +1 -1
- package/src/components/PageMetadata/PageMetadata.tsx +5 -3
- package/src/components/PageMetadata/types.ts +7 -0
- package/src/components/Pagination/Pagination.tsx +5 -3
- package/src/components/Pagination/types.ts +20 -0
- package/src/components/PhaseBanner/PhaseBanner.stories.tsx +1 -4
- package/src/components/PhaseBanner/PhaseBanner.tsx +2 -1
- package/src/components/PhaseBanner/types.ts +3 -0
- package/src/components/Question/Question.tsx +3 -2
- package/src/components/Question/types.ts +9 -0
- package/src/components/RadioButton/RadioButton.tsx +5 -4
- package/src/components/RadioButton/RadioGroup.tsx +2 -1
- package/src/components/RadioButton/types.ts +12 -0
- package/src/components/SearchFacets/SearchFacets.Group.stories.tsx +2 -3
- package/src/components/SearchFacets/SearchFacets.stories.tsx +1 -1
- package/src/components/SearchFacets/SearchFacets.tsx +7 -6
- package/src/components/SearchFacets/types.ts +14 -0
- package/src/components/SearchFilters/SearchFilters.Panel.stories.tsx +18 -7
- package/src/components/SearchFilters/SearchFilters.stories.tsx +1 -1
- package/src/components/SearchFilters/SearchFilters.tsx +4 -3
- package/src/components/SearchFilters/types.ts +14 -0
- package/src/components/SearchResult/SearchResult.stories.tsx +9 -10
- package/src/components/SearchResult/SearchResult.tsx +9 -8
- package/src/components/SearchResult/types.ts +13 -0
- package/src/components/SearchSort/SearchSort.stories.tsx +2 -1
- package/src/components/SearchSort/SearchSort.tsx +2 -1
- package/src/components/SearchSort/types.ts +7 -0
- package/src/components/Select/Select.tsx +5 -4
- package/src/components/Select/types.ts +7 -0
- package/src/components/SequentialNavigation/SequentialNavigation.tsx +6 -4
- package/src/components/SequentialNavigation/types.ts +12 -0
- package/src/components/SideNavigation/SideNavigation.tsx +5 -4
- package/src/components/SideNavigation/types.ts +16 -0
- package/src/components/SiteFooter/SiteFooter.tsx +7 -6
- package/src/components/SiteFooter/types.ts +20 -0
- package/src/components/SiteHeader/SiteHeader.stories.tsx +4 -3
- package/src/components/SiteHeader/SiteHeader.tsx +10 -9
- package/src/components/SiteHeader/types.ts +22 -0
- package/src/components/SiteNavigation/SiteNavigation.tsx +4 -2
- package/src/components/SiteNavigation/types.ts +11 -0
- package/src/components/SiteSearch/SiteSearch.stories.tsx +4 -2
- package/src/components/SiteSearch/SiteSearch.tsx +6 -5
- package/src/components/SiteSearch/types.ts +13 -0
- package/src/components/SkipLinks/SkipLinks.stories.tsx +3 -3
- package/src/components/SkipLinks/SkipLinks.tsx +4 -4
- package/src/components/SkipLinks/types.ts +9 -0
- package/src/components/SummaryCard/SummaryCard.test.tsx +0 -11
- package/src/components/SummaryCard/SummaryCard.tsx +6 -4
- package/src/components/SummaryCard/types.ts +6 -0
- package/src/components/SummaryList/SummaryList.Item.stories.tsx +5 -5
- package/src/components/SummaryList/SummaryList.stories.tsx +1 -1
- package/src/components/SummaryList/SummaryList.test.tsx +1 -6
- package/src/components/SummaryList/SummaryList.tsx +8 -6
- package/src/components/SummaryList/types.ts +7 -0
- package/src/components/Table/Table.tsx +3 -2
- package/src/components/Table/types.ts +6 -0
- package/src/components/Tabs/Tabs.Item.stories.tsx +7 -7
- package/src/components/Tabs/Tabs.stories.tsx +3 -3
- package/src/components/Tabs/Tabs.tsx +7 -5
- package/src/components/Tabs/types.ts +19 -0
- package/src/components/Tag/Tag.tsx +3 -1
- package/src/components/Tag/types.ts +5 -0
- package/src/components/TaskList/TaskList.Group.stories.tsx +0 -5
- package/src/components/TaskList/TaskList.stories.tsx +0 -1
- package/src/components/TaskList/TaskList.tsx +12 -9
- package/src/components/TaskList/types.ts +20 -0
- package/src/components/TextInput/TextInput.tsx +6 -6
- package/src/components/TextInput/types.ts +12 -0
- package/src/components/Textarea/Textarea.tsx +6 -5
- package/src/components/WarningText/WarningText.tsx +1 -1
- package/src/hooks/useTracking/useTracking.test.tsx +5 -7
- package/src/hooks/useTracking/useTracking.ts +1 -1
- package/src/images/icons/arrow_upward.tsx +10 -10
- package/src/images/icons/calendar_today.tsx +10 -10
- package/src/images/icons/cancel.tsx +8 -8
- package/src/images/icons/check_circle.tsx +10 -10
- package/src/images/icons/chevron_left.tsx +10 -10
- package/src/images/icons/chevron_right.tsx +10 -10
- package/src/images/icons/close.tsx +10 -10
- package/src/images/icons/description.tsx +10 -10
- package/src/images/icons/double_chevron_left.tsx +8 -8
- package/src/images/icons/double_chevron_right.tsx +8 -8
- package/src/images/icons/error.tsx +10 -10
- package/src/images/icons/expand_less.tsx +10 -10
- package/src/images/icons/expand_more.tsx +10 -10
- package/src/images/icons/list.tsx +13 -13
- package/src/images/icons/menu.tsx +10 -10
- package/src/images/icons/priority_high.tsx +11 -11
- package/src/images/icons/search.tsx +10 -10
- package/src/shared-types.ts +40 -0
- package/vite.config.ts +2 -1
- package/@types/common/AbstractNotificationBanner.d.ts +0 -17
- package/@types/common/ActionLink.d.ts +0 -8
- package/@types/common/ConditionalWrapper.d.ts +0 -6
- package/@types/common/FileIcon.d.ts +0 -7
- package/@types/common/HintText.d.ts +0 -6
- package/@types/common/Icon.d.ts +0 -9
- package/@types/common/ScreenReaderText.d.ts +0 -4
- package/@types/common/WrapperTag.d.ts +0 -5
- package/@types/components/Accordion.d.ts +0 -15
- package/@types/components/AspectBox.d.ts +0 -5
- package/@types/components/BackToTop.d.ts +0 -5
- package/@types/components/Breadcrumbs.d.ts +0 -11
- package/@types/components/Button.d.ts +0 -17
- package/@types/components/ButtonGroup.d.ts +0 -5
- package/@types/components/CategoryItem.d.ts +0 -10
- package/@types/components/CategoryList.d.ts +0 -7
- package/@types/components/Checkbox.d.ts +0 -11
- package/@types/components/ConfirmationMessage.d.ts +0 -7
- package/@types/components/ContentsNav.d.ts +0 -13
- package/@types/components/DatePicker.d.ts +0 -20
- package/@types/components/Details.d.ts +0 -6
- package/@types/components/ErrorMessage.d.ts +0 -5
- package/@types/components/ErrorSummary.d.ts +0 -12
- package/@types/components/FileDownload.d.ts +0 -11
- package/@types/components/HideThisPage.d.ts +0 -5
- package/@types/components/InsetText.d.ts +0 -5
- package/@types/components/Metadata.d.ts +0 -11
- package/@types/components/NotificationPanel.d.ts +0 -7
- package/@types/components/PageHeader.d.ts +0 -7
- package/@types/components/Pagination.d.ts +0 -22
- package/@types/components/PhaseBanner.d.ts +0 -5
- package/@types/components/Question.d.ts +0 -11
- package/@types/components/RadioButton.d.ts +0 -14
- package/@types/components/SearchFacets.d.ts +0 -18
- package/@types/components/SearchFilters.d.ts +0 -14
- package/@types/components/SearchResult.d.ts +0 -30
- package/@types/components/SearchSort.d.ts +0 -9
- package/@types/components/Select.d.ts +0 -7
- package/@types/components/SequentialNavigation.d.ts +0 -14
- package/@types/components/SideNavigation.d.ts +0 -18
- package/@types/components/SiteFooter.d.ts +0 -25
- package/@types/components/SiteHeader.d.ts +0 -20
- package/@types/components/SiteNavigation.d.ts +0 -13
- package/@types/components/SiteSearch.d.ts +0 -14
- package/@types/components/SkipLinks.d.ts +0 -13
- package/@types/components/SummaryCard.d.ts +0 -6
- package/@types/components/SummaryList.d.ts +0 -14
- package/@types/components/Table.d.ts +0 -8
- package/@types/components/Tabs.d.ts +0 -21
- package/@types/components/Tag.d.ts +0 -5
- package/@types/components/TaskList.d.ts +0 -22
- package/@types/components/TextInput.d.ts +0 -12
- package/@types/components/Textarea.d.ts +0 -4
- package/@types/components/WarningText.d.ts +0 -5
- package/@types/global.d.ts +0 -1
- package/@types/sgds.d.ts +0 -49
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -40
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/components/FeatureHeader/FeatureHeader.stories.tsx +0 -60
- package/src/components/FeatureHeader/FeatureHeader.tsx +0 -94
- package/src/components/FeatureHeader/index.ts +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SearchFiltersPanelProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
2
|
+
activeFilterCount?: number;
|
|
3
|
+
heading: string | React.ReactNode;
|
|
4
|
+
isScrollable?: boolean;
|
|
5
|
+
legend: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SearchFiltersCheckboxGroupProps {
|
|
9
|
+
children: React.ReactNode,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SearchFiltersProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
13
|
+
searchResultsContainerId?: string;
|
|
14
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import argTypes from '../../../.storybook/sgdsArgTypes';
|
|
3
|
-
|
|
4
3
|
import SearchResult from './SearchResult';
|
|
5
|
-
|
|
6
|
-
//@ts-ignore
|
|
4
|
+
// @ts-expect-error no types
|
|
7
5
|
import coo from '../../../static/images/highland-cow.jpg';
|
|
8
6
|
|
|
9
7
|
const meta = {
|
|
@@ -13,7 +11,8 @@ const meta = {
|
|
|
13
11
|
children: argTypes.children()
|
|
14
12
|
},
|
|
15
13
|
args: {
|
|
16
|
-
title: '
|
|
14
|
+
title: 'Greenhouse gas statistics 1990-2022',
|
|
15
|
+
href: '#foo'
|
|
17
16
|
}
|
|
18
17
|
} satisfies Meta<typeof SearchResult>;
|
|
19
18
|
|
|
@@ -22,7 +21,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
22
21
|
|
|
23
22
|
export const Default: Story = {
|
|
24
23
|
render: (args) => (
|
|
25
|
-
<SearchResult
|
|
24
|
+
<SearchResult {...args}>
|
|
26
25
|
<SearchResult.Content>
|
|
27
26
|
Official statistics showing emissions of greenhouse gases in Scotland over the period 1990 to 2022.
|
|
28
27
|
</SearchResult.Content>
|
|
@@ -32,7 +31,7 @@ export const Default: Story = {
|
|
|
32
31
|
|
|
33
32
|
export const Metadata: Story = {
|
|
34
33
|
render: (args) => (
|
|
35
|
-
<SearchResult
|
|
34
|
+
<SearchResult {...args}>
|
|
36
35
|
<SearchResult.Content>
|
|
37
36
|
Official statistics showing emissions of greenhouse gases in Scotland over the period 1990 to 2022.
|
|
38
37
|
</SearchResult.Content>
|
|
@@ -50,7 +49,7 @@ export const Metadata: Story = {
|
|
|
50
49
|
|
|
51
50
|
export const Context: Story = {
|
|
52
51
|
render: (args) => (
|
|
53
|
-
<SearchResult
|
|
52
|
+
<SearchResult {...args}>
|
|
54
53
|
<SearchResult.Content>
|
|
55
54
|
Official statistics showing emissions of greenhouse gases in Scotland over the period 1990 to 2022.
|
|
56
55
|
</SearchResult.Content>
|
|
@@ -64,7 +63,7 @@ export const Context: Story = {
|
|
|
64
63
|
|
|
65
64
|
export const Media: Story = {
|
|
66
65
|
render: (args) => (
|
|
67
|
-
<SearchResult
|
|
66
|
+
<SearchResult {...args}>
|
|
68
67
|
<SearchResult.Content>
|
|
69
68
|
<SearchResult.Media>
|
|
70
69
|
<img src={coo} alt="" />
|
|
@@ -77,7 +76,7 @@ export const Media: Story = {
|
|
|
77
76
|
|
|
78
77
|
export const Promoted: Story = {
|
|
79
78
|
render: (args) => (
|
|
80
|
-
<SearchResult isPromoted
|
|
79
|
+
<SearchResult isPromoted {...args}>
|
|
81
80
|
<SearchResult.Content>
|
|
82
81
|
Official statistics showing emissions of greenhouse gases in Scotland over the period 1990 to 2022.
|
|
83
82
|
</SearchResult.Content>
|
|
@@ -87,7 +86,7 @@ export const Promoted: Story = {
|
|
|
87
86
|
|
|
88
87
|
export const KitchenSink: Story = {
|
|
89
88
|
render: (args) => (
|
|
90
|
-
<SearchResult isPromoted
|
|
89
|
+
<SearchResult isPromoted {...args}>
|
|
91
90
|
<SearchResult.Content>
|
|
92
91
|
<SearchResult.Media>
|
|
93
92
|
<img src={coo} alt="" />
|
|
@@ -2,18 +2,19 @@ import { Children, createContext, useContext } from 'react';
|
|
|
2
2
|
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
3
3
|
import AspectBox from '../AspectBox';
|
|
4
4
|
import Metadata from '../PageMetadata';
|
|
5
|
+
import { SearchResultContextProps, SearchResultProps } from './types';
|
|
5
6
|
|
|
6
7
|
const SearchResultLinkHrefContext = createContext('');
|
|
7
8
|
|
|
8
9
|
const SearchResultContent = ({
|
|
9
10
|
children
|
|
10
|
-
}:
|
|
11
|
-
const otherChildren:
|
|
11
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
12
|
+
const otherChildren: React.ReactNode[] = [];
|
|
12
13
|
let imageChild: React.ReactNode = null;
|
|
13
14
|
|
|
14
15
|
// assign to slots
|
|
15
16
|
Children.forEach(children, (child: React.ReactNode) => {
|
|
16
|
-
const thisChild = child as React.
|
|
17
|
+
const thisChild = child as React.JSX.Element;
|
|
17
18
|
if (thisChild && thisChild.type === SearchResultMedia) {
|
|
18
19
|
imageChild = thisChild;
|
|
19
20
|
} else {
|
|
@@ -37,7 +38,7 @@ const SearchResultContent = ({
|
|
|
37
38
|
const SearchResultContext = ({
|
|
38
39
|
children,
|
|
39
40
|
title = 'Part of'
|
|
40
|
-
}:
|
|
41
|
+
}: SearchResultContextProps) => {
|
|
41
42
|
return (
|
|
42
43
|
<dl className="ds_search-result__context">
|
|
43
44
|
<dt className="ds_search-result__context-key">{title}:</dt>
|
|
@@ -48,7 +49,7 @@ const SearchResultContext = ({
|
|
|
48
49
|
|
|
49
50
|
const SearchResultContextItem = ({
|
|
50
51
|
children
|
|
51
|
-
}:
|
|
52
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
52
53
|
return (
|
|
53
54
|
<dd className="ds_search-result__context-value">
|
|
54
55
|
{children}
|
|
@@ -58,7 +59,7 @@ const SearchResultContextItem = ({
|
|
|
58
59
|
|
|
59
60
|
const SearchResultMedia = ({
|
|
60
61
|
children
|
|
61
|
-
}:
|
|
62
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
62
63
|
return (
|
|
63
64
|
<div className="ds_search-result__media-wrapper">
|
|
64
65
|
<a className="ds_search-result__media-link" href={useContext(SearchResultLinkHrefContext)} tabIndex={-1} aria-hidden="true">
|
|
@@ -72,7 +73,7 @@ const SearchResultMedia = ({
|
|
|
72
73
|
|
|
73
74
|
const SearchResultMeta = ({
|
|
74
75
|
children
|
|
75
|
-
}:
|
|
76
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
76
77
|
return (
|
|
77
78
|
<Metadata className="ds_search-result__metadata" isInline>
|
|
78
79
|
{children}
|
|
@@ -88,7 +89,7 @@ const SearchResult = ({
|
|
|
88
89
|
promotedTitle = 'Recommended',
|
|
89
90
|
title,
|
|
90
91
|
...props
|
|
91
|
-
}:
|
|
92
|
+
}: SearchResultProps) => {
|
|
92
93
|
const LINK_CLASS = 'ds_search-result__link';
|
|
93
94
|
|
|
94
95
|
return (
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LinkComponent } from "../../shared-types";
|
|
2
|
+
|
|
3
|
+
export interface SearchResultContextProps extends React.AllHTMLAttributes<HTMLDListElement> {
|
|
4
|
+
title: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SearchResultProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
8
|
+
href: string;
|
|
9
|
+
isPromoted?: boolean;
|
|
10
|
+
linkComponent?: LinkComponent;
|
|
11
|
+
promotedTitle?: string;
|
|
12
|
+
title: string;
|
|
13
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AllHTMLAttributes } from "react";
|
|
2
2
|
import Button from "../Button";
|
|
3
3
|
import Select from "../Select";
|
|
4
|
+
import { SearchSortProps } from "./types";
|
|
4
5
|
|
|
5
6
|
const Option = ({
|
|
6
7
|
children,
|
|
@@ -20,7 +21,7 @@ const SearchSort = ({
|
|
|
20
21
|
label = 'Sort by',
|
|
21
22
|
onApply,
|
|
22
23
|
...props
|
|
23
|
-
}:
|
|
24
|
+
}: SearchSortProps) => {
|
|
24
25
|
return (
|
|
25
26
|
<div
|
|
26
27
|
className={[
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ErrorMessage from '../ErrorMessage';
|
|
2
2
|
import HintText from '../../common/HintText';
|
|
3
|
+
import { SelectProps } from './types';
|
|
3
4
|
|
|
4
5
|
const Select = function ({
|
|
5
6
|
children,
|
|
@@ -16,7 +17,7 @@ const Select = function ({
|
|
|
16
17
|
placeholder,
|
|
17
18
|
width,
|
|
18
19
|
...props
|
|
19
|
-
}:
|
|
20
|
+
}: SelectProps) {
|
|
20
21
|
const errorMessageId = `error-message-${id}`;
|
|
21
22
|
const hintTextId = `hint-text-${id}`;
|
|
22
23
|
const describedbys: string[] = [];
|
|
@@ -24,13 +25,13 @@ const Select = function ({
|
|
|
24
25
|
if (hintText) { describedbys.push(hintTextId) };
|
|
25
26
|
if (errorMessage) { describedbys.push(errorMessageId) };
|
|
26
27
|
|
|
27
|
-
function handleBlur(event: React.FocusEvent) {
|
|
28
|
+
function handleBlur(event: React.FocusEvent<HTMLSelectElement>) {
|
|
28
29
|
if (typeof onBlur === 'function') {
|
|
29
30
|
onBlur(event);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function handleChange(event: React.ChangeEvent) {
|
|
34
|
+
function handleChange(event: React.ChangeEvent<HTMLSelectElement>) {
|
|
34
35
|
if (typeof onChange === 'function') {
|
|
35
36
|
onChange(event);
|
|
36
37
|
}
|
|
@@ -39,7 +40,7 @@ const Select = function ({
|
|
|
39
40
|
return (
|
|
40
41
|
<>
|
|
41
42
|
<label className="ds_label" htmlFor={id}>{label}</label>
|
|
42
|
-
{hintText && <HintText id={hintTextId}
|
|
43
|
+
{hintText && <HintText id={hintTextId}>{hintText}</HintText>}
|
|
43
44
|
{errorMessage && <ErrorMessage id={errorMessageId}>{errorMessage}</ErrorMessage>}
|
|
44
45
|
<div
|
|
45
46
|
className={[
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { SequentialNavigationLinkProps, SequentialNavigationProps } from "./types";
|
|
2
|
+
|
|
1
3
|
const SeqNavLink = ({
|
|
2
4
|
children,
|
|
3
5
|
href,
|
|
4
6
|
isPrev,
|
|
5
7
|
linkComponent,
|
|
6
8
|
textLabel
|
|
7
|
-
}:
|
|
9
|
+
}:SequentialNavigationLinkProps) => {
|
|
8
10
|
const LINK_CLASSES = [
|
|
9
11
|
'ds_sequential-nav__button',
|
|
10
12
|
isPrev ? 'ds_sequential-nav__button--left' : 'ds_sequential-nav__button--right'
|
|
@@ -39,7 +41,7 @@ const NextLink = ({
|
|
|
39
41
|
href,
|
|
40
42
|
linkComponent,
|
|
41
43
|
textLabel = 'Next'
|
|
42
|
-
}:
|
|
44
|
+
}: SequentialNavigationLinkProps) => {
|
|
43
45
|
return <SeqNavLink href={href} linkComponent={linkComponent} textLabel={textLabel}>{children}</SeqNavLink>
|
|
44
46
|
};
|
|
45
47
|
|
|
@@ -48,7 +50,7 @@ const PreviousLink = ({
|
|
|
48
50
|
href,
|
|
49
51
|
linkComponent,
|
|
50
52
|
textLabel = 'Previous'
|
|
51
|
-
}:
|
|
53
|
+
}: SequentialNavigationLinkProps) => {
|
|
52
54
|
return <SeqNavLink href={href} linkComponent={linkComponent} textLabel={textLabel} isPrev>{children}</SeqNavLink>
|
|
53
55
|
};
|
|
54
56
|
|
|
@@ -57,7 +59,7 @@ const SequentialNavigation = ({
|
|
|
57
59
|
children,
|
|
58
60
|
className,
|
|
59
61
|
...props
|
|
60
|
-
}:
|
|
62
|
+
}: SequentialNavigationProps) => {
|
|
61
63
|
return (
|
|
62
64
|
<nav
|
|
63
65
|
className={[
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LinkComponent } from "../../shared-types";
|
|
2
|
+
|
|
3
|
+
export interface SequentialNavigationLinkProps extends React.AllHTMLAttributes<HTMLDivElement> {
|
|
4
|
+
href: string;
|
|
5
|
+
isPrev?: boolean;
|
|
6
|
+
linkComponent?: LinkComponent;
|
|
7
|
+
textLabel?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SequentialNavigationProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
11
|
+
ariaLabel?: React.AriaAttributes['aria-label'];
|
|
12
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
// @ts-
|
|
2
|
+
// @ts-expect-error no types from core SGDS
|
|
3
3
|
import DSSideNavigation from '@scottish-government/design-system/src/components/side-navigation/side-navigation';
|
|
4
|
+
import { SideNavigationItemProps, SideNavigationListProps, SideNavigationProps } from './types';
|
|
4
5
|
|
|
5
6
|
const SideNavigationList = function ({
|
|
6
7
|
children,
|
|
7
8
|
isRoot
|
|
8
|
-
}:
|
|
9
|
+
}: SideNavigationListProps) {
|
|
9
10
|
return (
|
|
10
11
|
<ul className="ds_side-navigation__list"
|
|
11
12
|
id={isRoot ? 'side-navigation-root' : undefined }
|
|
@@ -21,7 +22,7 @@ const SideNavigationItem = function ({
|
|
|
21
22
|
isCurrent = false,
|
|
22
23
|
linkComponent,
|
|
23
24
|
title
|
|
24
|
-
}:
|
|
25
|
+
}: SideNavigationItemProps) {
|
|
25
26
|
const LINK_CLASS = 'ds_side-navigation__link';
|
|
26
27
|
|
|
27
28
|
return (
|
|
@@ -47,7 +48,7 @@ const SideNavigation = function ({
|
|
|
47
48
|
children,
|
|
48
49
|
className,
|
|
49
50
|
...props
|
|
50
|
-
}:
|
|
51
|
+
}: SideNavigationProps) {
|
|
51
52
|
const ref = useRef(null);
|
|
52
53
|
|
|
53
54
|
useEffect(() => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LinkComponent } from "../../shared-types";
|
|
2
|
+
|
|
3
|
+
export interface SideNavigationListProps extends React.AllHTMLAttributes<HTMLUListElement> {
|
|
4
|
+
isRoot?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SideNavigationItemProps extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
8
|
+
isCurrent?: boolean;
|
|
9
|
+
href: string;
|
|
10
|
+
linkComponent?: LinkComponent;
|
|
11
|
+
title: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SideNavigationProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
15
|
+
ariaLabel?: string;
|
|
16
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { Children } from 'react';
|
|
2
2
|
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
3
|
+
import { SiteFooterLicenseProps, SiteFooterLinkProps, SiteFooterOrgProps, SiteFooterProps } from './types';
|
|
3
4
|
|
|
4
5
|
const License = ({
|
|
5
6
|
children,
|
|
6
7
|
...props
|
|
7
|
-
}:
|
|
8
|
+
}: SiteFooterLicenseProps) => {
|
|
8
9
|
return (
|
|
9
10
|
<div className="ds_site-footer__copyright" {...props}>
|
|
10
11
|
{children}
|
|
@@ -15,7 +16,7 @@ const License = ({
|
|
|
15
16
|
const Links = ({
|
|
16
17
|
children,
|
|
17
18
|
...props
|
|
18
|
-
}:
|
|
19
|
+
}: React.AllHTMLAttributes<HTMLUListElement>) => {
|
|
19
20
|
return (
|
|
20
21
|
<ul className="ds_site-footer__site-items" {...props}>
|
|
21
22
|
{children}
|
|
@@ -28,7 +29,7 @@ const Link = ({
|
|
|
28
29
|
href,
|
|
29
30
|
linkComponent,
|
|
30
31
|
...props
|
|
31
|
-
}:
|
|
32
|
+
}: SiteFooterLinkProps) => {
|
|
32
33
|
function processChildren(children: React.ReactNode) {
|
|
33
34
|
if (linkComponent) {
|
|
34
35
|
return linkComponent({ href, children });
|
|
@@ -49,9 +50,9 @@ const Org = ({
|
|
|
49
50
|
title,
|
|
50
51
|
children,
|
|
51
52
|
...props
|
|
52
|
-
}:
|
|
53
|
+
}: SiteFooterOrgProps) => {
|
|
53
54
|
children = Children.map(children, child => {
|
|
54
|
-
|
|
55
|
+
const thisChild = child as React.ReactElement<HTMLElement>;
|
|
55
56
|
if (thisChild && ['img', 'svg', 'picture'].includes(thisChild.type as string)) {
|
|
56
57
|
return React.cloneElement(thisChild, { className: 'ds_site-footer__org-logo' });
|
|
57
58
|
} else {
|
|
@@ -75,7 +76,7 @@ const SiteFooter = ({
|
|
|
75
76
|
children,
|
|
76
77
|
className,
|
|
77
78
|
...props
|
|
78
|
-
}:
|
|
79
|
+
}: SiteFooterProps) => {
|
|
79
80
|
return (
|
|
80
81
|
<footer
|
|
81
82
|
className={[
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LinkComponent } from "../../shared-types";
|
|
2
|
+
|
|
3
|
+
export interface SiteFooterLinkProps extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
4
|
+
href?: string;
|
|
5
|
+
linkComponent?: LinkComponent;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SiteFooterLicenseProps extends React.AllHTMLAttributes<HTMLDivElement> {
|
|
9
|
+
href?: string;
|
|
10
|
+
logoSrc?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SiteFooterOrgProps extends React.AllHTMLAttributes<HTMLDivElement> {
|
|
14
|
+
href?: string;
|
|
15
|
+
title: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SiteFooterProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
@@ -17,6 +17,7 @@ const meta = {
|
|
|
17
17
|
<SiteHeader.Brand
|
|
18
18
|
homeUrl="/"
|
|
19
19
|
siteTitle="Design System React"
|
|
20
|
+
key="1"
|
|
20
21
|
>
|
|
21
22
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 206.7 30.7">
|
|
22
23
|
<title>The Scottish Government</title>
|
|
@@ -26,7 +27,7 @@ const meta = {
|
|
|
26
27
|
<path fill="#333e48" d="M205.1 12.8c.8 0 1.3-.2 1.6-.5l-.4-1.3c-.1.2-.4.3-.8.3-.5 0-.8-.4-.8-1V6.1h1.6V4.6h-1.6V2.3H203v2.2h-1.3V6h1.3v4.7c0 1.4.7 2.1 2.1 2.1m-4.7-.2V6.9c0-1.7-.9-2.6-2.6-2.6-1.3 0-2.3.7-2.9 1.3v-1h-1.8v8.1h1.8V7c.4-.5 1.2-1.1 2.1-1.1 1 0 1.6.4 1.6 1.7v5.1h1.8zm-10.5-4.7h-4.5c.1-1 .8-2.1 2.3-2.1 1.5 0 2.1 1.2 2.2 2.1m-2.2 4.9c1.3 0 2.5-.4 3.3-1.2l-.8-1.2c-.6.6-1.5.9-2.3.9-1.5 0-2.4-1-2.6-2.2h6.2v-.4c0-2.5-1.5-4.4-4-4.4a4 4 0 0 0-4.1 4.2c.1 2.6 1.9 4.3 4.3 4.3m-5.9-.2V6.8c0-1.6-.9-2.4-2.3-2.4-1.2 0-2.3.8-2.7 1.5-.3-.9-1-1.5-2.2-1.5-1.2 0-2.3.8-2.6 1.3V4.6h-1.8v8.1h1.8V7c.4-.5 1.1-1.1 1.9-1.1 1 0 1.3.6 1.3 1.5v5.3h1.8V7c.4-.5 1.1-1.1 1.9-1.1 1 0 1.3.6 1.3 1.5v5.3h1.6zm-13.9 0V6.9c0-1.7-.9-2.6-2.6-2.6-1.3 0-2.3.7-2.9 1.3v-1h-1.8v8.1h1.8V7c.4-.5 1.2-1.1 2.1-1.1 1 0 1.6.4 1.6 1.7v5.1h1.8zm-11.1 0V7.1c.4-.6 1.3-1.1 2.1-1.1h.5V4.4c-1 0-2 .6-2.6 1.4V4.6H155v8.1h1.8zm-5.1-4.7h-4.5c.1-1 .8-2.1 2.3-2.1 1.5 0 2.1 1.2 2.2 2.1m-2.2 4.9c1.3 0 2.5-.4 3.3-1.2l-.8-1.2c-.6.6-1.5.9-2.3.9-1.5 0-2.4-1-2.6-2.2h6.2v-.4c0-2.5-1.5-4.4-4-4.4a4 4 0 0 0-4.1 4.2c.1 2.6 1.9 4.3 4.3 4.3m-7.8-.2 3.3-8.1h-1.9l-2.4 6.1-2.4-6.1h-1.9l3.3 8.1h2zm-9.7-1.3c-1.5 0-2.3-1.3-2.3-2.7 0-1.4.8-2.7 2.3-2.7 1.5 0 2.3 1.3 2.3 2.7 0 1.4-.8 2.7-2.3 2.7m0 1.5c2.6 0 4.1-1.9 4.1-4.2 0-2.3-1.6-4.2-4.1-4.2s-4.1 1.9-4.1 4.2a4 4 0 0 0 4.1 4.2m-10.7 0c3.5 0 5.6-2.4 5.6-6.2h-6.1v1.7h4a3.2 3.2 0 0 1-3.3 2.7c-2.2 0-3.8-1.7-3.8-4 0-2.4 1.6-4 3.8-4 1.2 0 2.3.7 2.9 1.5l1.6-.9a5.2 5.2 0 0 0-4.5-2.3 5.7 5.7 0 0 0-5.9 5.8c0 3.5 2.7 5.7 5.7 5.7m-11.5-.2V6.9c0-1.7-.9-2.6-2.6-2.6-1.3 0-2.3.7-2.8 1.3V1.5h-1.8v11.2h1.8V7c.4-.5 1.2-1.1 2.1-1.1 1 0 1.6.4 1.6 1.6v5.1h1.7zm-12.2.2c2.2 0 3.4-1.1 3.4-2.5 0-3.2-4.9-2.1-4.9-3.6 0-.6.6-1 1.5-1 1 0 1.9.4 2.4 1l.7-1.2a4.8 4.8 0 0 0-3.1-1.1c-2 0-3.2 1.1-3.2 2.4 0 3.1 4.9 2 4.9 3.6 0 .6-.6 1.1-1.6 1.1a4 4 0 0 1-2.7-1.1l-.8 1.3c.8.7 2 1.1 3.4 1.1m-5-8.2h-1.8v8.1h1.8V4.6zm-.9-1c.6 0 1.1-.5 1.1-1.1 0-.6-.5-1.1-1.1-1.1-.6 0-1.1.5-1.1 1.1 0 .6.5 1.1 1.1 1.1M88 12.8c.8 0 1.3-.2 1.6-.5l-.4-1.3c-.1.2-.4.3-.8.3-.5 0-.8-.4-.8-1V6.1h1.6V4.6h-1.6V2.3h-1.8v2.2h-1.3V6h1.3v4.7c.1 1.4.8 2.1 2.2 2.1m-5.6 0c.8 0 1.3-.2 1.6-.5l-.4-1.3c-.1.2-.4.3-.8.3-.5 0-.8-.4-.8-1V6.1h1.6V4.6H82V2.3h-1.8v2.2h-1.3V6h1.3v4.7c.1 1.4.8 2.1 2.2 2.1m-8.3-1.5c-1.5 0-2.3-1.3-2.3-2.7 0-1.4.8-2.7 2.3-2.7 1.5 0 2.3 1.3 2.3 2.7 0 1.4-.8 2.7-2.3 2.7m0 1.5c2.6 0 4.1-1.9 4.1-4.2 0-2.3-1.6-4.2-4.1-4.2-2.6 0-4.1 1.9-4.1 4.2a4 4 0 0 0 4.1 4.2m-8.1 0c1.6 0 2.5-.7 3.1-1.4L68 10.3c-.5.6-1.1 1-1.9 1-1.5 0-2.4-1.1-2.4-2.7s1-2.7 2.4-2.7c.8 0 1.4.3 1.9.9l1.2-1.1c-.6-.7-1.6-1.3-3.2-1.3a4.1 4.1 0 0 0-4.2 4.2c.1 2.4 1.8 4.2 4.2 4.2m-9.7 0c3 0 4.3-1.6 4.3-3.5 0-4.1-6.5-2.9-6.5-4.9.1-.8.8-1.4 1.9-1.4 1.2 0 2.4.4 3.2 1.3l1.1-1.5c-1-1-2.4-1.6-4.2-1.6-2.5 0-4.1 1.4-4.1 3.3 0 4.1 6.5 2.6 6.5 5 0 .8-.6 1.5-2.2 1.5s-2.8-.7-3.5-1.6l-1.1 1.5a6 6 0 0 0 4.6 1.9"/>
|
|
27
28
|
</svg>
|
|
28
29
|
</SiteHeader.Brand>,
|
|
29
|
-
<SiteHeader.Navigation>
|
|
30
|
+
<SiteHeader.Navigation key="2">
|
|
30
31
|
<SiteNavigation>
|
|
31
32
|
<SiteNavigation.Item href="#about">
|
|
32
33
|
About
|
|
@@ -51,10 +52,10 @@ const meta = {
|
|
|
51
52
|
</SiteNavigation.Item>
|
|
52
53
|
</SiteNavigation>
|
|
53
54
|
</SiteHeader.Navigation>,
|
|
54
|
-
<SiteHeader.Search>
|
|
55
|
+
<SiteHeader.Search key="3">
|
|
55
56
|
<SiteSearch id="site-header-search" />
|
|
56
57
|
</SiteHeader.Search>,
|
|
57
|
-
<SiteHeader.Phase>
|
|
58
|
+
<SiteHeader.Phase key="4">
|
|
58
59
|
<PhaseBanner phaseName="Beta">
|
|
59
60
|
This is a new service. Your{' '}
|
|
60
61
|
<a href="#feedback">
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React, { Children, useEffect, useRef } from 'react';
|
|
2
2
|
import Icon from '../../common/Icon';
|
|
3
3
|
import SiteNavigation from '../SiteNavigation';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
4
|
+
// @ts-expect-error no types from core SGDS
|
|
6
5
|
import DSMobileMenu from '@scottish-government/design-system/src/components/site-navigation/site-navigation';
|
|
6
|
+
import { SiteHeaderBrandProps, SiteHeaderProps } from './types';
|
|
7
|
+
import { SiteNavigationProps } from '../SiteNavigation/types';
|
|
7
8
|
|
|
8
9
|
const Brand = ({
|
|
9
10
|
children,
|
|
10
11
|
homeUrl = '/',
|
|
11
12
|
linkComponent,
|
|
12
13
|
siteTitle
|
|
13
|
-
}:
|
|
14
|
+
}: SiteHeaderBrandProps) => {
|
|
14
15
|
function processChildren(children: React.ReactNode) {
|
|
15
16
|
const image = React.cloneElement(children as React.ReactElement<HTMLImageElement>, { className: 'ds_site-branding__logo-image' });
|
|
16
17
|
|
|
@@ -36,26 +37,26 @@ const Brand = ({
|
|
|
36
37
|
|
|
37
38
|
const Navigation = ({
|
|
38
39
|
children
|
|
39
|
-
}:
|
|
40
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
40
41
|
return children;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const Phase = ({
|
|
44
45
|
children
|
|
45
|
-
}:
|
|
46
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
46
47
|
return children;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
const Search = ({
|
|
50
51
|
children
|
|
51
|
-
}:
|
|
52
|
+
}: React.AllHTMLAttributes<HTMLElement>) => {
|
|
52
53
|
return children;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const SiteHeader = ({
|
|
56
57
|
children,
|
|
57
58
|
...props
|
|
58
|
-
}:
|
|
59
|
+
}: SiteHeaderProps) => {
|
|
59
60
|
const mobileMenuRef = useRef(null);
|
|
60
61
|
|
|
61
62
|
let branding: React.ReactNode;
|
|
@@ -66,14 +67,14 @@ const SiteHeader = ({
|
|
|
66
67
|
|
|
67
68
|
// assign to slots
|
|
68
69
|
Children.forEach(children, (child: React.ReactNode) => {
|
|
69
|
-
const thisChild = child as React.
|
|
70
|
+
const thisChild = child as React.JSX.Element;
|
|
70
71
|
if (thisChild && thisChild.type === Brand) {
|
|
71
72
|
branding = thisChild;
|
|
72
73
|
} else if (thisChild && thisChild.type === Navigation) {
|
|
73
74
|
navigation = thisChild;
|
|
74
75
|
|
|
75
76
|
if (thisChild.props.children.type === SiteNavigation) {
|
|
76
|
-
mobileNavigation = React.cloneElement(thisChild.props.children as React.ReactElement<
|
|
77
|
+
mobileNavigation = React.cloneElement(thisChild.props.children as React.ReactElement<SiteNavigationProps>, { className: 'ds_site-navigation--mobile', id: 'mobile-navigation', ref: mobileMenuRef});
|
|
77
78
|
}
|
|
78
79
|
} else if (thisChild && thisChild.type === Phase) {
|
|
79
80
|
phase = thisChild;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LinkComponent } from "../../shared-types";
|
|
2
|
+
import { PhaseBannerProps } from "../PhaseBanner/types";
|
|
3
|
+
import { SiteNavigationItemProps } from "../SiteNavigation/types";
|
|
4
|
+
import { SiteSearchProps } from "../SiteSearch/types";
|
|
5
|
+
|
|
6
|
+
export interface SiteHeaderBrandProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
7
|
+
homeUrl: string;
|
|
8
|
+
linkComponent?: LinkComponent;
|
|
9
|
+
siteTitle?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SiteHeaderProps extends React.AllHTMLAttributes<HTMLHeadingElement> {
|
|
13
|
+
logo?: {
|
|
14
|
+
alt?: string;
|
|
15
|
+
href?: string;
|
|
16
|
+
src?: string;
|
|
17
|
+
};
|
|
18
|
+
navigationItems?: SiteNavigationItemProps[];
|
|
19
|
+
phaseBanner?: PhaseBannerProps;
|
|
20
|
+
siteSearch?: SiteSearchProps;
|
|
21
|
+
siteTitle?: string;
|
|
22
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { SiteNavigationItemProps, SiteNavigationProps } from "./types";
|
|
2
|
+
|
|
1
3
|
const Item = ({
|
|
2
4
|
children,
|
|
3
5
|
isCurrent = false,
|
|
4
6
|
href,
|
|
5
7
|
linkComponent
|
|
6
|
-
}:
|
|
8
|
+
}: SiteNavigationItemProps) => {
|
|
7
9
|
const classNames = ['ds_site-navigation__link'];
|
|
8
10
|
let ariaCurrent: React.AriaAttributes["aria-current"];
|
|
9
11
|
|
|
@@ -33,7 +35,7 @@ const SiteNavigation = ({
|
|
|
33
35
|
children,
|
|
34
36
|
className,
|
|
35
37
|
...props
|
|
36
|
-
}:
|
|
38
|
+
}: SiteNavigationProps) => {
|
|
37
39
|
return (
|
|
38
40
|
<nav
|
|
39
41
|
className={[
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LinkComponent } from '../../shared-types';
|
|
2
|
+
|
|
3
|
+
export interface SiteNavigationItemProps extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
4
|
+
isCurrent?: boolean;
|
|
5
|
+
href: string;
|
|
6
|
+
linkComponent?: LinkComponent;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SiteNavigationProps extends React.AllHTMLAttributes<HTMLElement> {
|
|
10
|
+
ref?: React.RefObject<null>;
|
|
11
|
+
}
|
|
@@ -11,8 +11,10 @@ type AutocompleteResponseObject = {
|
|
|
11
11
|
category: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type SuggestionObject = { response: string };
|
|
15
|
+
|
|
16
|
+
const suggestionMappingFunction = function (suggestionObj: SuggestionObject) {
|
|
17
|
+
const responseObj = JSON.parse(suggestionObj.response).map((item: string) => ({
|
|
16
18
|
key: '',
|
|
17
19
|
displayText: item,
|
|
18
20
|
weight: '',
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
// @ts-
|
|
2
|
+
// @ts-expect-error no types from core SGDS
|
|
3
3
|
import DSAutocomplete from '@scottish-government/design-system/src/components/autocomplete/autocomplete';
|
|
4
4
|
import Button from '../Button';
|
|
5
|
+
import { SiteSearchProps, SuggestionMappingFunctionProps } from './types';
|
|
5
6
|
|
|
6
7
|
const SiteSearch = function ({
|
|
7
8
|
action = '/search',
|
|
@@ -14,14 +15,14 @@ const SiteSearch = function ({
|
|
|
14
15
|
name = 'q',
|
|
15
16
|
placeholder = 'Search',
|
|
16
17
|
...props
|
|
17
|
-
}:
|
|
18
|
+
}: SiteSearchProps) {
|
|
18
19
|
const ref = useRef(null);
|
|
19
20
|
const hasAutocomplete = !!autocompleteEndpoint;
|
|
20
|
-
|
|
21
|
+
const autocompleteId = hasAutocomplete ? id + '-autocomplete' : '';
|
|
21
22
|
|
|
22
23
|
type AutoCompleteOptions = {
|
|
23
24
|
minLength?: number,
|
|
24
|
-
suggestionMappingFunction?:
|
|
25
|
+
suggestionMappingFunction?: SuggestionMappingFunctionProps,
|
|
25
26
|
throttleDelay?: number
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -48,7 +49,7 @@ const SiteSearch = function ({
|
|
|
48
49
|
return (
|
|
49
50
|
<div
|
|
50
51
|
className={[
|
|
51
|
-
'ds_site-search',
|
|
52
|
+
'ds_site-search',
|
|
52
53
|
className,
|
|
53
54
|
hasAutocomplete ? 'ds_autocomplete' : undefined
|
|
54
55
|
].join(' ')}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type FormMethods = 'GET' | 'POST';
|
|
2
|
+
export type SuggestionMappingFunctionProps = (suggestionObj: {response: string}) => [];
|
|
3
|
+
|
|
4
|
+
export interface SiteSearchProps extends React.AllHTMLAttributes<HTMLInputElement> {
|
|
5
|
+
action?: string;
|
|
6
|
+
autocompleteEndpoint?: string;
|
|
7
|
+
autocompleteSuggestionMappingFunction?: SuggestionMappingFunctionProps;
|
|
8
|
+
id: string;
|
|
9
|
+
method?: FormMethods;
|
|
10
|
+
minLength?: number;
|
|
11
|
+
name?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
}
|