@scottish-government/designsystem-react 0.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.
Files changed (111) hide show
  1. package/.editorconfig +12 -0
  2. package/.github/workflows/release-package.yml +96 -0
  3. package/@types/common/ConditionalWrapper.d.ts +6 -0
  4. package/@types/common/HintText.d.ts +6 -0
  5. package/@types/common/Icon.d.ts +11 -0
  6. package/@types/common/ScreenReaderText.d.ts +4 -0
  7. package/@types/common/WrapperTag.d.ts +5 -0
  8. package/@types/components/Accordion.d.ts +15 -0
  9. package/@types/components/AspectBox.d.ts +5 -0
  10. package/@types/components/BackToTop.d.ts +5 -0
  11. package/@types/components/Breadcrumbs.d.ts +14 -0
  12. package/@types/components/Button.d.ts +17 -0
  13. package/@types/components/Checkbox.d.ts +13 -0
  14. package/@types/components/ConfirmationMessage.d.ts +7 -0
  15. package/@types/components/ContentsNav.d.ts +15 -0
  16. package/@types/components/DatePicker.d.ts +19 -0
  17. package/@types/components/Details.d.ts +6 -0
  18. package/@types/components/ErrorMessage.d.ts +6 -0
  19. package/@types/components/Metadata.d.ts +11 -0
  20. package/@types/components/NotificationBanner.d.ts +9 -0
  21. package/@types/components/NotificationPanel.d.ts +7 -0
  22. package/@types/components/PageHeader.d.ts +6 -0
  23. package/@types/components/PhaseBanner.d.ts +5 -0
  24. package/@types/components/Question.d.ts +11 -0
  25. package/@types/components/RadioButton.d.ts +15 -0
  26. package/@types/components/Select.d.ts +14 -0
  27. package/@types/components/SequentialNavigation.d.ts +14 -0
  28. package/@types/components/SideNavigation.d.ts +19 -0
  29. package/@types/components/SiteNavigation.d.ts +13 -0
  30. package/@types/components/SiteSearch.d.ts +14 -0
  31. package/@types/components/SkipLinks.d.ts +14 -0
  32. package/@types/components/Tag.d.ts +7 -0
  33. package/@types/components/TaskList.d.ts +21 -0
  34. package/@types/components/TextInput.d.ts +12 -0
  35. package/@types/components/Textarea.d.ts +4 -0
  36. package/@types/global.d.ts +1 -0
  37. package/@types/sgds.d.ts +35 -0
  38. package/package.json +36 -0
  39. package/src/common/conditional-wrapper.test.tsx +36 -0
  40. package/src/common/conditional-wrapper.tsx +9 -0
  41. package/src/common/hint-text.test.tsx +47 -0
  42. package/src/common/hint-text.tsx +21 -0
  43. package/src/common/icon.test.tsx +100 -0
  44. package/src/common/icon.tsx +28 -0
  45. package/src/common/screen-reader-text.test.tsx +31 -0
  46. package/src/common/screen-reader-text.tsx +17 -0
  47. package/src/common/wrapper-tag.test.tsx +42 -0
  48. package/src/common/wrapper-tag.tsx +15 -0
  49. package/src/components/accordion/accordion.test.tsx +212 -0
  50. package/src/components/accordion/accordion.tsx +108 -0
  51. package/src/components/aspect-box/aspect-box.test.tsx +81 -0
  52. package/src/components/aspect-box/aspect-box.tsx +57 -0
  53. package/src/components/back-to-top/back-to-top.test.tsx +45 -0
  54. package/src/components/back-to-top/back-to-top.tsx +33 -0
  55. package/src/components/breadcrumbs/breadcrumbs.test.tsx +77 -0
  56. package/src/components/breadcrumbs/breadcrumbs.tsx +53 -0
  57. package/src/components/button/button.test.tsx +125 -0
  58. package/src/components/button/button.tsx +48 -0
  59. package/src/components/checkbox/checkbox.test.tsx +180 -0
  60. package/src/components/checkbox/checkbox.tsx +107 -0
  61. package/src/components/confirmation-message/confirmation-message.test.tsx +46 -0
  62. package/src/components/confirmation-message/confirmation-message.tsx +32 -0
  63. package/src/components/contents-nav/contents-nav.test.tsx +136 -0
  64. package/src/components/contents-nav/contents-nav.tsx +54 -0
  65. package/src/components/date-picker/date-picker.test.tsx +209 -0
  66. package/src/components/date-picker/date-picker.tsx +129 -0
  67. package/src/components/details/details.test.tsx +38 -0
  68. package/src/components/details/details.tsx +25 -0
  69. package/src/components/error-message/error-message.test.tsx +40 -0
  70. package/src/components/error-message/error-message.tsx +23 -0
  71. package/src/components/inset-text/inset-text.test.tsx +33 -0
  72. package/src/components/inset-text/inset-text.tsx +19 -0
  73. package/src/components/notification-banner/notification-banner.test.tsx +93 -0
  74. package/src/components/notification-banner/notification-banner.tsx +70 -0
  75. package/src/components/notification-panel/notification-panel.test.tsx +77 -0
  76. package/src/components/notification-panel/notification-panel.tsx +31 -0
  77. package/src/components/page-header/page-header.test.tsx +48 -0
  78. package/src/components/page-header/page-header.tsx +22 -0
  79. package/src/components/page-metadata/page-metadata.test.tsx +56 -0
  80. package/src/components/page-metadata/page-metadata.tsx +39 -0
  81. package/src/components/phase-banner/phase-banner.test.tsx +67 -0
  82. package/src/components/phase-banner/phase-banner.tsx +27 -0
  83. package/src/components/question/question.test.tsx +69 -0
  84. package/src/components/question/question.tsx +33 -0
  85. package/src/components/radio-button/radio-button.test.tsx +190 -0
  86. package/src/components/radio-button/radio-button.tsx +88 -0
  87. package/src/components/select/select.test.tsx +208 -0
  88. package/src/components/select/select.tsx +86 -0
  89. package/src/components/sequential-navigation/sequential-navigation.test.tsx +67 -0
  90. package/src/components/sequential-navigation/sequential-navigation.tsx +55 -0
  91. package/src/components/side-navigation/side-navigation.test.tsx +156 -0
  92. package/src/components/side-navigation/side-navigation.tsx +85 -0
  93. package/src/components/site-navigation/site-navigation.test.tsx +63 -0
  94. package/src/components/site-navigation/site-navigation.tsx +40 -0
  95. package/src/components/site-search/site-search.test.tsx +153 -0
  96. package/src/components/site-search/site-search.tsx +97 -0
  97. package/src/components/skip-links/skip-links.test.tsx +84 -0
  98. package/src/components/skip-links/skip-links.tsx +39 -0
  99. package/src/components/tag/tag.test.tsx +45 -0
  100. package/src/components/tag/tag.tsx +23 -0
  101. package/src/components/task-list/task-list.test.tsx +409 -0
  102. package/src/components/task-list/task-list.tsx +132 -0
  103. package/src/components/text-input/text-input.test.tsx +307 -0
  104. package/src/components/text-input/text-input.tsx +98 -0
  105. package/src/components/textarea/textarea.test.tsx +212 -0
  106. package/src/components/textarea/textarea.tsx +82 -0
  107. package/src/components/warning-text/warning-text.test.tsx +40 -0
  108. package/src/components/warning-text/warning-text.tsx +21 -0
  109. package/tsconfig.json +45 -0
  110. package/vite.config.ts +12 -0
  111. package/vitest-setup.ts +13 -0
