@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.
- package/.editorconfig +12 -0
- package/.github/workflows/release-package.yml +96 -0
- package/@types/common/ConditionalWrapper.d.ts +6 -0
- package/@types/common/HintText.d.ts +6 -0
- package/@types/common/Icon.d.ts +11 -0
- package/@types/common/ScreenReaderText.d.ts +4 -0
- package/@types/common/WrapperTag.d.ts +5 -0
- package/@types/components/Accordion.d.ts +15 -0
- package/@types/components/AspectBox.d.ts +5 -0
- package/@types/components/BackToTop.d.ts +5 -0
- package/@types/components/Breadcrumbs.d.ts +14 -0
- package/@types/components/Button.d.ts +17 -0
- package/@types/components/Checkbox.d.ts +13 -0
- package/@types/components/ConfirmationMessage.d.ts +7 -0
- package/@types/components/ContentsNav.d.ts +15 -0
- package/@types/components/DatePicker.d.ts +19 -0
- package/@types/components/Details.d.ts +6 -0
- package/@types/components/ErrorMessage.d.ts +6 -0
- package/@types/components/Metadata.d.ts +11 -0
- package/@types/components/NotificationBanner.d.ts +9 -0
- package/@types/components/NotificationPanel.d.ts +7 -0
- package/@types/components/PageHeader.d.ts +6 -0
- package/@types/components/PhaseBanner.d.ts +5 -0
- package/@types/components/Question.d.ts +11 -0
- package/@types/components/RadioButton.d.ts +15 -0
- package/@types/components/Select.d.ts +14 -0
- package/@types/components/SequentialNavigation.d.ts +14 -0
- package/@types/components/SideNavigation.d.ts +19 -0
- package/@types/components/SiteNavigation.d.ts +13 -0
- package/@types/components/SiteSearch.d.ts +14 -0
- package/@types/components/SkipLinks.d.ts +14 -0
- package/@types/components/Tag.d.ts +7 -0
- package/@types/components/TaskList.d.ts +21 -0
- package/@types/components/TextInput.d.ts +12 -0
- package/@types/components/Textarea.d.ts +4 -0
- package/@types/global.d.ts +1 -0
- package/@types/sgds.d.ts +35 -0
- package/package.json +36 -0
- package/src/common/conditional-wrapper.test.tsx +36 -0
- package/src/common/conditional-wrapper.tsx +9 -0
- package/src/common/hint-text.test.tsx +47 -0
- package/src/common/hint-text.tsx +21 -0
- package/src/common/icon.test.tsx +100 -0
- package/src/common/icon.tsx +28 -0
- package/src/common/screen-reader-text.test.tsx +31 -0
- package/src/common/screen-reader-text.tsx +17 -0
- package/src/common/wrapper-tag.test.tsx +42 -0
- package/src/common/wrapper-tag.tsx +15 -0
- package/src/components/accordion/accordion.test.tsx +212 -0
- package/src/components/accordion/accordion.tsx +108 -0
- package/src/components/aspect-box/aspect-box.test.tsx +81 -0
- package/src/components/aspect-box/aspect-box.tsx +57 -0
- package/src/components/back-to-top/back-to-top.test.tsx +45 -0
- package/src/components/back-to-top/back-to-top.tsx +33 -0
- package/src/components/breadcrumbs/breadcrumbs.test.tsx +77 -0
- package/src/components/breadcrumbs/breadcrumbs.tsx +53 -0
- package/src/components/button/button.test.tsx +125 -0
- package/src/components/button/button.tsx +48 -0
- package/src/components/checkbox/checkbox.test.tsx +180 -0
- package/src/components/checkbox/checkbox.tsx +107 -0
- package/src/components/confirmation-message/confirmation-message.test.tsx +46 -0
- package/src/components/confirmation-message/confirmation-message.tsx +32 -0
- package/src/components/contents-nav/contents-nav.test.tsx +136 -0
- package/src/components/contents-nav/contents-nav.tsx +54 -0
- package/src/components/date-picker/date-picker.test.tsx +209 -0
- package/src/components/date-picker/date-picker.tsx +129 -0
- package/src/components/details/details.test.tsx +38 -0
- package/src/components/details/details.tsx +25 -0
- package/src/components/error-message/error-message.test.tsx +40 -0
- package/src/components/error-message/error-message.tsx +23 -0
- package/src/components/inset-text/inset-text.test.tsx +33 -0
- package/src/components/inset-text/inset-text.tsx +19 -0
- package/src/components/notification-banner/notification-banner.test.tsx +93 -0
- package/src/components/notification-banner/notification-banner.tsx +70 -0
- package/src/components/notification-panel/notification-panel.test.tsx +77 -0
- package/src/components/notification-panel/notification-panel.tsx +31 -0
- package/src/components/page-header/page-header.test.tsx +48 -0
- package/src/components/page-header/page-header.tsx +22 -0
- package/src/components/page-metadata/page-metadata.test.tsx +56 -0
- package/src/components/page-metadata/page-metadata.tsx +39 -0
- package/src/components/phase-banner/phase-banner.test.tsx +67 -0
- package/src/components/phase-banner/phase-banner.tsx +27 -0
- package/src/components/question/question.test.tsx +69 -0
- package/src/components/question/question.tsx +33 -0
- package/src/components/radio-button/radio-button.test.tsx +190 -0
- package/src/components/radio-button/radio-button.tsx +88 -0
- package/src/components/select/select.test.tsx +208 -0
- package/src/components/select/select.tsx +86 -0
- package/src/components/sequential-navigation/sequential-navigation.test.tsx +67 -0
- package/src/components/sequential-navigation/sequential-navigation.tsx +55 -0
- package/src/components/side-navigation/side-navigation.test.tsx +156 -0
- package/src/components/side-navigation/side-navigation.tsx +85 -0
- package/src/components/site-navigation/site-navigation.test.tsx +63 -0
- package/src/components/site-navigation/site-navigation.tsx +40 -0
- package/src/components/site-search/site-search.test.tsx +153 -0
- package/src/components/site-search/site-search.tsx +97 -0
- package/src/components/skip-links/skip-links.test.tsx +84 -0
- package/src/components/skip-links/skip-links.tsx +39 -0
- package/src/components/tag/tag.test.tsx +45 -0
- package/src/components/tag/tag.tsx +23 -0
- package/src/components/task-list/task-list.test.tsx +409 -0
- package/src/components/task-list/task-list.tsx +132 -0
- package/src/components/text-input/text-input.test.tsx +307 -0
- package/src/components/text-input/text-input.tsx +98 -0
- package/src/components/textarea/textarea.test.tsx +212 -0
- package/src/components/textarea/textarea.tsx +82 -0
- package/src/components/warning-text/warning-text.test.tsx +40 -0
- package/src/components/warning-text/warning-text.tsx +21 -0
- package/tsconfig.json +45 -0
- package/vite.config.ts +12 -0
- package/vitest-setup.ts +13 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# editorconfig.org
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
indent_size = 4
|
|
8
|
+
indent_style = space
|
|
9
|
+
end_of_line = lf
|
|
10
|
+
charset = utf-8
|
|
11
|
+
trim_trailing_whitespace = true
|
|
12
|
+
insert_final_newline = true
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
name: Versioned release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
release_type:
|
|
7
|
+
description: 'Release type'
|
|
8
|
+
required: true
|
|
9
|
+
type: choice
|
|
10
|
+
options:
|
|
11
|
+
- patch
|
|
12
|
+
- minor
|
|
13
|
+
- major
|
|
14
|
+
- prepatch
|
|
15
|
+
- preminor
|
|
16
|
+
- premajor
|
|
17
|
+
- prerelease
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
build:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
# Set up node and add the registry url
|
|
28
|
+
- name: Setup Node.js
|
|
29
|
+
uses: actions/setup-node@v3
|
|
30
|
+
with:
|
|
31
|
+
node-version: 18
|
|
32
|
+
registry-url: 'https://registry.npmjs.org'
|
|
33
|
+
always-auth: true
|
|
34
|
+
|
|
35
|
+
# Install
|
|
36
|
+
- name: Install
|
|
37
|
+
run: npm ci
|
|
38
|
+
|
|
39
|
+
# Test
|
|
40
|
+
- name: Run tests
|
|
41
|
+
run: npm run test
|
|
42
|
+
|
|
43
|
+
# Configure Git
|
|
44
|
+
- name: Git configuration
|
|
45
|
+
run: |
|
|
46
|
+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
47
|
+
git config --global user.name "GitHub Actions"
|
|
48
|
+
|
|
49
|
+
# Set package version
|
|
50
|
+
- name: Set package version
|
|
51
|
+
if: startsWith(github.event.inputs.release_type, 'pre') != true
|
|
52
|
+
run: |
|
|
53
|
+
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
|
|
54
|
+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
|
|
55
|
+
env:
|
|
56
|
+
RELEASE_TYPE: ${{github.event.inputs.release_type}}
|
|
57
|
+
|
|
58
|
+
# Set pre-release version
|
|
59
|
+
- name: Set pre-release version
|
|
60
|
+
if: startsWith(github.event.inputs.release_type, 'pre')
|
|
61
|
+
run: |
|
|
62
|
+
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
|
|
63
|
+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
|
|
64
|
+
env:
|
|
65
|
+
RELEASE_TYPE: ${{github.event.inputs.release_type}}
|
|
66
|
+
|
|
67
|
+
# Build release assets
|
|
68
|
+
- name: Build release assets
|
|
69
|
+
run: |
|
|
70
|
+
npm run build
|
|
71
|
+
|
|
72
|
+
## Add release assets
|
|
73
|
+
- name: Add release assets to commit
|
|
74
|
+
run: |
|
|
75
|
+
git add -f "dist/**/*"
|
|
76
|
+
|
|
77
|
+
# Commit updated package.json
|
|
78
|
+
- name: Commit package.json and create tag
|
|
79
|
+
run: |
|
|
80
|
+
git add "package.json"
|
|
81
|
+
git add "package-lock.json"
|
|
82
|
+
git commit -m "chore: release ${{env.NEW_VERSION}}"
|
|
83
|
+
git tag ${{env.NEW_VERSION}}
|
|
84
|
+
|
|
85
|
+
# Push to git repo
|
|
86
|
+
- name: Push changes to git
|
|
87
|
+
env:
|
|
88
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
89
|
+
run: |
|
|
90
|
+
git push origin && git push --tags
|
|
91
|
+
|
|
92
|
+
# Publish to npm
|
|
93
|
+
- name: Publish npm package
|
|
94
|
+
run: npm publish --access public
|
|
95
|
+
env:
|
|
96
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace Accordion {
|
|
3
|
+
interface Item extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
headerLevel?: SGDS.HeaderLevel,
|
|
5
|
+
id: string,
|
|
6
|
+
open?: boolean,
|
|
7
|
+
title: string
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Accordion extends React.AllHTMLAttributes<HTMLElement> {
|
|
12
|
+
headerLevel?: SGDS.HeaderLevel,
|
|
13
|
+
hideOpenAll?: boolean
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace Breadcrumbs {
|
|
3
|
+
interface Item extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
hidden?: boolean,
|
|
5
|
+
href?: string,
|
|
6
|
+
title: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Breadcrumbs extends React.AllHTMLAttributes<HTMLElement> {
|
|
11
|
+
hideLastItem?: boolean,
|
|
12
|
+
items: Breadcrumbs.Item[]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
type ButtonStyle = 'primary' | 'secondary';
|
|
3
|
+
type ButtonType = 'submit' | 'reset' | 'button';
|
|
4
|
+
type ButtonWidth = 'fluid' | 'fixed' | 'max';
|
|
5
|
+
|
|
6
|
+
interface Button extends React.AllHTMLAttributes<HTMLButtonElement> {
|
|
7
|
+
icon?: string,
|
|
8
|
+
iconLeft?: boolean
|
|
9
|
+
iconOnly?: boolean,
|
|
10
|
+
href?: string,
|
|
11
|
+
small?: boolean,
|
|
12
|
+
buttonStyle?: ButtonStyle,
|
|
13
|
+
styleAsLink?: boolean,
|
|
14
|
+
type?: ButtonType
|
|
15
|
+
width?: ButtonWidth
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace Checkbox {
|
|
3
|
+
interface Group extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
items: Checkbox[],
|
|
5
|
+
small?: boolean
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface Checkbox extends CheckboxRadioBase<HTMLInputElement> {
|
|
10
|
+
exclusive?: boolean
|
|
11
|
+
id: string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace ContentsNav {
|
|
3
|
+
interface Link extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
title: string,
|
|
5
|
+
current: boolean,
|
|
6
|
+
href: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ContentsNav extends React.AllHTMLAttributes<HTMLElement> {
|
|
11
|
+
items: ContentsNav.Link[],
|
|
12
|
+
label: string,
|
|
13
|
+
title: string
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
interface DatePicker extends React.AllHTMLAttributes<HTMLElement> {
|
|
3
|
+
disabledDates?: string,
|
|
4
|
+
error?: boolean,
|
|
5
|
+
errorMessage?: string,
|
|
6
|
+
id: string,
|
|
7
|
+
hintText?: string,
|
|
8
|
+
iconPath?: string,
|
|
9
|
+
label: string,
|
|
10
|
+
maxDate?: string,
|
|
11
|
+
minDate?: string,
|
|
12
|
+
multiple?: boolean,
|
|
13
|
+
name?: string,
|
|
14
|
+
onBlur?: React.EventHandler<any>,
|
|
15
|
+
onChange?: React.EventHandler<any>,
|
|
16
|
+
value?: string,
|
|
17
|
+
width?: SGDS.InputWidth
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
type QuestionTags = 'div' | 'fieldset';
|
|
3
|
+
|
|
4
|
+
interface Question extends React.AllHTMLAttributes<HTMLElement> {
|
|
5
|
+
error?: boolean,
|
|
6
|
+
errorMessage?: string,
|
|
7
|
+
hintText?: string,
|
|
8
|
+
legend?: string,
|
|
9
|
+
tagName: QuestionTags
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace RadioButton {
|
|
3
|
+
interface Group extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
inline?: boolean,
|
|
5
|
+
items: RadioButton[],
|
|
6
|
+
name: string,
|
|
7
|
+
small?: boolean
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface RadioButton extends CheckboxRadioBase<HTMLInputElement> {
|
|
12
|
+
id: string,
|
|
13
|
+
name: string
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace Select {
|
|
3
|
+
interface Option extends React.AllHTMLAttributes<HTMLOptionElement> {
|
|
4
|
+
text: string
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Select extends FormFieldBase<HTMLDivElement> {
|
|
9
|
+
defaultValue?: string,
|
|
10
|
+
options: Select.Option[],
|
|
11
|
+
placeholder?: string,
|
|
12
|
+
width?: InputWidth
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace SequentialNavigation {
|
|
3
|
+
interface Link extends React.AllHTMLAttributes<HTMLDivElement> {
|
|
4
|
+
href: string,
|
|
5
|
+
title: string
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface SequentialNavigation extends React.AllHTMLAttributes<HTMLElement> {
|
|
10
|
+
ariaLabel?: string,
|
|
11
|
+
next?: SequentialNavigation.Link,
|
|
12
|
+
previous?: SequentialNavigation.Link
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace SideNavigation {
|
|
3
|
+
interface List extends React.AllHTMLAttributes<HTMLUListElement> {
|
|
4
|
+
items?: SideNavigation.Link[],
|
|
5
|
+
root?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Link extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
9
|
+
current?: boolean,
|
|
10
|
+
href: string,
|
|
11
|
+
items?: SideNavigation.Link[]
|
|
12
|
+
title: string,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface SideNavigation extends React.AllHTMLAttributes<HTMLElement> {
|
|
17
|
+
items: SideNavigation.Link[]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace SiteNavigation {
|
|
3
|
+
interface Link extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
4
|
+
current?: boolean,
|
|
5
|
+
href: string,
|
|
6
|
+
title: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SiteNavigation extends React.AllHTMLAttributes<HTMLElement> {
|
|
11
|
+
items: SiteNavigation.Link[]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
type FormMethods = 'GET' | 'POST';
|
|
3
|
+
|
|
4
|
+
interface SiteSearch extends React.AllHTMLAttributes<HTMLInputElement> {
|
|
5
|
+
action?: string,
|
|
6
|
+
autocompleteEndpoint?: string,
|
|
7
|
+
autocompleteSuggestionMappingFunction?: Function,
|
|
8
|
+
id: string,
|
|
9
|
+
method?: FormMethods,
|
|
10
|
+
minLength?: number,
|
|
11
|
+
name?: string,
|
|
12
|
+
placeholder?: string
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace SkipLinks {
|
|
3
|
+
interface Link extends React.AllHTMLAttributes<HTMLLIElement> {
|
|
4
|
+
targetId: string,
|
|
5
|
+
title: string
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface SkipLinks extends React.AllHTMLAttributes<HTMLDivElement> {
|
|
10
|
+
items?: SkipLinks.Link[],
|
|
11
|
+
mainContentId?: string,
|
|
12
|
+
mainLinkText?: string
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
namespace TaskList {
|
|
3
|
+
interface Group extends React.AllHTMLAttributes<HTMLElement> {
|
|
4
|
+
intro?: string,
|
|
5
|
+
title: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Task extends React.AllHTMLAttributes<HTMLElement> {
|
|
9
|
+
href?: string,
|
|
10
|
+
id?: string,
|
|
11
|
+
isComplete?: boolean,
|
|
12
|
+
statusText?: string,
|
|
13
|
+
tagColour?: TagColour,
|
|
14
|
+
title: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface TaskList extends React.AllHTMLAttributes<HTMLElement> {
|
|
19
|
+
headingId?: string
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare namespace SGDS.Component {
|
|
2
|
+
interface TextInput extends TextInputBase<HTMLInputElement> {
|
|
3
|
+
buttonIcon?: string,
|
|
4
|
+
buttonText?: string,
|
|
5
|
+
className?: string,
|
|
6
|
+
currency?: boolean,
|
|
7
|
+
currencySymbol?: string,
|
|
8
|
+
hasButton?: boolean,
|
|
9
|
+
type?: string,
|
|
10
|
+
width?: InputWidth
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import React from 'react'
|
package/@types/sgds.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare namespace SGDS {
|
|
2
|
+
type AriaLive = 'polite' | 'assertive';
|
|
3
|
+
type HeaderLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
4
|
+
type InputWidth = 'fixed-20' | 'fixed-10' | 'fixed-5' | 'fixed-4' | 'fixed-3' | 'fixed-2' | 'fluid-three-quarters' | 'fluid-two-thirds' | 'fluid-half' | 'fluid-one-third' | 'fluid-one-quarter';
|
|
5
|
+
type TagColour = 'grey' | 'green' | 'teal' | 'blue' | 'purple' | 'pink' | 'red' | 'orange' | 'yellow';
|
|
6
|
+
|
|
7
|
+
interface CheckboxRadioBase<T> extends React.AllHTMLAttributes<T> {
|
|
8
|
+
checked?: boolean,
|
|
9
|
+
hintText?: string,
|
|
10
|
+
id?: string,
|
|
11
|
+
label: string,
|
|
12
|
+
name?: string,
|
|
13
|
+
onBlur?: React.EventHandler<any>,
|
|
14
|
+
onChange?: React.EventHandler<any>,
|
|
15
|
+
small?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface FormFieldBase<T> extends React.AllHTMLAttributes <T> {
|
|
19
|
+
error?: boolean,
|
|
20
|
+
errorMessage?: string,
|
|
21
|
+
id: string,
|
|
22
|
+
hintText?: string,
|
|
23
|
+
label: string,
|
|
24
|
+
name?: string,
|
|
25
|
+
onBlur?: React.EventHandler<any>,
|
|
26
|
+
onChange?: React.EventHandler<any>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface TextInputBase<T> extends FormFieldBase<T> {
|
|
30
|
+
countThreshold?: number,
|
|
31
|
+
maxlength?: number,
|
|
32
|
+
placeholder?: string,
|
|
33
|
+
value?: string
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scottish-government/designsystem-react",
|
|
3
|
+
"description": "A React/JSX implementation of the Scottish Government Design System",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Scottish Government Digital Design System team",
|
|
8
|
+
"email": "designsystem@gov.scot",
|
|
9
|
+
"url": "https://designsystem.gov.scot"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "npm run tsc",
|
|
13
|
+
"coverage": "vitest run --coverage",
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"tsc": "node ./node_modules/typescript/bin/tsc"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@scottish-government/design-system": "^3.0.1"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@testing-library/dom": "^10.4.0",
|
|
22
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
23
|
+
"@testing-library/react": "^16.3.0",
|
|
24
|
+
"@testing-library/user-event": "^14.6.1",
|
|
25
|
+
"@types/node": "22.15.19",
|
|
26
|
+
"@types/react": "^19.1.6",
|
|
27
|
+
"@types/react-dom": "^19.1.5",
|
|
28
|
+
"@vitejs/plugin-react-swc": "^3.10.0",
|
|
29
|
+
"@vitest/coverage-v8": "^3.2.0",
|
|
30
|
+
"jsdom": "^26.1.0",
|
|
31
|
+
"react": "^19.1.0",
|
|
32
|
+
"react-dom": "^19.1.0",
|
|
33
|
+
"typescript": "^5.8.3",
|
|
34
|
+
"vitest": "^3.2.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import ConditionalWrapper from './conditional-wrapper';
|
|
4
|
+
|
|
5
|
+
test('conditional wrapper true', () => {
|
|
6
|
+
render(
|
|
7
|
+
<ConditionalWrapper
|
|
8
|
+
condition={true}
|
|
9
|
+
wrapper={(children: React.JSX.Element) => <a data-testid="wrapper">{children}</a>}
|
|
10
|
+
>
|
|
11
|
+
<span data-testid="testContent">Bar</span>
|
|
12
|
+
</ConditionalWrapper>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const element = screen.getByTestId('testContent');
|
|
16
|
+
const elementParent = screen.getByTestId('wrapper');
|
|
17
|
+
expect(element).toBeInTheDocument();
|
|
18
|
+
expect(elementParent).toBeInTheDocument();
|
|
19
|
+
expect(element.parentNode).toEqual(elementParent)
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('conditional wrapper false', () => {
|
|
23
|
+
render(
|
|
24
|
+
<ConditionalWrapper
|
|
25
|
+
condition={false}
|
|
26
|
+
wrapper={(children: React.JSX.Element) => <a href="foo">{children}</a>}
|
|
27
|
+
>
|
|
28
|
+
<span data-testid="testContent">Bar</span>
|
|
29
|
+
</ConditionalWrapper>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const element = screen.getByTestId('testContent');
|
|
33
|
+
const elementParent = screen.queryByTestId('wrapper');
|
|
34
|
+
expect(element).toBeInTheDocument();
|
|
35
|
+
expect(elementParent).not.toBeInTheDocument();
|
|
36
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps all children in a specified HTML tag if a condition is met.
|
|
3
|
+
*/
|
|
4
|
+
const ConditionalWrapper: React.FC<SGDS.Common.ConditionalWrapper> = ({ condition, wrapper, children }) =>
|
|
5
|
+
condition ? wrapper(children) : children;
|
|
6
|
+
|
|
7
|
+
ConditionalWrapper.displayName = 'ConditionalWrapper';
|
|
8
|
+
|
|
9
|
+
export default ConditionalWrapper;
|