@scottish-government/designsystem-react 0.13.0 → 1.0.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/sgdsArgTypes.ts +23 -0
- package/CHANGELOG.md +23 -0
- package/LICENSE.txt +21 -0
- package/README.md +3 -0
- package/dist/common/AbstractNotificationBanner/AbstractNotificationBanner.d.ts +3 -2
- package/dist/common/AbstractNotificationBanner/AbstractNotificationBanner.jsx +8 -7
- package/dist/common/AbstractNotificationBanner/types.d.ts +13 -0
- package/dist/common/AbstractNotificationBanner/types.js +2 -0
- package/dist/common/ActionLink/ActionLink.d.ts +2 -1
- package/dist/common/ActionLink/types.d.ts +7 -0
- package/dist/common/ActionLink/types.js +2 -0
- package/dist/common/ConditionalWrapper/ConditionalWrapper.d.ts +2 -1
- package/dist/common/ConditionalWrapper/ConditionalWrapper.jsx +4 -2
- package/dist/common/ConditionalWrapper/types.d.ts +4 -0
- package/dist/common/ConditionalWrapper/types.js +2 -0
- package/dist/common/FileIcon/FileIcon.d.ts +2 -1
- package/dist/common/FileIcon/types.d.ts +6 -0
- package/dist/common/FileIcon/types.js +2 -0
- package/dist/common/HintText/HintText.d.ts +2 -1
- package/dist/common/HintText/HintText.jsx +3 -3
- package/dist/common/HintText/types.d.ts +4 -0
- package/dist/common/HintText/types.js +2 -0
- package/dist/common/Icon/Icon.d.ts +2 -1
- package/dist/common/Icon/Icon.jsx +3 -2
- package/dist/common/Icon/types.d.ts +8 -0
- package/dist/common/Icon/types.js +2 -0
- package/dist/common/ScreenReaderText/ScreenReaderText.d.ts +1 -1
- package/dist/common/WrapperTag/WrapperTag.d.ts +385 -1
- package/dist/common/WrapperTag/WrapperTag.jsx +5 -2
- package/dist/common/WrapperTag/types.d.ts +3 -0
- package/dist/common/WrapperTag/types.js +2 -0
- package/dist/components/Accordion/Accordion.d.ts +3 -2
- package/dist/components/Accordion/Accordion.jsx +12 -11
- package/dist/components/Accordion/types.d.ts +11 -0
- package/dist/components/Accordion/types.js +2 -0
- package/dist/components/AspectBox/AspectBox.d.ts +2 -1
- package/dist/components/AspectBox/AspectBox.jsx +3 -9
- package/dist/components/AspectBox/types.d.ts +3 -0
- package/dist/components/AspectBox/types.js +2 -0
- package/dist/components/BackToTop/BackToTop.d.ts +2 -1
- package/dist/components/BackToTop/BackToTop.jsx +4 -3
- package/dist/components/BackToTop/types.d.ts +3 -0
- package/dist/components/BackToTop/types.js +2 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -2
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +6 -2
- package/dist/components/Breadcrumbs/types.d.ts +5 -0
- package/dist/components/Breadcrumbs/types.js +2 -0
- package/dist/components/Button/Button.d.ts +2 -1
- package/dist/components/Button/Button.jsx +4 -3
- package/dist/components/Button/ButtonGroup.d.ts +2 -1
- package/dist/components/Button/ButtonGroup.jsx +9 -4
- package/dist/components/Button/types.d.ts +20 -0
- package/dist/components/Button/types.js +2 -0
- package/dist/components/Card/Card.d.ts +34 -0
- package/dist/components/Card/Card.jsx +118 -0
- package/dist/components/Card/index.d.ts +1 -0
- package/dist/components/Card/index.js +8 -0
- package/dist/components/Card/types.d.ts +26 -0
- package/dist/components/Card/types.js +2 -0
- package/dist/components/CategoryItem/CategoryItem.d.ts +2 -1
- package/dist/components/CategoryItem/CategoryItem.jsx +8 -5
- package/dist/components/CategoryItem/types.d.ts +9 -0
- package/dist/components/CategoryItem/types.js +2 -0
- package/dist/components/CategoryList/CategoryList.d.ts +2 -1
- package/dist/components/CategoryList/CategoryList.jsx +3 -2
- package/dist/components/CategoryList/types.d.ts +5 -0
- package/dist/components/CategoryList/types.js +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +2 -1
- package/dist/components/Checkbox/Checkbox.jsx +4 -3
- package/dist/components/Checkbox/CheckboxGroup.d.ts +2 -1
- package/dist/components/Checkbox/CheckboxGroup.jsx +5 -4
- package/dist/components/Checkbox/types.d.ts +7 -0
- package/dist/components/Checkbox/types.js +2 -0
- package/dist/components/ConfirmationMessage/ConfirmationMessage.d.ts +2 -1
- package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +3 -2
- package/dist/components/ConfirmationMessage/types.d.ts +6 -0
- package/dist/components/ConfirmationMessage/types.js +2 -0
- package/dist/components/ContentsNav/ContentsNav.d.ts +3 -2
- package/dist/components/ContentsNav/ContentsNav.jsx +7 -5
- package/dist/components/ContentsNav/types.d.ts +9 -0
- package/dist/components/ContentsNav/types.js +2 -0
- package/dist/components/CookieBanner/CookieBanner.d.ts +3 -2
- package/dist/components/CookieBanner/CookieBanner.jsx +13 -3
- package/dist/components/DatePicker/DatePicker.d.ts +2 -1
- package/dist/components/DatePicker/DatePicker.jsx +7 -7
- package/dist/components/DatePicker/types.d.ts +18 -0
- package/dist/components/DatePicker/types.js +2 -0
- package/dist/components/Details/Details.d.ts +2 -1
- package/dist/components/Details/Details.jsx +6 -2
- package/dist/components/Details/types.d.ts +4 -0
- package/dist/components/Details/types.js +2 -0
- package/dist/components/ErrorMessage/ErrorMessage.d.ts +2 -1
- package/dist/components/ErrorMessage/ErrorMessage.jsx +6 -2
- package/dist/components/ErrorMessage/types.d.ts +3 -0
- package/dist/components/ErrorMessage/types.js +2 -0
- package/dist/components/ErrorSummary/ErrorSummary.d.ts +3 -2
- package/dist/components/ErrorSummary/ErrorSummary.jsx +6 -2
- package/dist/components/ErrorSummary/types.d.ts +8 -0
- package/dist/components/ErrorSummary/types.js +2 -0
- package/dist/components/FeatureHeader/FeatureHeader.d.ts +7 -5
- package/dist/components/FeatureHeader/FeatureHeader.jsx +87 -50
- package/dist/components/FeatureHeader/types.d.ts +12 -0
- package/dist/components/FeatureHeader/types.js +2 -0
- package/dist/components/FileDownload/FileDownload.d.ts +2 -1
- package/dist/components/FileDownload/FileDownload.jsx +4 -3
- package/dist/components/FileDownload/types.d.ts +10 -0
- package/dist/components/FileDownload/types.js +2 -0
- package/dist/components/HideThisPage/HideThisPage.d.ts +2 -1
- package/dist/components/HideThisPage/HideThisPage.jsx +5 -4
- package/dist/components/HideThisPage/types.d.ts +3 -0
- package/dist/components/HideThisPage/types.js +2 -0
- package/dist/components/InsetText/InsetText.d.ts +1 -1
- package/dist/components/InsetText/InsetText.jsx +6 -2
- package/dist/components/NotificationBanner/NotificationBanner.d.ts +3 -2
- package/dist/components/NotificationBanner/NotificationBanner.jsx +5 -4
- package/dist/components/NotificationPanel/NotificationPanel.d.ts +2 -1
- package/dist/components/NotificationPanel/NotificationPanel.jsx +3 -2
- package/dist/components/NotificationPanel/types.d.ts +6 -0
- package/dist/components/NotificationPanel/types.js +2 -0
- package/dist/components/NotificationTag/NotificationTag.d.ts +6 -0
- package/dist/components/NotificationTag/NotificationTag.jsx +20 -0
- package/dist/components/NotificationTag/index.d.ts +1 -0
- package/dist/components/NotificationTag/index.js +8 -0
- package/dist/components/NotificationTag/types.d.ts +5 -0
- package/dist/components/NotificationTag/types.js +2 -0
- package/dist/components/PageHeader/PageHeader.d.ts +2 -1
- package/dist/components/PageHeader/PageHeader.jsx +6 -2
- package/dist/components/PageHeader/types.d.ts +5 -0
- package/dist/components/PageHeader/types.js +2 -0
- package/dist/components/PageMetadata/PageMetadata.d.ts +3 -2
- package/dist/components/PageMetadata/PageMetadata.jsx +8 -4
- package/dist/components/PageMetadata/types.d.ts +6 -0
- package/dist/components/PageMetadata/types.js +2 -0
- package/dist/components/Pagination/Pagination.d.ts +3 -2
- package/dist/components/Pagination/Pagination.jsx +7 -5
- package/dist/components/Pagination/types.d.ts +18 -0
- package/dist/components/Pagination/types.js +2 -0
- package/dist/components/PhaseBanner/PhaseBanner.d.ts +2 -1
- package/dist/components/PhaseBanner/PhaseBanner.jsx +3 -2
- package/dist/components/PhaseBanner/types.d.ts +3 -0
- package/dist/components/PhaseBanner/types.js +2 -0
- package/dist/components/Question/Question.d.ts +2 -1
- package/dist/components/Question/Question.jsx +4 -3
- package/dist/components/Question/types.d.ts +9 -0
- package/dist/components/Question/types.js +2 -0
- package/dist/components/RadioButton/RadioButton.d.ts +2 -1
- package/dist/components/RadioButton/RadioButton.jsx +4 -3
- package/dist/components/RadioButton/RadioGroup.d.ts +2 -1
- package/dist/components/RadioButton/RadioGroup.jsx +3 -2
- package/dist/components/RadioButton/types.d.ts +10 -0
- package/dist/components/RadioButton/types.js +2 -0
- package/dist/components/SearchFacets/SearchFacets.d.ts +4 -3
- package/dist/components/SearchFacets/SearchFacets.jsx +3 -2
- package/dist/components/SearchFacets/types.d.ts +12 -0
- package/dist/components/SearchFacets/types.js +2 -0
- package/dist/components/SearchFilters/SearchFilters.d.ts +5 -4
- package/dist/components/SearchFilters/types.d.ts +12 -0
- package/dist/components/SearchFilters/types.js +2 -0
- package/dist/components/SearchResult/SearchResult.d.ts +8 -11
- package/dist/components/SearchResult/SearchResult.jsx +6 -7
- package/dist/components/SearchResult/types.d.ts +11 -0
- package/dist/components/SearchResult/types.js +2 -0
- package/dist/components/SearchSort/SearchSort.d.ts +2 -1
- package/dist/components/SearchSort/SearchSort.jsx +3 -2
- package/dist/components/SearchSort/types.d.ts +7 -0
- package/dist/components/SearchSort/types.js +2 -0
- package/dist/components/Select/Select.d.ts +2 -1
- package/dist/components/Select/Select.jsx +4 -3
- package/dist/components/Select/types.d.ts +6 -0
- package/dist/components/Select/types.js +2 -0
- package/dist/components/SequentialNavigation/SequentialNavigation.d.ts +4 -3
- package/dist/components/SequentialNavigation/SequentialNavigation.jsx +10 -6
- package/dist/components/SequentialNavigation/types.d.ts +10 -0
- package/dist/components/SequentialNavigation/types.js +2 -0
- package/dist/components/SideNavigation/SideNavigation.d.ts +4 -3
- package/dist/components/SideNavigation/SideNavigation.jsx +10 -7
- package/dist/components/SideNavigation/types.d.ts +13 -0
- package/dist/components/SideNavigation/types.js +2 -0
- package/dist/components/SiteFooter/SiteFooter.d.ts +6 -5
- package/dist/components/SiteFooter/SiteFooter.jsx +4 -3
- package/dist/components/SiteFooter/types.d.ts +16 -0
- package/dist/components/SiteFooter/types.js +2 -0
- package/dist/components/SiteHeader/SiteHeader.d.ts +6 -5
- package/dist/components/SiteHeader/SiteHeader.jsx +1 -1
- package/dist/components/SiteHeader/types.d.ts +20 -0
- package/dist/components/SiteHeader/types.js +2 -0
- package/dist/components/SiteNavigation/SiteNavigation.d.ts +3 -2
- package/dist/components/SiteNavigation/SiteNavigation.jsx +12 -4
- package/dist/components/SiteNavigation/types.d.ts +9 -0
- package/dist/components/SiteNavigation/types.js +2 -0
- package/dist/components/SiteSearch/SiteSearch.d.ts +2 -1
- package/dist/components/SiteSearch/SiteSearch.jsx +12 -11
- package/dist/components/SiteSearch/types.d.ts +17 -0
- package/dist/components/SiteSearch/types.js +2 -0
- package/dist/components/SkipLinks/SkipLinks.d.ts +3 -2
- package/dist/components/SkipLinks/SkipLinks.jsx +4 -4
- package/dist/components/SkipLinks/types.d.ts +8 -0
- package/dist/components/SkipLinks/types.js +2 -0
- package/dist/components/SummaryCard/SummaryCard.d.ts +4 -2
- package/dist/components/SummaryCard/SummaryCard.jsx +5 -4
- package/dist/components/SummaryCard/types.d.ts +5 -0
- package/dist/components/SummaryCard/types.js +2 -0
- package/dist/components/SummaryList/SummaryList.d.ts +6 -4
- package/dist/components/SummaryList/SummaryList.jsx +5 -4
- package/dist/components/SummaryList/types.d.ts +6 -0
- package/dist/components/SummaryList/types.js +2 -0
- package/dist/components/Table/Table.d.ts +2 -1
- package/dist/components/Table/Table.jsx +5 -4
- package/dist/components/Table/types.d.ts +6 -0
- package/dist/components/Table/types.js +2 -0
- package/dist/components/Tabs/Tabs.d.ts +3 -2
- package/dist/components/Tabs/Tabs.jsx +6 -5
- package/dist/components/Tabs/types.d.ts +16 -0
- package/dist/components/Tabs/types.js +2 -0
- package/dist/components/Tag/Tag.d.ts +2 -1
- package/dist/components/Tag/Tag.jsx +7 -3
- package/dist/components/Tag/types.d.ts +4 -0
- package/dist/components/Tag/types.js +2 -0
- package/dist/components/TaskList/TaskList.d.ts +4 -3
- package/dist/components/TaskList/TaskList.jsx +11 -8
- package/dist/components/TaskList/types.d.ts +17 -0
- package/dist/components/TaskList/types.js +2 -0
- package/dist/components/TextInput/TextInput.d.ts +2 -1
- package/dist/components/TextInput/TextInput.jsx +10 -9
- package/dist/components/TextInput/types.d.ts +11 -0
- package/dist/components/TextInput/types.js +2 -0
- package/dist/components/Textarea/Textarea.d.ts +2 -1
- package/dist/components/Textarea/Textarea.jsx +6 -5
- package/dist/components/WarningText/WarningText.d.ts +1 -1
- package/dist/components/WarningText/WarningText.jsx +6 -2
- package/dist/hooks/useTracking/useTracking.js +0 -1
- package/package.json +5 -3
- package/src/common/AbstractNotificationBanner/AbstractNotificationBanner.tsx +8 -6
- package/src/common/Icon/Icon.tsx +3 -2
- package/src/components/Accordion/Accordion.test.tsx +11 -0
- package/src/components/Accordion/Accordion.tsx +11 -10
- package/src/components/AspectBox/AspectBox.tsx +4 -11
- package/src/components/BackToTop/BackToTop.test.tsx +21 -1
- package/src/components/BackToTop/BackToTop.tsx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +3 -2
- package/src/components/Button/Button.tsx +4 -3
- package/src/components/Button/ButtonGroup.stories.tsx +22 -0
- package/src/components/Button/ButtonGroup.test.tsx +21 -0
- package/src/components/Button/ButtonGroup.tsx +6 -3
- package/src/components/Button/types.ts +1 -0
- package/src/components/Card/Card.stories.tsx +446 -0
- package/src/components/Card/Card.test.tsx +282 -0
- package/src/components/Card/Card.tsx +208 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Card/types.ts +30 -0
- package/src/components/CategoryItem/CategoryItem.tsx +3 -2
- package/src/components/CategoryList/CategoryList.tsx +3 -2
- package/src/components/Checkbox/Checkbox.test.tsx +30 -0
- package/src/components/Checkbox/Checkbox.tsx +3 -3
- package/src/components/Checkbox/CheckboxGroup.test.tsx +10 -0
- package/src/components/Checkbox/CheckboxGroup.tsx +5 -4
- package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +3 -2
- package/src/components/ContentsNav/ContentsNav.tsx +8 -5
- package/src/components/CookieBanner/CookieBanner.test.tsx +18 -1
- package/src/components/CookieBanner/CookieBanner.tsx +4 -3
- package/src/components/DatePicker/DatePicker.test.tsx +52 -14
- package/src/components/DatePicker/DatePicker.tsx +6 -7
- package/src/components/DatePicker/types.ts +2 -3
- package/src/components/Details/Details.tsx +3 -2
- package/src/components/ErrorMessage/ErrorMessage.tsx +3 -2
- package/src/components/ErrorSummary/ErrorSummary.tsx +3 -2
- package/src/components/FeatureHeader/FeatureHeader.stories.tsx +223 -0
- package/src/components/FeatureHeader/FeatureHeader.test.tsx +298 -0
- package/src/components/FeatureHeader/FeatureHeader.tsx +119 -0
- package/src/components/FeatureHeader/index.ts +1 -0
- package/src/components/FeatureHeader/types.ts +13 -0
- package/src/components/FileDownload/FileDownload.test.tsx +1 -5
- package/src/components/FileDownload/FileDownload.tsx +4 -3
- package/src/components/HideThisPage/HideThisPage.test.tsx +12 -1
- package/src/components/HideThisPage/HideThisPage.tsx +5 -4
- package/src/components/InsetText/InsetText.tsx +4 -2
- package/src/components/NotificationBanner/NotificationBanner.test.tsx +10 -0
- package/src/components/NotificationBanner/NotificationBanner.tsx +4 -3
- package/src/components/NotificationPanel/NotificationPanel.tsx +3 -2
- package/src/components/NotificationTag/NotificationTag.stories.tsx +68 -0
- package/src/components/NotificationTag/NotificationTag.test.tsx +70 -0
- package/src/components/NotificationTag/NotificationTag.tsx +32 -0
- package/src/components/NotificationTag/index.ts +1 -0
- package/src/components/NotificationTag/types.ts +5 -0
- package/src/components/PageHeader/PageHeader.tsx +3 -2
- package/src/components/PageMetadata/PageMetadata.tsx +5 -4
- package/src/components/Pagination/Pagination.test.tsx +20 -0
- package/src/components/Pagination/Pagination.tsx +7 -5
- package/src/components/PhaseBanner/PhaseBanner.tsx +3 -2
- package/src/components/Question/Question.tsx +3 -2
- package/src/components/Question/types.ts +2 -2
- package/src/components/RadioButton/RadioButton.test.tsx +30 -0
- package/src/components/RadioButton/RadioButton.tsx +3 -3
- package/src/components/RadioButton/RadioGroup.tsx +3 -2
- package/src/components/SearchFacets/SearchFacets.stories.tsx +1 -1
- package/src/components/SearchFacets/SearchFacets.tsx +3 -2
- package/src/components/SearchResult/SearchResult.stories.tsx +14 -13
- package/src/components/SearchResult/SearchResult.test.tsx +5 -4
- package/src/components/SearchResult/SearchResult.tsx +6 -7
- package/src/components/SearchSort/SearchSort.tsx +3 -2
- package/src/components/Select/Select.test.tsx +42 -0
- package/src/components/Select/Select.tsx +3 -2
- package/src/components/SequentialNavigation/SequentialNavigation.tsx +7 -6
- package/src/components/SideNavigation/SideNavigation.test.tsx +24 -0
- package/src/components/SideNavigation/SideNavigation.tsx +10 -7
- package/src/components/SiteFooter/SiteFooter.tsx +3 -2
- package/src/components/SiteHeader/SiteHeader.test.tsx +29 -16
- package/src/components/SiteHeader/SiteHeader.tsx +1 -1
- package/src/components/SiteNavigation/SiteNavigation.test.tsx +16 -1
- package/src/components/SiteNavigation/SiteNavigation.tsx +9 -4
- package/src/components/SiteSearch/SiteSearch.test.tsx +22 -0
- package/src/components/SiteSearch/SiteSearch.tsx +10 -9
- package/src/components/SiteSearch/types.ts +7 -1
- package/src/components/SkipLinks/SkipLinks.tsx +4 -4
- package/src/components/SummaryCard/SummaryCard.tsx +3 -2
- package/src/components/SummaryList/SummaryList.tsx +3 -3
- package/src/components/Table/Table.test.tsx +36 -0
- package/src/components/Table/Table.tsx +5 -4
- package/src/components/Tabs/Tabs.test.tsx +14 -0
- package/src/components/Tabs/Tabs.tsx +6 -5
- package/src/components/Tag/Tag.tsx +4 -3
- package/src/components/TaskList/TaskList.tsx +5 -4
- package/src/components/TextInput/TextInput.test.tsx +53 -1
- package/src/components/TextInput/TextInput.tsx +12 -7
- package/src/components/Textarea/Textarea.test.tsx +53 -1
- package/src/components/Textarea/Textarea.tsx +5 -4
- package/src/components/WarningText/WarningText.tsx +4 -2
- package/src/hooks/useTracking/useTracking.ts +0 -1
- package/src/shared-types.ts +3 -3
- package/static/images/illustration.svg +502 -0
- package/tsconfig.json +0 -3
- package/vite.config.ts +4 -0
|
@@ -134,6 +134,48 @@ test('select with change function', () => {
|
|
|
134
134
|
expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
test('select with onBlur that is not a function', () => {
|
|
138
|
+
render(
|
|
139
|
+
<Select
|
|
140
|
+
id={SELECT_ID}
|
|
141
|
+
label={LABEL_TEXT}
|
|
142
|
+
// @ts-expect-error onBlur is not a function
|
|
143
|
+
onBlur='foo'
|
|
144
|
+
>
|
|
145
|
+
{OPTIONS}
|
|
146
|
+
</Select>
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const select = screen.getByRole('combobox');
|
|
150
|
+
|
|
151
|
+
fireEvent.blur(select);
|
|
152
|
+
|
|
153
|
+
// todo: assertion
|
|
154
|
+
// success indicated by no errors thrown
|
|
155
|
+
// error would be thrown on an untestable thread
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('select with onChange that is not a function', () => {
|
|
159
|
+
render(
|
|
160
|
+
<Select
|
|
161
|
+
id={SELECT_ID}
|
|
162
|
+
label={LABEL_TEXT}
|
|
163
|
+
// @ts-expect-error onChange is not a function
|
|
164
|
+
onChange='foo'
|
|
165
|
+
>
|
|
166
|
+
{OPTIONS}
|
|
167
|
+
</Select>
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const select = screen.getByRole('combobox');
|
|
171
|
+
|
|
172
|
+
fireEvent.change(select, {target: {value: 'button'}});
|
|
173
|
+
|
|
174
|
+
// todo: assertion
|
|
175
|
+
// success indicated by no errors thrown
|
|
176
|
+
// error would be thrown on an untestable thread
|
|
177
|
+
});
|
|
178
|
+
|
|
137
179
|
test('select with placeholder option', () => {
|
|
138
180
|
const PLACEHOLDER_TEXT = 'foo';
|
|
139
181
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ErrorMessage from '../ErrorMessage';
|
|
2
2
|
import HintText from '../../common/HintText';
|
|
3
3
|
import { SelectProps } from './types';
|
|
4
|
+
import clsx from 'clsx';
|
|
4
5
|
|
|
5
6
|
const Select = function ({
|
|
6
7
|
children,
|
|
@@ -43,12 +44,12 @@ const Select = function ({
|
|
|
43
44
|
{hintText && <HintText id={hintTextId}>{hintText}</HintText>}
|
|
44
45
|
{errorMessage && <ErrorMessage id={errorMessageId}>{errorMessage}</ErrorMessage>}
|
|
45
46
|
<div
|
|
46
|
-
className={[
|
|
47
|
+
className={clsx([
|
|
47
48
|
"ds_select-wrapper",
|
|
48
49
|
hasError && 'ds_input--error',
|
|
49
50
|
width && `ds_input--${width}`,
|
|
50
51
|
className
|
|
51
|
-
]
|
|
52
|
+
])}
|
|
52
53
|
{...props}
|
|
53
54
|
>
|
|
54
55
|
<select
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SequentialNavigationLinkProps, SequentialNavigationProps } from "./types";
|
|
2
|
+
import clsx from 'clsx';
|
|
2
3
|
|
|
3
4
|
const SeqNavLink = ({
|
|
4
5
|
children,
|
|
@@ -7,15 +8,15 @@ const SeqNavLink = ({
|
|
|
7
8
|
linkComponent,
|
|
8
9
|
textLabel
|
|
9
10
|
}:SequentialNavigationLinkProps) => {
|
|
10
|
-
const LINK_CLASSES = [
|
|
11
|
+
const LINK_CLASSES = clsx([
|
|
11
12
|
'ds_sequential-nav__button',
|
|
12
13
|
isPrev ? 'ds_sequential-nav__button--left' : 'ds_sequential-nav__button--right'
|
|
13
|
-
]
|
|
14
|
+
]);
|
|
14
15
|
|
|
15
|
-
const ITEM_CLASSES = [
|
|
16
|
+
const ITEM_CLASSES = clsx([
|
|
16
17
|
'ds_sequential-nav__item',
|
|
17
18
|
isPrev ? 'ds_sequential-nav__item--prev' : 'ds_sequential-nav__item--next'
|
|
18
|
-
]
|
|
19
|
+
]);
|
|
19
20
|
|
|
20
21
|
function processChildren(children: React.ReactNode) {
|
|
21
22
|
const linkInner = <span className="ds_sequential-nav__text" data-label={textLabel}>{children}</span>
|
|
@@ -62,10 +63,10 @@ const SequentialNavigation = ({
|
|
|
62
63
|
}: SequentialNavigationProps) => {
|
|
63
64
|
return (
|
|
64
65
|
<nav
|
|
65
|
-
className={[
|
|
66
|
+
className={clsx([
|
|
66
67
|
'ds_sequential-nav',
|
|
67
68
|
className
|
|
68
|
-
]
|
|
69
|
+
])}
|
|
69
70
|
aria-label={ariaLabel}
|
|
70
71
|
{...props}
|
|
71
72
|
>
|
|
@@ -109,6 +109,30 @@ test('side nav link with custom element', () => {
|
|
|
109
109
|
expect(link?.textContent).toEqual(LINK_TEXT);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
test('instantiating/initialising DS component script', () => {
|
|
113
|
+
render(
|
|
114
|
+
<SideNavigation>
|
|
115
|
+
<SideNavigation.List>
|
|
116
|
+
<SideNavigation.Item href="#dates" title="Dates"/>
|
|
117
|
+
</SideNavigation.List>
|
|
118
|
+
</SideNavigation>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const sideNavigation = screen.getByRole('navigation');
|
|
122
|
+
expect(sideNavigation).toHaveClass('js-initialised');
|
|
123
|
+
expect(sideNavigation).toHaveClass('js-instantiated');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('instantiating/initialising DS component script: no children', () => {
|
|
127
|
+
render(
|
|
128
|
+
<SideNavigation />
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const sideNavigation = screen.getByRole('navigation');
|
|
132
|
+
expect(sideNavigation).not.toHaveClass('js-initialised');
|
|
133
|
+
expect(sideNavigation).not.toHaveClass('js-instantiated');
|
|
134
|
+
});
|
|
135
|
+
|
|
112
136
|
test('passing additional props', () => {
|
|
113
137
|
render(
|
|
114
138
|
<SideNavigation data-test="foo" />
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
// @ts-expect-error no types from core SGDS
|
|
3
2
|
import DSSideNavigation from '@scottish-government/design-system/src/components/side-navigation/side-navigation';
|
|
4
3
|
import { SideNavigationItemProps, SideNavigationListProps, SideNavigationProps } from './types';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
const SideNavigationList = function ({
|
|
7
7
|
children,
|
|
@@ -27,10 +27,10 @@ const SideNavigationItem = function ({
|
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
29
|
<li
|
|
30
|
-
className={[
|
|
30
|
+
className={clsx([
|
|
31
31
|
'ds_side-navigation__item',
|
|
32
32
|
children && 'ds_side-navigation__item--has-children'
|
|
33
|
-
]
|
|
33
|
+
])}
|
|
34
34
|
>
|
|
35
35
|
{isCurrent ?
|
|
36
36
|
<span className={LINK_CLASS + ' ds_current'}>{title}</span> :
|
|
@@ -52,18 +52,21 @@ const SideNavigation = function ({
|
|
|
52
52
|
const ref = useRef(null);
|
|
53
53
|
|
|
54
54
|
useEffect(() => {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
/* istanbul ignore else */
|
|
56
|
+
if (ref.current) {
|
|
57
|
+
if (children) {
|
|
58
|
+
new DSSideNavigation(ref.current).init();
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
}, [ref]);
|
|
59
62
|
|
|
60
63
|
return (
|
|
61
64
|
<nav
|
|
62
65
|
aria-label={ariaLabel}
|
|
63
|
-
className={[
|
|
66
|
+
className={clsx([
|
|
64
67
|
'ds_side-navigation',
|
|
65
68
|
className
|
|
66
|
-
]
|
|
69
|
+
])}
|
|
67
70
|
data-module="ds-side-navigation"
|
|
68
71
|
ref={ref}
|
|
69
72
|
{...props}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { Children } from 'react';
|
|
2
2
|
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
3
3
|
import { SiteFooterLicenseProps, SiteFooterLinkProps, SiteFooterOrgProps, SiteFooterProps } from './types';
|
|
4
|
+
import clsx from 'clsx';
|
|
4
5
|
|
|
5
6
|
const License = ({
|
|
6
7
|
children,
|
|
@@ -79,10 +80,10 @@ const SiteFooter = ({
|
|
|
79
80
|
}: SiteFooterProps) => {
|
|
80
81
|
return (
|
|
81
82
|
<footer
|
|
82
|
-
className={[
|
|
83
|
+
className={clsx([
|
|
83
84
|
"ds_site-footer",
|
|
84
85
|
className
|
|
85
|
-
]
|
|
86
|
+
])}
|
|
86
87
|
{...props}
|
|
87
88
|
>
|
|
88
89
|
<div className="ds_wrapper">
|
|
@@ -5,6 +5,17 @@ import SiteNavigation from '../SiteNavigation';
|
|
|
5
5
|
import SiteSearch from '../SiteSearch';
|
|
6
6
|
import PhaseBanner from '../PhaseBanner';
|
|
7
7
|
|
|
8
|
+
const NAVIGATION_ITEMS = (
|
|
9
|
+
<>
|
|
10
|
+
<SiteNavigation.Item href="#about">About</SiteNavigation.Item>
|
|
11
|
+
<SiteNavigation.Item href="#get-started">Get started</SiteNavigation.Item>
|
|
12
|
+
<SiteNavigation.Item href="#styles">Styles</SiteNavigation.Item>
|
|
13
|
+
<SiteNavigation.Item href="#components" isCurrent>Components</SiteNavigation.Item>
|
|
14
|
+
<SiteNavigation.Item href="#patterns">Patterns</SiteNavigation.Item>
|
|
15
|
+
<SiteNavigation.Item href="#guidance">Guidance</SiteNavigation.Item>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
|
|
8
19
|
test('site header renders correctly (maximal, testing markup structure)', () => {
|
|
9
20
|
render(
|
|
10
21
|
<SiteHeader>
|
|
@@ -13,12 +24,7 @@ test('site header renders correctly (maximal, testing markup structure)', () =>
|
|
|
13
24
|
</SiteHeader.Brand>
|
|
14
25
|
<SiteHeader.Navigation>
|
|
15
26
|
<SiteNavigation>
|
|
16
|
-
|
|
17
|
-
<SiteNavigation.Item href="#get-started">Get started</SiteNavigation.Item>
|
|
18
|
-
<SiteNavigation.Item href="#styles">Styles</SiteNavigation.Item>
|
|
19
|
-
<SiteNavigation.Item href="#components" current>Components</SiteNavigation.Item>
|
|
20
|
-
<SiteNavigation.Item href="#patterns">Patterns</SiteNavigation.Item>
|
|
21
|
-
<SiteNavigation.Item href="#guidance">Guidance</SiteNavigation.Item>
|
|
27
|
+
{NAVIGATION_ITEMS}
|
|
22
28
|
</SiteNavigation>
|
|
23
29
|
</SiteHeader.Navigation>
|
|
24
30
|
<SiteHeader.Search>
|
|
@@ -155,16 +161,7 @@ test('site header logo link link with custom element', () => {
|
|
|
155
161
|
});
|
|
156
162
|
|
|
157
163
|
test('site header with site navigation', () => {
|
|
158
|
-
|
|
159
|
-
<>
|
|
160
|
-
<SiteNavigation.Item href="#about">About</SiteNavigation.Item>
|
|
161
|
-
<SiteNavigation.Item href="#get-started">Get started</SiteNavigation.Item>
|
|
162
|
-
<SiteNavigation.Item href="#styles">Styles</SiteNavigation.Item>
|
|
163
|
-
<SiteNavigation.Item href="#components" current>Components</SiteNavigation.Item>
|
|
164
|
-
<SiteNavigation.Item href="#patterns">Patterns</SiteNavigation.Item>
|
|
165
|
-
<SiteNavigation.Item href="#guidance">Guidance</SiteNavigation.Item>
|
|
166
|
-
</>
|
|
167
|
-
);
|
|
164
|
+
|
|
168
165
|
|
|
169
166
|
render(
|
|
170
167
|
<>
|
|
@@ -240,6 +237,22 @@ test('site header with phase banner', () => {
|
|
|
240
237
|
expect(siteHeaderPhaseBanner?.innerHTML).toEqual(phaseBannerReference.innerHTML);
|
|
241
238
|
});
|
|
242
239
|
|
|
240
|
+
test('instantiating/initialising DS component script', () => {
|
|
241
|
+
render(
|
|
242
|
+
<SiteHeader>
|
|
243
|
+
<SiteHeader.Navigation>
|
|
244
|
+
<SiteNavigation>
|
|
245
|
+
{NAVIGATION_ITEMS}
|
|
246
|
+
</SiteNavigation>
|
|
247
|
+
</SiteHeader.Navigation>
|
|
248
|
+
</SiteHeader>
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const mobileNav = screen.getAllByRole('navigation')[0];
|
|
252
|
+
expect(mobileNav).toHaveClass('js-initialised');
|
|
253
|
+
expect(mobileNav).toHaveClass('js-instantiated');
|
|
254
|
+
});
|
|
255
|
+
|
|
243
256
|
test('passing additional props', () => {
|
|
244
257
|
render(
|
|
245
258
|
<SiteHeader data-test="foo" />
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { Children, useEffect, useRef } from 'react';
|
|
2
2
|
import Icon from '../../common/Icon';
|
|
3
3
|
import SiteNavigation from '../SiteNavigation';
|
|
4
|
-
// @ts-expect-error no types from core SGDS
|
|
5
4
|
import DSMobileMenu from '@scottish-government/design-system/src/components/site-navigation/site-navigation';
|
|
6
5
|
import { SiteHeaderBrandProps, SiteHeaderProps } from './types';
|
|
7
6
|
import { SiteNavigationProps } from '../SiteNavigation/types';
|
|
@@ -84,6 +83,7 @@ const SiteHeader = ({
|
|
|
84
83
|
});
|
|
85
84
|
|
|
86
85
|
useEffect(() => {
|
|
86
|
+
/* istanbul ignore else */
|
|
87
87
|
if (mobileMenuRef.current) {
|
|
88
88
|
new DSMobileMenu(mobileMenuRef.current).init();
|
|
89
89
|
}
|
|
@@ -45,7 +45,7 @@ test('site navigation link renders correctly', () => {
|
|
|
45
45
|
expect(link).toHaveAttribute('href', LINK_HREF)
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
test('site navigation
|
|
48
|
+
test('site navigation item with custom link element', () => {
|
|
49
49
|
render(
|
|
50
50
|
<SiteNavigation.Item href={LINK_HREF} linkComponent={
|
|
51
51
|
({ className, ...props }) => (
|
|
@@ -62,6 +62,21 @@ test('site navigation link with custom element', () => {
|
|
|
62
62
|
expect(link?.textContent).toEqual(LINK_TEXT);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
test('site navigation item without href', () => {
|
|
66
|
+
render(
|
|
67
|
+
// @ts-expect-error required prop missing
|
|
68
|
+
<SiteNavigation.Item>
|
|
69
|
+
{LINK_TEXT}
|
|
70
|
+
</SiteNavigation.Item>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const item = screen.getByRole('listitem');
|
|
74
|
+
const link = within(item).queryByRole('link');
|
|
75
|
+
|
|
76
|
+
expect(link).not.toBeInTheDocument();
|
|
77
|
+
expect(item.textContent).toEqual(LINK_TEXT);
|
|
78
|
+
});
|
|
79
|
+
|
|
65
80
|
test('highlights current item', () => {
|
|
66
81
|
render(
|
|
67
82
|
<SiteNavigation.Item href={LINK_HREF} isCurrent>{LINK_TEXT}</SiteNavigation.Item>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SiteNavigationItemProps, SiteNavigationProps } from "./types";
|
|
2
|
+
import clsx from 'clsx';
|
|
2
3
|
|
|
3
4
|
const Item = ({
|
|
4
5
|
children,
|
|
@@ -14,11 +15,15 @@ const Item = ({
|
|
|
14
15
|
ariaCurrent = 'page';
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
const classNamesString = clsx(classNames);
|
|
19
|
+
|
|
17
20
|
function processChildren(children: React.ReactNode) {
|
|
18
21
|
if (linkComponent) {
|
|
19
|
-
return linkComponent({ className:
|
|
22
|
+
return linkComponent({ className: classNamesString, href, children });
|
|
20
23
|
} else if (href) {
|
|
21
|
-
return <a href={href} aria-current={ariaCurrent ? ariaCurrent : undefined} className={
|
|
24
|
+
return <a href={href} aria-current={ariaCurrent ? ariaCurrent : undefined} className={classNamesString}>{children}</a>;
|
|
25
|
+
} else {
|
|
26
|
+
return <span className={classNamesString}>{children}</span>;
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -38,10 +43,10 @@ const SiteNavigation = ({
|
|
|
38
43
|
}: SiteNavigationProps) => {
|
|
39
44
|
return (
|
|
40
45
|
<nav
|
|
41
|
-
className={[
|
|
46
|
+
className={clsx([
|
|
42
47
|
'ds_site-navigation',
|
|
43
48
|
className
|
|
44
|
-
]
|
|
49
|
+
])}
|
|
45
50
|
{...props}
|
|
46
51
|
>
|
|
47
52
|
<ul className="ds_site-navigation__list">
|
|
@@ -142,6 +142,28 @@ test('autocomplete', () => {
|
|
|
142
142
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
+
test('instantiating/initialising DS component script: autocomplete', () => {
|
|
146
|
+
render(
|
|
147
|
+
<SiteSearch autocompleteEndpoint="/endpoint" />
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const searchForm = screen.getByRole('search');
|
|
151
|
+
const searchFormContainer = searchForm.parentElement;
|
|
152
|
+
expect(searchFormContainer).toHaveClass('js-initialised');
|
|
153
|
+
expect(searchFormContainer).toHaveClass('js-instantiated');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('instantiating/initialising DS component script: no autocomplete', () => {
|
|
157
|
+
render(
|
|
158
|
+
<SiteSearch />
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const searchForm = screen.getByRole('search');
|
|
162
|
+
const searchFormContainer = searchForm.parentElement;
|
|
163
|
+
expect(searchFormContainer).not.toHaveClass('js-initialised');
|
|
164
|
+
expect(searchFormContainer).not.toHaveClass('js-instantiated');
|
|
165
|
+
});
|
|
166
|
+
|
|
145
167
|
test('passing additional props', () => {
|
|
146
168
|
render(
|
|
147
169
|
<SiteSearch data-test="foo" />
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
// @ts-expect-error no types from core SGDS
|
|
3
2
|
import DSAutocomplete from '@scottish-government/design-system/src/components/autocomplete/autocomplete';
|
|
4
3
|
import Button from '../Button';
|
|
5
4
|
import { SiteSearchProps, SuggestionMappingFunctionProps } from './types';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
6
|
|
|
7
7
|
const SiteSearch = function ({
|
|
8
8
|
action = '/search',
|
|
@@ -27,7 +27,8 @@ const SiteSearch = function ({
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
useEffect(() => {
|
|
30
|
-
|
|
30
|
+
const autocompleteElement = document.getElementById(autocompleteId);
|
|
31
|
+
if (hasAutocomplete && autocompleteElement && ref.current) {
|
|
31
32
|
const options: AutoCompleteOptions = {};
|
|
32
33
|
if (minLength) {
|
|
33
34
|
options.minLength = minLength;
|
|
@@ -37,7 +38,7 @@ const SiteSearch = function ({
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
const autocomplete = new DSAutocomplete(
|
|
40
|
-
|
|
41
|
+
autocompleteElement,
|
|
41
42
|
autocompleteEndpoint,
|
|
42
43
|
options
|
|
43
44
|
);
|
|
@@ -48,11 +49,11 @@ const SiteSearch = function ({
|
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
51
|
<div
|
|
51
|
-
className={[
|
|
52
|
+
className={clsx([
|
|
52
53
|
'ds_site-search',
|
|
53
54
|
className,
|
|
54
|
-
hasAutocomplete
|
|
55
|
-
]
|
|
55
|
+
hasAutocomplete && 'ds_autocomplete'
|
|
56
|
+
])}
|
|
56
57
|
id={autocompleteId ? autocompleteId : undefined}
|
|
57
58
|
ref={ref}
|
|
58
59
|
{...props}
|
|
@@ -69,11 +70,11 @@ const SiteSearch = function ({
|
|
|
69
70
|
<input aria-autocomplete={hasAutocomplete ? 'list' : undefined}
|
|
70
71
|
aria-owns={hasAutocomplete ? 'autocomplete-suggestions' : undefined}
|
|
71
72
|
autoComplete={hasAutocomplete ? 'off' : undefined}
|
|
72
|
-
className={[
|
|
73
|
+
className={clsx([
|
|
73
74
|
'ds_input',
|
|
74
75
|
'ds_site-search__input',
|
|
75
|
-
hasAutocomplete
|
|
76
|
-
]
|
|
76
|
+
hasAutocomplete && 'js-autocomplete-input'
|
|
77
|
+
])}
|
|
77
78
|
id={id}
|
|
78
79
|
name={name}
|
|
79
80
|
placeholder={placeholder}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
type FormMethods = 'GET' | 'POST';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export type Suggestion = {
|
|
4
|
+
displayText: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type SuggestionMappingFunctionProps = (suggestions: object[]) => Suggestion[];
|
|
3
9
|
|
|
4
10
|
export interface SiteSearchProps extends React.AllHTMLAttributes<HTMLInputElement> {
|
|
5
11
|
action?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
// @ts-expect-error no types from core SGDS
|
|
3
2
|
import dsSkipLinks from '@scottish-government/design-system/src/components/skip-links/skip-links';
|
|
4
3
|
import { SkipLinksLinkProps, SkipLinksProps } from './types';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
const Link = ({
|
|
7
7
|
children,
|
|
@@ -30,10 +30,10 @@ const SkipLinks = ({
|
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<div
|
|
33
|
-
className={[
|
|
33
|
+
className={clsx([
|
|
34
34
|
'ds_skip-links',
|
|
35
|
-
isStatic && 'ds_skip-links--static'
|
|
36
|
-
]
|
|
35
|
+
isStatic && 'ds_skip-links--static'
|
|
36
|
+
])}
|
|
37
37
|
{...props}
|
|
38
38
|
>
|
|
39
39
|
<ul className="ds_skip-links__list">
|
|
@@ -5,6 +5,7 @@ import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
|
5
5
|
import WrapperTag from "../../common/WrapperTag";
|
|
6
6
|
import { SummaryCardProps } from './types';
|
|
7
7
|
import { ActionLinkProps } from '../../common/ActionLink/types';
|
|
8
|
+
import clsx from 'clsx';
|
|
8
9
|
|
|
9
10
|
const SummaryCard = ({
|
|
10
11
|
children,
|
|
@@ -29,10 +30,10 @@ const SummaryCard = ({
|
|
|
29
30
|
|
|
30
31
|
return (
|
|
31
32
|
<div
|
|
32
|
-
className={[
|
|
33
|
+
className={clsx([
|
|
33
34
|
'ds_summary-card',
|
|
34
35
|
className
|
|
35
|
-
]
|
|
36
|
+
])}
|
|
36
37
|
{...props}
|
|
37
38
|
>
|
|
38
39
|
<div className="ds_summary-card__header">
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { Children, useId } from 'react';
|
|
2
|
-
|
|
3
2
|
import ActionLink from '../../common/ActionLink';
|
|
4
3
|
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
5
4
|
import { SummaryListItemProps, SummaryListProps } from './types';
|
|
6
5
|
import { ActionLinkProps } from '@/src/common/ActionLink/types';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
7
|
|
|
8
8
|
const Item = ({
|
|
9
9
|
children,
|
|
@@ -80,11 +80,11 @@ const SummaryList = ({
|
|
|
80
80
|
}: SummaryListProps) => {
|
|
81
81
|
return (
|
|
82
82
|
<ol
|
|
83
|
-
className={[
|
|
83
|
+
className={clsx([
|
|
84
84
|
'ds_summary-list',
|
|
85
85
|
isBorderless && 'ds_summary-list--no-border',
|
|
86
86
|
className
|
|
87
|
-
]
|
|
87
|
+
])}
|
|
88
88
|
{...props}
|
|
89
89
|
>
|
|
90
90
|
{children}
|
|
@@ -58,6 +58,42 @@ test('table with smallscreen behaviour', () => {
|
|
|
58
58
|
expect(table.nodeName).toEqual('TABLE');
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
test('instantiating/initialising DS component script: smallscreen', () => {
|
|
62
|
+
render(
|
|
63
|
+
<Table smallscreen="scrolling">
|
|
64
|
+
<caption>Public holidays in 2020</caption>
|
|
65
|
+
<thead>
|
|
66
|
+
<tr>
|
|
67
|
+
<th scope="col">Date</th>
|
|
68
|
+
<th scope="col">Day</th>
|
|
69
|
+
<th scope="col">Holiday</th>
|
|
70
|
+
</tr>
|
|
71
|
+
</thead>
|
|
72
|
+
<tbody>
|
|
73
|
+
<tr>
|
|
74
|
+
<td>10 April</td>
|
|
75
|
+
<td>Friday</td>
|
|
76
|
+
<td>Good Friday</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</tbody>
|
|
79
|
+
</Table>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const table = screen.getByRole('table');
|
|
83
|
+
expect(table).toHaveClass('js-initialised');
|
|
84
|
+
expect(table).toHaveClass('js-instantiated');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('instantiating/initialising DS component script: not smallscreen', () => {
|
|
88
|
+
render(
|
|
89
|
+
<Table />
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const table = screen.getByRole('table');
|
|
93
|
+
expect(table).not.toHaveClass('js-initialised');
|
|
94
|
+
expect(table).not.toHaveClass('js-instantiated');
|
|
95
|
+
});
|
|
96
|
+
|
|
61
97
|
test('passing additional props', () => {
|
|
62
98
|
render(
|
|
63
99
|
<Table data-test="foo"/>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
// @ts-expect-error no types from core SGDS
|
|
3
2
|
import DSTable from '@scottish-government/design-system/src/components/table/table';
|
|
4
3
|
import { TableProps } from './types';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
const Table = ({
|
|
7
7
|
children,
|
|
@@ -12,17 +12,18 @@ const Table = ({
|
|
|
12
12
|
const ref = useRef(null);
|
|
13
13
|
|
|
14
14
|
useEffect(() => {
|
|
15
|
+
/* istanbul ignore else */
|
|
15
16
|
if (ref.current) {
|
|
16
|
-
new DSTable().init();
|
|
17
|
+
new DSTable(ref.current).init();
|
|
17
18
|
}
|
|
18
19
|
}, [ref]);
|
|
19
20
|
|
|
20
21
|
return (
|
|
21
22
|
<table
|
|
22
|
-
className={[
|
|
23
|
+
className={clsx([
|
|
23
24
|
'ds_table',
|
|
24
25
|
className
|
|
25
|
-
]
|
|
26
|
+
])}
|
|
26
27
|
data-smallscreen={smallscreen}
|
|
27
28
|
ref={ref}
|
|
28
29
|
{...props}
|
|
@@ -187,6 +187,20 @@ test('with manual activation', () => {
|
|
|
187
187
|
expect(tabContainer).toHaveClass('ds_tabs--manual');
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
+
test('instantiating/initialising DS component script', () => {
|
|
191
|
+
render(
|
|
192
|
+
<Tabs data-testid="tabcontainer" data-test="foo">
|
|
193
|
+
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
194
|
+
<div data-testid="tabpanel1content">Content one</div>
|
|
195
|
+
</Tabs.Item>
|
|
196
|
+
</Tabs>
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const tabContainer = screen.getByTestId('tabcontainer');
|
|
200
|
+
expect(tabContainer).toHaveClass('js-initialised');
|
|
201
|
+
expect(tabContainer).toHaveClass('js-instantiated');
|
|
202
|
+
});
|
|
203
|
+
|
|
190
204
|
test('passing additional props to tab container', () => {
|
|
191
205
|
render(
|
|
192
206
|
<Tabs data-testid="tabcontainer" data-test="foo">
|