@@ -0,0 +1,40 @@
1
+ import { test, expect } from 'vitest';
2
+ import { render } from '@testing-library/react';
3
+ import WarningText from './warning-text';
4
+
5
+ const text = `Call 999 if you or someone else is in immediate danger, or if the crime is in progress.`;
6
+
7
+ test('warning text renders correctly', () => {
8
+
9
+ render(
10
+ <WarningText>
11
+ {text}
12
+ </WarningText>
13
+ );
14
+
15
+ const warningTextOuter = document.querySelector('.ds_warning-text');
16
+ const warningTextInner = warningTextOuter?.querySelector('.ds_warning-text__text');
17
+ const warningTextIcon = warningTextOuter?.querySelector('.ds_warning-text__icon');
18
+ const warningTextTitle = warningTextOuter?.querySelector('strong.visually-hidden');
19
+
20
+ expect(warningTextOuter).toBeInTheDocument();
21
+ expect(warningTextInner).toBeInTheDocument();
22
+ expect(warningTextInner?.textContent).toEqual(text);
23
+
24
+ expect(warningTextIcon).toHaveAttribute('aria-hidden');
25
+ expect(warningTextTitle?.textContent).toEqual('Warning');
26
+
27
+ expect(warningTextInner?.previousSibling).toEqual(warningTextTitle);
28
+ expect(warningTextTitle?.previousSibling).toEqual(warningTextIcon);
29
+ });
30
+
31
+ test('passing additional props', () => {
32
+ render(
33
+ <WarningText data-test="foo">
34
+ {text}
35
+ </WarningText>
36
+ )
37
+
38
+ const warningTextOuter = document.querySelector('.ds_warning-text');
39
+ expect(warningTextOuter?.dataset.test).toEqual('foo');
40
+ });
@@ -0,0 +1,21 @@
1
+ const WarningText: React.FC<React.PropsWithChildren> = ({
2
+ children,
3
+ ...props
4
+ }) => {
5
+ return (
6
+ <div
7
+ className="ds_warning-text"
8
+ {...props}
9
+ >
10
+ <strong className="ds_warning-text__icon" aria-hidden="true"></strong>
11
+ <strong className="visually-hidden">Warning</strong>
12
+ <div className="ds_warning-text__text">
13
+ {children}
14
+ </div>
15
+ </div>
16
+ );
17
+ };
18
+
19
+ WarningText.displayName = 'WarningText';
20
+
21
+ export default WarningText;
package/tsconfig.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": false,
4
+ "jsx": "preserve",
5
+ "module": "NodeNext",
6
+ "moduleResolution": "nodenext",
7
+ "outDir": "./dist",
8
+ "paths": {
9
+ "@/*": [
10
+ "./*"
11
+ ],
12
+ "@design-system/*": [
13
+ "./node_modules/@scottish-government/design-system/src/*"
14
+ ]
15
+ },
16
+ "target": "esnext",
17
+ "types": [],
18
+ "typeRoots": [
19
+ "./node_modules/@types",
20
+ "./@types"
21
+ ],
22
+ "lib": [
23
+ "dom",
24
+ "dom.iterable",
25
+ "esnext"
26
+ ],
27
+ "incremental": true,
28
+ "esModuleInterop": true,
29
+ "resolveJsonModule": true,
30
+
31
+ "noFallthroughCasesInSwitch": true,
32
+ "noUnusedLocals": true,
33
+ "noUnusedParameters": true,
34
+ "strict": true
35
+ },
36
+ "include": [
37
+ "@types",
38
+ "src/**/*.tsx",
39
+ "vitest.setup.ts"
40
+ ],
41
+ "exclude": [
42
+ "node_modules/**/*",
43
+ "src/**/*.test.tsx"
44
+ ]
45
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import react from "@vitejs/plugin-react-swc";
3
+
4
+ export default defineConfig({
5
+ plugins: [
6
+ react()
7
+ ],
8
+ test: {
9
+ environment: 'jsdom',
10
+ setupFiles: ["./vitest-setup.ts"]
11
+ }
12
+ });
@@ -0,0 +1,13 @@
1
+ import '@testing-library/jest-dom/vitest';
2
+ import { vi } from 'vitest';
3
+ import { cleanup } from '@testing-library/react';
4
+ import { afterEach } from 'vitest';
5
+
6
+ afterEach(() => {
7
+ cleanup();
8
+ });
9
+
10
+ // mock CSS.supports()
11
+ Object.defineProperty(global.CSS, 'supports', {
12
+ value: () => vi.fn()
13
+ });