@scottish-government/designsystem-react 0.8.0 → 0.10.0-beta.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 +20 -0
- package/.storybook/manager.ts +13 -0
- package/.storybook/preview-head.html +1 -0
- package/.storybook/preview.tsx +56 -0
- package/.storybook/sgdsArgTypes.ts +123 -0
- package/.storybook/sgdsTheme.ts +9 -0
- package/.storybook/vitest.setup.ts +7 -0
- package/@types/common/AbstractNotificationBanner.d.ts +2 -2
- package/@types/common/ActionLink.d.ts +1 -1
- package/@types/common/Icon.d.ts +1 -1
- package/@types/components/Accordion.d.ts +2 -3
- package/@types/components/Button.d.ts +5 -5
- package/@types/components/CategoryItem.d.ts +10 -0
- package/@types/components/CategoryList.d.ts +7 -0
- package/@types/components/Checkbox.d.ts +2 -2
- package/@types/components/ContentsNav.d.ts +1 -1
- package/@types/components/DatePicker.d.ts +1 -1
- package/@types/components/ErrorMessage.d.ts +1 -2
- package/@types/components/ErrorSummary.d.ts +1 -1
- package/@types/components/FileDownload.d.ts +2 -2
- package/@types/components/Metadata.d.ts +1 -1
- package/@types/components/Pagination.d.ts +1 -1
- package/@types/components/RadioButton.d.ts +2 -2
- package/@types/components/SideNavigation.d.ts +1 -1
- package/@types/components/SiteNavigation.d.ts +1 -1
- package/@types/components/SummaryList.d.ts +1 -1
- package/@types/components/Tabs.d.ts +3 -3
- package/@types/components/TextInput.d.ts +1 -1
- package/@types/sgds.d.ts +2 -1
- package/CHANGELOG.md +29 -0
- package/dist/common/AbstractNotificationBanner.jsx +4 -4
- package/dist/common/Icon.jsx +2 -2
- package/dist/components/Accordion/Accordion.jsx +8 -7
- package/dist/components/Button/Button.jsx +6 -6
- package/dist/components/CategoryItem/CategoryItem.jsx +35 -0
- package/dist/components/CategoryList/CategoryList.jsx +55 -0
- package/dist/components/Checkbox/Checkbox.jsx +7 -4
- package/dist/components/Checkbox/CheckboxGroup.jsx +5 -11
- package/dist/components/ContentsNav/ContentsNav.jsx +2 -2
- package/dist/components/DatePicker/DatePicker.jsx +1 -1
- package/dist/components/ErrorMessage/ErrorMessage.jsx +3 -3
- package/dist/components/FileDownload/FileDownload.jsx +2 -2
- package/dist/components/NotificationBanner/NotificationBanner.jsx +2 -2
- package/dist/components/PageMetadata/PageMetadata.jsx +4 -4
- package/dist/components/Pagination/Pagination.jsx +4 -4
- package/dist/components/Question/Question.jsx +1 -1
- package/dist/components/RadioButton/RadioButton.jsx +6 -2
- package/dist/components/RadioButton/RadioGroup.jsx +7 -47
- package/dist/components/Select/Select.jsx +1 -1
- package/dist/components/SideNavigation/SideNavigation.jsx +2 -2
- package/dist/components/SiteHeader/SiteHeader.jsx +3 -3
- package/dist/components/SiteNavigation/SiteNavigation.jsx +2 -2
- package/dist/components/SiteSearch/SiteSearch.jsx +1 -1
- package/dist/components/SkipLinks/SkipLinks.jsx +1 -1
- package/dist/components/SummaryList/SummaryList.jsx +3 -3
- package/dist/components/Tabs/Tabs.jsx +6 -7
- package/dist/components/TextInput/TextInput.jsx +5 -5
- package/dist/components/Textarea/Textarea.jsx +1 -1
- package/dist/hooks/useTracking.js +21 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/context.js +5 -0
- package/package.json +15 -4
- package/src/common/AbstractNotificationBanner.test.tsx +1 -1
- package/src/common/AbstractNotificationBanner.tsx +4 -4
- package/src/common/Icon.test.tsx +1 -1
- package/src/common/Icon.tsx +2 -2
- package/src/components/Accordion/Accordion.stories.tsx +111 -0
- package/src/components/Accordion/Accordion.test.tsx +5 -17
- package/src/components/Accordion/Accordion.tsx +11 -10
- package/src/components/AspectBox/AspectBox.stories.tsx +64 -0
- package/src/components/BackToTop/BackToTop.stories.tsx +36 -0
- package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +49 -0
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -1
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/components/Button/Button.stories.tsx +194 -0
- package/src/components/Button/Button.test.tsx +4 -4
- package/src/components/Button/Button.tsx +9 -9
- package/src/components/CategoryItem/CategoryItem.stories.tsx +55 -0
- package/src/components/CategoryItem/CategoryItem.test.tsx +93 -0
- package/src/components/CategoryItem/CategoryItem.tsx +56 -0
- package/src/components/CategoryList/CategoryList.stories.tsx +65 -0
- package/src/components/CategoryList/CategoryList.test.tsx +59 -0
- package/src/components/CategoryList/CategoryList.tsx +33 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +85 -0
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Checkbox/Checkbox.tsx +11 -6
- package/src/components/Checkbox/CheckboxGroup.stories.tsx +68 -0
- package/src/components/Checkbox/CheckboxGroup.tsx +7 -12
- package/src/components/ConfirmationMessage/ConfirmationMessage.stories.tsx +38 -0
- package/src/components/ContentsNav/ContentsNav.stories.tsx +43 -0
- package/src/components/ContentsNav/ContentsNav.test.tsx +2 -2
- package/src/components/ContentsNav/ContentsNav.tsx +2 -2
- package/src/components/CookieBanner/CookieBanner.stories.tsx +33 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +113 -0
- package/src/components/DatePicker/DatePicker.tsx +1 -1
- package/src/components/Details/Details.stories.tsx +36 -0
- package/src/components/ErrorMessage/ErrorMessage.stories.tsx +19 -0
- package/src/components/ErrorMessage/ErrorMessage.test.tsx +3 -15
- package/src/components/ErrorMessage/ErrorMessage.tsx +1 -3
- package/src/components/ErrorSummary/ErrorSummary.stories.tsx +38 -0
- package/src/components/FileDownload/FileDownload.stories.tsx +75 -0
- package/src/components/FileDownload/FileDownload.test.tsx +1 -1
- package/src/components/FileDownload/FileDownload.tsx +2 -2
- package/src/components/HideThisPage/HideThisPage.stories.tsx +20 -0
- package/src/components/InsetText/InsetText.stories.tsx +21 -0
- package/src/components/NotificationBanner/NotificationBanner.stories.tsx +57 -0
- package/src/components/NotificationBanner/NotificationBanner.test.tsx +1 -1
- package/src/components/NotificationBanner/NotificationBanner.tsx +4 -4
- package/src/components/NotificationPanel/NotificationPanel.stories.tsx +32 -0
- package/src/components/PageHeader/PageHeader.stories.tsx +60 -0
- package/src/components/PageMetadata/PageMetadata.stories.tsx +58 -0
- package/src/components/PageMetadata/PageMetadata.test.tsx +2 -2
- package/src/components/PageMetadata/PageMetadata.tsx +4 -4
- package/src/components/Pagination/Pagination.stories.tsx +69 -0
- package/src/components/Pagination/Pagination.test.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +4 -4
- package/src/components/PhaseBanner/PhaseBanner.stories.tsx +38 -0
- package/src/components/Question/Question.stories.tsx +78 -0
- package/src/components/Question/Question.tsx +1 -1
- package/src/components/RadioButton/RadioButton.stories.tsx +67 -0
- package/src/components/RadioButton/RadioButton.test.tsx +2 -1
- package/src/components/RadioButton/RadioButton.tsx +9 -3
- package/src/components/RadioButton/RadioGroup.stories.tsx +77 -0
- package/src/components/RadioButton/RadioGroup.test.tsx +2 -2
- package/src/components/RadioButton/RadioGroup.tsx +8 -15
- package/src/components/Select/Select.stories.tsx +76 -0
- package/src/components/Select/Select.tsx +1 -1
- package/src/components/SequentialNavigation/SequentialNavigation.stories.tsx +31 -0
- package/src/components/SideNavigation/SideNavigation.stories.tsx +92 -0
- package/src/components/SideNavigation/SideNavigation.test.tsx +2 -2
- package/src/components/SideNavigation/SideNavigation.tsx +2 -2
- package/src/components/SiteFooter/SiteFooter.stories.tsx +65 -0
- package/src/components/SiteHeader/SiteHeader.stories.tsx +92 -0
- package/src/components/SiteHeader/SiteHeader.tsx +2 -7
- package/src/components/SiteNavigation/SiteNavigation.stories.tsx +45 -0
- package/src/components/SiteNavigation/SiteNavigation.test.tsx +1 -1
- package/src/components/SiteNavigation/SiteNavigation.tsx +2 -2
- package/src/components/SiteSearch/SiteSearch.stories.tsx +81 -0
- package/src/components/SiteSearch/SiteSearch.tsx +1 -1
- package/src/components/SkipLinks/SkipLinks.stories.tsx +57 -0
- package/src/components/SkipLinks/SkipLinks.tsx +1 -1
- package/src/components/SummaryCard/SummaryCard.stories.tsx +46 -0
- package/src/components/SummaryList/SummaryList.stories.tsx +75 -0
- package/src/components/SummaryList/SummaryList.test.tsx +1 -1
- package/src/components/SummaryList/SummaryList.tsx +3 -3
- package/src/components/Table/Table.stories.tsx +96 -0
- package/src/components/Tabs/Tabs.stories.tsx +90 -0
- package/src/components/Tabs/Tabs.test.tsx +6 -8
- package/src/components/Tabs/Tabs.tsx +8 -9
- package/src/components/Tag/Tag.stories.tsx +25 -0
- package/src/components/TaskList/TaskList.stories.tsx +129 -0
- package/src/components/TextInput/TextInput.stories.tsx +123 -0
- package/src/components/TextInput/TextInput.test.tsx +2 -2
- package/src/components/TextInput/TextInput.tsx +5 -5
- package/src/components/Textarea/Textarea.stories.tsx +71 -0
- package/src/components/Textarea/Textarea.tsx +1 -1
- package/src/components/WarningText/WarningText.stories.tsx +21 -0
- package/src/hooks/useTracking.test.tsx +64 -0
- package/src/hooks/useTracking.ts +19 -0
- package/src/utils/context.ts +3 -0
- package/static/data/autocomplete-dummy-data.json +2361 -0
- package/static/images/highland-cow.jpg +0 -0
- package/static/images/scottish-government--min.svg +11 -0
- package/static/images/scottish-government.svg +6 -0
- package/tsconfig.json +3 -2
- package/vite.config.ts +45 -11
- package/vitest-setup.ts +1 -0
- package/vitest.shims.d.ts +1 -0
- package/src/utils/slugify.ts +0 -13
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import argTypes from '../../../.storybook/sgdsArgTypes';
|
|
3
|
+
|
|
4
|
+
import Textarea from './Textarea';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Textarea',
|
|
8
|
+
component: Textarea,
|
|
9
|
+
argTypes: {
|
|
10
|
+
countThreshold: argTypes.countThreshold(),
|
|
11
|
+
errorMessage: argTypes.errorMessage(),
|
|
12
|
+
hasError: argTypes.hasError(),
|
|
13
|
+
hintText: argTypes.hintText(),
|
|
14
|
+
id: argTypes.id(),
|
|
15
|
+
label: argTypes.label(),
|
|
16
|
+
maxlength: argTypes.maxlength(),
|
|
17
|
+
name: { type: 'string' },
|
|
18
|
+
onBlur: argTypes.onBlur(),
|
|
19
|
+
onChange: argTypes.onChange(),
|
|
20
|
+
placeholder: {type: 'string'},
|
|
21
|
+
rows: {
|
|
22
|
+
type: 'number'
|
|
23
|
+
},
|
|
24
|
+
value: {type: 'string'}
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
id: 'description',
|
|
28
|
+
label: 'Description'
|
|
29
|
+
}
|
|
30
|
+
} satisfies Meta<typeof Textarea>;
|
|
31
|
+
|
|
32
|
+
export default meta;
|
|
33
|
+
type Story = StoryObj<typeof meta>;
|
|
34
|
+
|
|
35
|
+
export const Default: Story = {
|
|
36
|
+
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const KitchenSink: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
defaultValue: 'Nothing seems to do anything when I click on it. I am using Megabrowser 3.8 on an OmniComputer 5000 and I\'ve disabled all of my plugins.\n\nThis problem didn\'t start happening until two weeks ago but now I can\'t use this tool at all.',
|
|
42
|
+
countThreshold: 50,
|
|
43
|
+
errorMessage: 'This field is required',
|
|
44
|
+
hasError: true,
|
|
45
|
+
hintText: 'Please describe the problem you are having',
|
|
46
|
+
id: 'kitchensink',
|
|
47
|
+
maxlength: 200,
|
|
48
|
+
rows: 6
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const Blur: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
onBlur: () => {console.log('textarea blur')}
|
|
55
|
+
},
|
|
56
|
+
play: async ({ canvas, userEvent }) => {
|
|
57
|
+
await userEvent.click(canvas.getByRole('textbox'));
|
|
58
|
+
await userEvent.tab();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const Change: Story = {
|
|
63
|
+
args: {
|
|
64
|
+
onChange: () => {console.log('textarea change')}
|
|
65
|
+
},
|
|
66
|
+
play: async ({ canvas, userEvent }) => {
|
|
67
|
+
await userEvent.click(canvas.getByRole('textbox'));
|
|
68
|
+
await userEvent.type(canvas.getByRole('textbox'),'banana');
|
|
69
|
+
await userEvent.tab();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -55,7 +55,7 @@ const Textarea = ({
|
|
|
55
55
|
>
|
|
56
56
|
<label className="ds_label" htmlFor={id}>{label}</label>
|
|
57
57
|
{hintText && <HintText id={hintTextId} text={hintText} />}
|
|
58
|
-
{errorMessage && <ErrorMessage id={errorMessageId}
|
|
58
|
+
{errorMessage && <ErrorMessage id={errorMessageId}>{errorMessage}</ErrorMessage>}
|
|
59
59
|
|
|
60
60
|
<textarea
|
|
61
61
|
aria-describedby={describedbys.join(' ')}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import argTypes from '../../../.storybook/sgdsArgTypes';
|
|
3
|
+
|
|
4
|
+
import WarningText from './WarningText';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Warning text',
|
|
8
|
+
component: WarningText,
|
|
9
|
+
argTypes: {
|
|
10
|
+
children: argTypes.children()
|
|
11
|
+
}
|
|
12
|
+
} satisfies Meta<typeof WarningText>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const Default: Story = {
|
|
18
|
+
args: {
|
|
19
|
+
children: <p>Call 999 if you or someone else is in immediate danger, or if the crime is in progress.</p>
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { test, expect } from 'vitest';
|
|
5
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
6
|
+
|
|
7
|
+
import useTracking from './useTracking';
|
|
8
|
+
|
|
9
|
+
const Link = ({ children }) => <a href="#">{children}</a>;
|
|
10
|
+
|
|
11
|
+
const Links = () => {
|
|
12
|
+
useTracking();
|
|
13
|
+
const [links, setLinks] = useState<string[]>([]);
|
|
14
|
+
|
|
15
|
+
const addNewLink = () => {
|
|
16
|
+
setLinks((prev) => [...prev, 'Second link']);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
{links.map((link, index) => (
|
|
22
|
+
<Link key={`link-${index}`}>{link}</Link>
|
|
23
|
+
))}
|
|
24
|
+
|
|
25
|
+
<button onClick={addNewLink}>
|
|
26
|
+
Add
|
|
27
|
+
</button>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// basic test to verify the tracking script is having an effect
|
|
33
|
+
test('text tracking on component render', async () => {
|
|
34
|
+
const SECTION_ONE_TEXT = 'Foo';
|
|
35
|
+
const SECTION_TWO_TEXT = 'Bar';
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<>
|
|
39
|
+
<h1>{SECTION_ONE_TEXT}</h1>
|
|
40
|
+
<Link>First link</Link>
|
|
41
|
+
<h1>{SECTION_TWO_TEXT}</h1>
|
|
42
|
+
<Links />
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const button = screen.getByRole('button');
|
|
47
|
+
const firstLink = screen.getByText('First link');
|
|
48
|
+
|
|
49
|
+
// todo: this will fail until the tracking script in DS core is updated to use textContent instead of innerText
|
|
50
|
+
// expect(firstLink).toHaveAttribute('data-section', SECTION_ONE_TEXT);
|
|
51
|
+
|
|
52
|
+
fireEvent(
|
|
53
|
+
button,
|
|
54
|
+
new MouseEvent('click', new MouseEvent('click', {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
cancelable: true,
|
|
57
|
+
})
|
|
58
|
+
));
|
|
59
|
+
|
|
60
|
+
const secondLink = await screen.findByText('Second link')
|
|
61
|
+
|
|
62
|
+
// todo: this will fail until the tracking script in DS core is updated to use textContent instead of innerText
|
|
63
|
+
// expect(secondLink).toHaveAttribute('data-section', SECTION_TWO_TEXT);
|
|
64
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
//@ts-ignore
|
|
4
|
+
import DSTracking from '@scottish-government/design-system/src/base/tools/tracking/tracking';
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const observer = new MutationObserver(() => {
|
|
9
|
+
DSTracking.init();
|
|
10
|
+
});
|
|
11
|
+
DSTracking.init();
|
|
12
|
+
|
|
13
|
+
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
observer.disconnect();
|
|
17
|
+
}
|
|
18
|
+
}, []);
|
|
19
|
+
}
|