@scottish-government/designsystem-react 0.0.2 → 0.1.1
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/@types/components/InsetText.d.ts +5 -0
- package/@types/components/WarningText.d.ts +5 -0
- package/dist/common/conditional-wrapper.jsx +8 -0
- package/dist/common/hint-text.jsx +9 -0
- package/dist/common/icon.jsx +14 -0
- package/dist/common/screen-reader-text.jsx +9 -0
- package/dist/common/wrapper-tag.jsx +11 -0
- package/dist/components/accordion/accordion.jsx +103 -0
- package/dist/components/aspect-box/aspect-box.jsx +79 -0
- package/dist/components/back-to-top/back-to-top.jsx +27 -0
- package/dist/components/breadcrumbs/breadcrumbs.jsx +28 -0
- package/dist/components/button/button.jsx +30 -0
- package/dist/components/checkbox/checkbox.jsx +62 -0
- package/dist/components/confirmation-message/confirmation-message.jsx +24 -0
- package/dist/components/contents-nav/contents-nav.jsx +33 -0
- package/dist/components/date-picker/date-picker.jsx +50 -0
- package/dist/components/details/details.jsx +17 -0
- package/dist/components/error-message/error-message.jsx +12 -0
- package/dist/components/inset-text/inset-text.jsx +14 -0
- package/dist/components/notification-banner/notification-banner.jsx +54 -0
- package/dist/components/notification-panel/notification-panel.jsx +21 -0
- package/dist/components/page-header/page-header.jsx +15 -0
- package/dist/components/page-metadata/page-metadata.jsx +27 -0
- package/dist/components/phase-banner/phase-banner.jsx +23 -0
- package/dist/components/question/question.jsx +22 -0
- package/dist/components/radio-button/radio-button.jsx +43 -0
- package/dist/components/select/select.jsx +52 -0
- package/dist/components/sequential-navigation/sequential-navigation.jsx +31 -0
- package/dist/components/side-navigation/side-navigation.jsx +52 -0
- package/dist/components/site-navigation/site-navigation.jsx +22 -0
- package/dist/components/site-search/site-search.jsx +55 -0
- package/dist/components/skip-links/skip-links.jsx +21 -0
- package/dist/components/tag/tag.jsx +13 -0
- package/dist/components/task-list/task-list.jsx +96 -0
- package/dist/components/text-input/text-input.jsx +58 -0
- package/dist/components/textarea/textarea.jsx +54 -0
- package/dist/components/warning-text/warning-text.jsx +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
- package/src/common/icon.test.tsx +1 -1
- package/src/components/accordion/accordion.test.tsx +25 -1
- package/src/components/accordion/accordion.tsx +10 -2
- package/src/components/aspect-box/aspect-box.test.tsx +12 -0
- package/src/components/aspect-box/aspect-box.tsx +3 -1
- package/src/components/back-to-top/back-to-top.test.tsx +10 -0
- package/src/components/back-to-top/back-to-top.tsx +5 -1
- package/src/components/breadcrumbs/breadcrumbs.test.tsx +12 -0
- package/src/components/breadcrumbs/breadcrumbs.tsx +2 -0
- package/src/components/button/button.test.tsx +9 -0
- package/src/components/button/button.tsx +4 -2
- package/src/components/checkbox/checkbox.test.tsx +13 -0
- package/src/components/checkbox/checkbox.tsx +6 -1
- package/src/components/confirmation-message/confirmation-message.test.tsx +22 -0
- package/src/components/confirmation-message/confirmation-message.tsx +8 -2
- package/src/components/contents-nav/contents-nav.test.tsx +13 -0
- package/src/components/contents-nav/contents-nav.tsx +8 -4
- package/src/components/date-picker/date-picker.test.tsx +13 -0
- package/src/components/date-picker/date-picker.tsx +4 -2
- package/src/components/details/details.test.tsx +12 -0
- package/src/components/details/details.tsx +2 -0
- package/src/components/error-message/error-message.test.tsx +9 -0
- package/src/components/error-message/error-message.tsx +2 -0
- package/src/components/inset-text/inset-text.test.tsx +11 -0
- package/src/components/inset-text/inset-text.tsx +6 -2
- package/src/components/notification-banner/notification-banner.test.tsx +11 -0
- package/src/components/notification-banner/notification-banner.tsx +6 -1
- package/src/components/notification-panel/notification-panel.test.tsx +12 -0
- package/src/components/notification-panel/notification-panel.tsx +5 -1
- package/src/components/page-header/page-header.test.tsx +9 -0
- package/src/components/page-header/page-header.tsx +5 -1
- package/src/components/page-metadata/page-metadata.test.tsx +15 -0
- package/src/components/page-metadata/page-metadata.tsx +7 -1
- package/src/components/phase-banner/phase-banner.test.tsx +11 -0
- package/src/components/phase-banner/phase-banner.tsx +5 -1
- package/src/components/question/question.test.tsx +10 -0
- package/src/components/question/question.tsx +3 -1
- package/src/components/radio-button/radio-button.test.tsx +13 -0
- package/src/components/radio-button/radio-button.tsx +3 -1
- package/src/components/select/select.test.tsx +15 -0
- package/src/components/select/select.tsx +2 -0
- package/src/components/sequential-navigation/sequential-navigation.test.tsx +13 -0
- package/src/components/sequential-navigation/sequential-navigation.tsx +5 -1
- package/src/components/side-navigation/side-navigation.test.tsx +18 -0
- package/src/components/side-navigation/side-navigation.tsx +5 -1
- package/src/components/site-navigation/site-navigation.test.tsx +9 -0
- package/src/components/site-navigation/site-navigation.tsx +5 -1
- package/src/components/site-search/site-search.test.tsx +10 -0
- package/src/components/site-search/site-search.tsx +3 -1
- package/src/components/tag/tag.test.tsx +7 -7
- package/src/components/task-list/task-list.test.tsx +46 -0
- package/src/components/task-list/task-list.tsx +18 -5
- package/src/components/text-input/text-input.test.tsx +13 -0
- package/src/components/textarea/textarea.test.tsx +13 -0
- package/src/components/textarea/textarea.tsx +2 -0
- package/src/components/warning-text/warning-text.test.tsx +11 -0
- package/src/components/warning-text/warning-text.tsx +6 -2
- package/.editorconfig +0 -12
- package/.github/workflows/release-package.yml +0 -96
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const PageHeader = ({ children, className, label, title, ...props }) => {
|
|
4
|
+
return (<header className={[
|
|
5
|
+
'ds_page-header',
|
|
6
|
+
className
|
|
7
|
+
].join(' ')} {...props}>
|
|
8
|
+
{label && <span className="ds_page-header__label ds_content-label">{label}</span>}
|
|
9
|
+
<h1 className="ds_page-header__title">{title}</h1>
|
|
10
|
+
|
|
11
|
+
{children}
|
|
12
|
+
</header>);
|
|
13
|
+
};
|
|
14
|
+
PageHeader.displayName = 'PageHeader';
|
|
15
|
+
exports.default = PageHeader;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetadataItem = void 0;
|
|
4
|
+
const MetadataItem = ({ children, className, name, ...props }) => {
|
|
5
|
+
return (<div className={[
|
|
6
|
+
'ds_metadata__item',
|
|
7
|
+
className
|
|
8
|
+
].join(' ')} {...props}>
|
|
9
|
+
<dt className="ds_metadata__key">{name}</dt>{' '}
|
|
10
|
+
<dd className="ds_metadata__value">
|
|
11
|
+
{children}
|
|
12
|
+
</dd>
|
|
13
|
+
</div>);
|
|
14
|
+
};
|
|
15
|
+
exports.MetadataItem = MetadataItem;
|
|
16
|
+
const Metadata = ({ children, className, inline, ...props }) => {
|
|
17
|
+
return (<dl className={[
|
|
18
|
+
'ds_metadata',
|
|
19
|
+
inline && 'ds_metadata--inline',
|
|
20
|
+
className
|
|
21
|
+
].join(' ')} {...props}>
|
|
22
|
+
{children}
|
|
23
|
+
</dl>);
|
|
24
|
+
};
|
|
25
|
+
Metadata.displayName = 'Metadata';
|
|
26
|
+
exports.MetadataItem.displayName = 'MetadataItem';
|
|
27
|
+
exports.default = Metadata;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const tag_1 = __importDefault(require("../tag/tag"));
|
|
7
|
+
const PhaseBanner = ({ children, className, phaseName, ...props }) => {
|
|
8
|
+
return (<div className={[
|
|
9
|
+
'ds_phase-banner',
|
|
10
|
+
className
|
|
11
|
+
].join(' ')} {...props}>
|
|
12
|
+
<div className="ds_wrapper">
|
|
13
|
+
<p className="ds_phase-banner__content">
|
|
14
|
+
{phaseName && <tag_1.default title={phaseName} className="ds_phase-banner__tag"/>}
|
|
15
|
+
<span className="ds_phase-banner__text">
|
|
16
|
+
{children || "This is a new service"}
|
|
17
|
+
</span>
|
|
18
|
+
</p>
|
|
19
|
+
</div>
|
|
20
|
+
</div>);
|
|
21
|
+
};
|
|
22
|
+
PhaseBanner.displayName = 'PhaseBanner';
|
|
23
|
+
exports.default = PhaseBanner;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const error_message_1 = __importDefault(require("../error-message/error-message"));
|
|
7
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
8
|
+
const wrapper_tag_1 = __importDefault(require("../../common/wrapper-tag"));
|
|
9
|
+
const Question = function ({ children, className, error, errorMessage, hintText, legend, tagName = 'div', ...props }) {
|
|
10
|
+
return (<wrapper_tag_1.default tagName={tagName} className={[
|
|
11
|
+
'ds_question',
|
|
12
|
+
error && 'ds_question--error',
|
|
13
|
+
className
|
|
14
|
+
].join(' ')} {...props}>
|
|
15
|
+
{legend && <legend>{legend}</legend>}
|
|
16
|
+
{hintText && <hint_text_1.default text={hintText}/>}
|
|
17
|
+
{error && errorMessage && <error_message_1.default text={errorMessage}/>}
|
|
18
|
+
{children}
|
|
19
|
+
</wrapper_tag_1.default>);
|
|
20
|
+
};
|
|
21
|
+
Question.displayName = 'Question';
|
|
22
|
+
exports.default = Question;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Radio = void 0;
|
|
7
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
8
|
+
const Radio = ({ checked, hintText, id, label, name, onBlur, onChange, small }) => {
|
|
9
|
+
const hintTextId = `hint-text-${id}`;
|
|
10
|
+
function handleBlur(event) {
|
|
11
|
+
if (typeof onBlur === 'function') {
|
|
12
|
+
onBlur(event);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function handleChange(event) {
|
|
16
|
+
if (typeof onChange === 'function') {
|
|
17
|
+
onChange(event);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return (<div className={[
|
|
21
|
+
'ds_radio',
|
|
22
|
+
small && 'ds_radio--small'
|
|
23
|
+
].join(' ')}>
|
|
24
|
+
<input aria-describedby={hintText ? hintTextId : undefined} className="ds_radio__input" defaultChecked={!!checked} id={id} name={name} onBlur={handleBlur} onChange={handleChange} type="radio"/>
|
|
25
|
+
<label className="ds_radio__label" htmlFor={id}>{label}</label>
|
|
26
|
+
{hintText && <hint_text_1.default id={hintTextId} text={hintText}/>}
|
|
27
|
+
</div>);
|
|
28
|
+
};
|
|
29
|
+
exports.Radio = Radio;
|
|
30
|
+
const RadioGroup = ({ className, inline, items, name, small, ...props }) => {
|
|
31
|
+
return (<div className={[
|
|
32
|
+
'ds_radios',
|
|
33
|
+
'ds_field-group',
|
|
34
|
+
inline && 'ds_field-group--inline',
|
|
35
|
+
className
|
|
36
|
+
].join(' ')} {...props}>
|
|
37
|
+
|
|
38
|
+
{items && items.map((item, index) => (<exports.Radio checked={item.checked} hintText={item.hintText} id={item.id} key={'radio' + index} label={item.label} name={name} onBlur={item.onBlur} onChange={item.onChange} small={small || item.small}/>))}
|
|
39
|
+
</div>);
|
|
40
|
+
};
|
|
41
|
+
exports.Radio.displayName = 'Radio';
|
|
42
|
+
RadioGroup.displayName = 'RadioGroup';
|
|
43
|
+
exports.default = RadioGroup;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const error_message_1 = __importDefault(require("../error-message/error-message"));
|
|
7
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
8
|
+
const Option = function ({ text, value }) {
|
|
9
|
+
return (<option value={value}>{text}</option>);
|
|
10
|
+
};
|
|
11
|
+
const Select = function ({ className, defaultValue, error, errorMessage, hintText, id, label, name, onBlur, onChange, options, placeholder, width, ...props }) {
|
|
12
|
+
const errorMessageId = `error-message-${id}`;
|
|
13
|
+
const hintTextId = `hint-text-${id}`;
|
|
14
|
+
const describedbys = [];
|
|
15
|
+
if (hintText) {
|
|
16
|
+
describedbys.push(hintTextId);
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
if (errorMessage) {
|
|
20
|
+
describedbys.push(errorMessageId);
|
|
21
|
+
}
|
|
22
|
+
;
|
|
23
|
+
function handleBlur(event) {
|
|
24
|
+
if (typeof onBlur === 'function') {
|
|
25
|
+
onBlur(event);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function handleChange(event) {
|
|
29
|
+
if (typeof onChange === 'function') {
|
|
30
|
+
onChange(event);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return (<>
|
|
34
|
+
<label className="ds_label" htmlFor={id}>{label}</label>
|
|
35
|
+
{hintText && <hint_text_1.default id={hintTextId} text={hintText}/>}
|
|
36
|
+
{errorMessage && <error_message_1.default id={errorMessageId} text={errorMessage}/>}
|
|
37
|
+
<div className={[
|
|
38
|
+
"ds_select-wrapper",
|
|
39
|
+
error && 'ds_input--error',
|
|
40
|
+
width && `ds_input--${width}`,
|
|
41
|
+
className
|
|
42
|
+
].join(' ')} {...props}>
|
|
43
|
+
<select aria-describedby={describedbys.join(' ')} className="ds_select" defaultValue={defaultValue} id={id} name={name || id} onBlur={handleBlur} onChange={handleChange}>
|
|
44
|
+
<option value="">{placeholder}</option>
|
|
45
|
+
{options && options.map((option, index) => (<Option value={option.value} text={option.text} key={`option-${index}`}/>))}
|
|
46
|
+
</select>
|
|
47
|
+
<span className="ds_select-arrow" aria-hidden="true"></span>
|
|
48
|
+
</div>
|
|
49
|
+
</>);
|
|
50
|
+
};
|
|
51
|
+
Select.displayName = 'Select';
|
|
52
|
+
exports.default = Select;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const NextLink = ({ href, title }) => {
|
|
4
|
+
return (<div className="ds_sequential-nav__item ds_sequential-nav__item--next">
|
|
5
|
+
<a href={href} className="ds_sequential-nav__button ds_sequential-nav__button--right">
|
|
6
|
+
<span className="ds_sequential-nav__text" data-label="Next">
|
|
7
|
+
{title}
|
|
8
|
+
</span>
|
|
9
|
+
</a>
|
|
10
|
+
</div>);
|
|
11
|
+
};
|
|
12
|
+
const PrevLink = ({ href, title, }) => {
|
|
13
|
+
return (<div className="ds_sequential-nav__item ds_sequential-nav__item--prev">
|
|
14
|
+
<a href={href} className="ds_sequential-nav__button ds_sequential-nav__button--left">
|
|
15
|
+
<span className="ds_sequential-nav__text" data-label="Previous">
|
|
16
|
+
{title}
|
|
17
|
+
</span>
|
|
18
|
+
</a>
|
|
19
|
+
</div>);
|
|
20
|
+
};
|
|
21
|
+
const SequentialNavigation = ({ ariaLabel = 'Article navigation', className, next, previous, ...props }) => {
|
|
22
|
+
return (<nav className={[
|
|
23
|
+
'ds_sequential-nav',
|
|
24
|
+
className
|
|
25
|
+
].join(' ')} aria-label={ariaLabel} {...props}>
|
|
26
|
+
{previous && <PrevLink href={previous.href} title={previous.title}></PrevLink>}
|
|
27
|
+
{next && <NextLink href={next.href} title={next.title}></NextLink>}
|
|
28
|
+
</nav>);
|
|
29
|
+
};
|
|
30
|
+
SequentialNavigation.displayName = 'SequentialNavigation';
|
|
31
|
+
exports.default = SequentialNavigation;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Link = exports.List = void 0;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const side_navigation_1 = __importDefault(require("@scottish-government/design-system/src/components/side-navigation/side-navigation"));
|
|
10
|
+
const List = function ({ items, root }) {
|
|
11
|
+
return (<ul className="ds_side-navigation__list" id={root ? 'side-navigation-root' : undefined}>
|
|
12
|
+
{items && items.map((item, index) => (<exports.Link title={item.title} href={item.href} items={item.items} current={item.current} key={'sidenavitem' + index}/>))}
|
|
13
|
+
</ul>);
|
|
14
|
+
};
|
|
15
|
+
exports.List = List;
|
|
16
|
+
const Link = function ({ current = false, href, items, title }) {
|
|
17
|
+
return (<li className={[
|
|
18
|
+
'ds_side-navigation__item',
|
|
19
|
+
items && 'ds_side-navigation__item--has-children'
|
|
20
|
+
].join(' ')}>
|
|
21
|
+
{current ?
|
|
22
|
+
<span className="ds_side-navigation__link ds_current">{title}</span> :
|
|
23
|
+
<a href={href} className="ds_side-navigation__link">{title}</a>}
|
|
24
|
+
|
|
25
|
+
{items && <exports.List items={items}/>}
|
|
26
|
+
</li>);
|
|
27
|
+
};
|
|
28
|
+
exports.Link = Link;
|
|
29
|
+
const SideNavigation = function ({ children, className, items, ...props }) {
|
|
30
|
+
const ref = (0, react_1.useRef)(null);
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
if (ref.current) {
|
|
33
|
+
new side_navigation_1.default(ref.current).init();
|
|
34
|
+
}
|
|
35
|
+
}, [ref]);
|
|
36
|
+
return (<nav aria-label="Sections" className={[
|
|
37
|
+
'ds_side-navigation',
|
|
38
|
+
className
|
|
39
|
+
].join(' ')} data-module="ds-side-navigation" ref={ref} {...props}>
|
|
40
|
+
<input type="checkbox" className="fully-hidden js-toggle-side-navigation" id="show-side-navigation" aria-controls="side-navigation-root"/>
|
|
41
|
+
<label className="ds_side-navigation__expand ds_link" htmlFor="show-side-navigation">
|
|
42
|
+
<span className="visually-hidden">Show all</span> Pages in this section
|
|
43
|
+
<span className="ds_side-navigation__expand-indicator"></span>
|
|
44
|
+
</label>
|
|
45
|
+
|
|
46
|
+
{items && <exports.List root items={items}/>}
|
|
47
|
+
</nav>);
|
|
48
|
+
};
|
|
49
|
+
SideNavigation.displayName = 'SideNavigation';
|
|
50
|
+
exports.Link.displayName = 'SideNavLink';
|
|
51
|
+
exports.List.displayName = 'SideNavList';
|
|
52
|
+
exports.default = SideNavigation;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SiteNavLink = ({ current = false, href, title }) => {
|
|
4
|
+
return (<li className="ds_site-navigation__item">
|
|
5
|
+
<a href={href} className={[
|
|
6
|
+
'ds_site-navigation__link',
|
|
7
|
+
current ? 'ds_current' : undefined
|
|
8
|
+
].join(' ')}>{title}</a>
|
|
9
|
+
</li>);
|
|
10
|
+
};
|
|
11
|
+
const SiteNavigation = ({ className, items, ...props }) => {
|
|
12
|
+
return (<nav className={[
|
|
13
|
+
'ds_site-navigation',
|
|
14
|
+
className
|
|
15
|
+
].join(' ')} {...props}>
|
|
16
|
+
<ul className="ds_site-navigation__list">
|
|
17
|
+
{items && items.map((item, index) => (<SiteNavLink current={item.current} href={item.href} title={item.title} key={`link-${index}`}/>))}
|
|
18
|
+
</ul>
|
|
19
|
+
</nav>);
|
|
20
|
+
};
|
|
21
|
+
SiteNavigation.displayName = 'SiteNavigation';
|
|
22
|
+
exports.default = SiteNavigation;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const autocomplete_1 = __importDefault(require("@scottish-government/design-system/src/components/autocomplete/autocomplete"));
|
|
9
|
+
const button_1 = __importDefault(require("../button/button"));
|
|
10
|
+
const SiteSearch = function ({ action = '/search', autocompleteEndpoint, autocompleteSuggestionMappingFunction, className, id = 'site-search', method = 'GET', minLength = 3, name = 'q', placeholder = 'Search', ...props }) {
|
|
11
|
+
const ref = (0, react_1.useRef)(null);
|
|
12
|
+
const hasAutocomplete = !!autocompleteEndpoint;
|
|
13
|
+
let autocompleteId = hasAutocomplete ? id + '-autocomplete' : '';
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
if (hasAutocomplete && ref.current) {
|
|
16
|
+
const options = {};
|
|
17
|
+
if (minLength) {
|
|
18
|
+
options.minLength = minLength;
|
|
19
|
+
}
|
|
20
|
+
if (autocompleteSuggestionMappingFunction) {
|
|
21
|
+
options.suggestionMappingFunction = autocompleteSuggestionMappingFunction;
|
|
22
|
+
}
|
|
23
|
+
const autocomplete = new autocomplete_1.default(document.getElementById(autocompleteId), autocompleteEndpoint, options);
|
|
24
|
+
autocomplete.init();
|
|
25
|
+
}
|
|
26
|
+
}, [ref, autocompleteEndpoint, autocompleteId, hasAutocomplete, minLength, autocompleteSuggestionMappingFunction]);
|
|
27
|
+
return (<div className={[
|
|
28
|
+
'ds_site-search', ,
|
|
29
|
+
className,
|
|
30
|
+
hasAutocomplete ? 'ds_autocomplete' : undefined
|
|
31
|
+
].join(' ')} id={autocompleteId ? autocompleteId : undefined} ref={ref} {...props}>
|
|
32
|
+
|
|
33
|
+
<form role="search" className="ds_site-search__form" method={method} action={action}>
|
|
34
|
+
<label className="ds_label visually-hidden" htmlFor={id} id={id + '-label'}>Search</label>
|
|
35
|
+
|
|
36
|
+
{hasAutocomplete && (<div role="status" aria-live="polite" id="autocomplete-status" className="visually-hidden"></div>)}
|
|
37
|
+
|
|
38
|
+
<div className="ds_input__wrapper ds_input__wrapper--has-icon">
|
|
39
|
+
<input aria-autocomplete={hasAutocomplete ? 'list' : undefined} aria-owns={hasAutocomplete ? 'autocomplete-suggestions' : undefined} autoComplete={hasAutocomplete ? 'off' : undefined} className={[
|
|
40
|
+
'ds_input',
|
|
41
|
+
'ds_site-search__input',
|
|
42
|
+
hasAutocomplete ? 'js-autocomplete-input' : undefined
|
|
43
|
+
].join(' ')} id={id} name={name} placeholder={placeholder} required spellCheck="false" type="search"/>
|
|
44
|
+
|
|
45
|
+
<button_1.default type="submit" icon="search" iconOnly>Search</button_1.default>
|
|
46
|
+
|
|
47
|
+
{hasAutocomplete && (<div id="autocomplete-suggestions" className="ds_autocomplete__suggestions">
|
|
48
|
+
<ol className="ds_autocomplete__suggestions-list" role="listbox" aria-labelledby="site-search-label"></ol>
|
|
49
|
+
</div>)}
|
|
50
|
+
</div>
|
|
51
|
+
</form>
|
|
52
|
+
</div>);
|
|
53
|
+
};
|
|
54
|
+
SiteSearch.displayName = 'SiteSearch';
|
|
55
|
+
exports.default = SiteSearch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkipLink = void 0;
|
|
4
|
+
const SkipLink = ({ targetId, title }) => {
|
|
5
|
+
return (<li className="ds_skip-links__item">
|
|
6
|
+
<a href={`#${targetId}`} className="ds_skip-links__link">{title}</a>
|
|
7
|
+
</li>);
|
|
8
|
+
};
|
|
9
|
+
exports.SkipLink = SkipLink;
|
|
10
|
+
const SkipLinks = ({ items, mainContentId = 'main-content', mainLinkText = 'Skip to main content', ...props }) => {
|
|
11
|
+
return (<div className="ds_skip-links" {...props}>
|
|
12
|
+
<ul className="ds_skip-links__list">
|
|
13
|
+
<exports.SkipLink title={mainLinkText} targetId={mainContentId}/>
|
|
14
|
+
|
|
15
|
+
{items && items.map((item, index) => (<exports.SkipLink title={item.title} targetId={item.targetId} key={`skiplink-${index}`}/>))}
|
|
16
|
+
</ul>
|
|
17
|
+
</div>);
|
|
18
|
+
};
|
|
19
|
+
SkipLinks.displayName = 'SkipLinks';
|
|
20
|
+
exports.SkipLink.displayName = 'SkipLink';
|
|
21
|
+
exports.default = SkipLinks;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Tag = ({ className, colour, title, ...props }) => {
|
|
4
|
+
return (<span className={[
|
|
5
|
+
'ds_tag',
|
|
6
|
+
className,
|
|
7
|
+
colour && `ds_tag--${colour}`,
|
|
8
|
+
].join(' ')} {...props}>
|
|
9
|
+
{title}
|
|
10
|
+
</span>);
|
|
11
|
+
};
|
|
12
|
+
Tag.displayName = 'Tag';
|
|
13
|
+
exports.default = Tag;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TaskGroup = exports.Task = void 0;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const conditional_wrapper_1 = __importDefault(require("../../common/conditional-wrapper"));
|
|
9
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
10
|
+
const screen_reader_text_1 = __importDefault(require("../../common/screen-reader-text"));
|
|
11
|
+
const tag_1 = __importDefault(require("../tag/tag"));
|
|
12
|
+
const Task = ({ children, className, href, id, isComplete = false, statusText, tagColour = 'grey', title, ...props }) => {
|
|
13
|
+
if (isComplete) {
|
|
14
|
+
tagColour = 'green';
|
|
15
|
+
}
|
|
16
|
+
return (<li className={[
|
|
17
|
+
'ds_task-list__task',
|
|
18
|
+
className
|
|
19
|
+
].join(' ')} id={id} {...props}>
|
|
20
|
+
<div className="ds_task-list__task-details">
|
|
21
|
+
<h3 className="ds_task-list__task-heading">
|
|
22
|
+
<conditional_wrapper_1.default condition={typeof href !== 'undefined'} wrapper={(children) => <a className="ds_task-list__task-link" href={href}>{children}</a>}>
|
|
23
|
+
{title}
|
|
24
|
+
{statusText && <screen_reader_text_1.default>({statusText})</screen_reader_text_1.default>}
|
|
25
|
+
</conditional_wrapper_1.default>
|
|
26
|
+
</h3>
|
|
27
|
+
<hint_text_1.default className="ds_task-list__task-summary">{children}</hint_text_1.default>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
{typeof statusText !== 'undefined' &&
|
|
31
|
+
<tag_1.default aria-hidden="true" colour={tagColour} title={statusText}/>}
|
|
32
|
+
</li>);
|
|
33
|
+
};
|
|
34
|
+
exports.Task = Task;
|
|
35
|
+
/**
|
|
36
|
+
* @param {Object} props
|
|
37
|
+
* @param {string} props.intro - Intro text
|
|
38
|
+
* @param {string} props.title - The title of the task group
|
|
39
|
+
* @returns {JSX.Element} - The element
|
|
40
|
+
*/
|
|
41
|
+
const TaskGroup = ({ children, className, intro, title, ...props }) => {
|
|
42
|
+
return (<li className={[
|
|
43
|
+
'ds_task-list-group__section',
|
|
44
|
+
className
|
|
45
|
+
].join(' ')} {...props}>
|
|
46
|
+
<h2 className="ds_task-list-heading">{title}</h2>
|
|
47
|
+
{intro && <p className="ds_task-list-intro">{intro}</p>}
|
|
48
|
+
<ul className="ds_task-list">
|
|
49
|
+
{children}
|
|
50
|
+
</ul>
|
|
51
|
+
</li>);
|
|
52
|
+
};
|
|
53
|
+
exports.TaskGroup = TaskGroup;
|
|
54
|
+
const TaskList = ({ children, className, headingId = 'task-list', title, ...props }) => {
|
|
55
|
+
let taskCount = 0;
|
|
56
|
+
let incompleteTaskIds = [];
|
|
57
|
+
let completedTasksCount = 0;
|
|
58
|
+
function processChild(item) {
|
|
59
|
+
if (item.type.displayName === 'Task') {
|
|
60
|
+
taskCount = taskCount + 1;
|
|
61
|
+
if (item.props.isComplete) {
|
|
62
|
+
completedTasksCount = completedTasksCount + 1;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
incompleteTaskIds.push(item.props.id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (item.type.displayName === 'TaskGroup') {
|
|
69
|
+
react_1.Children.forEach(item.props.children, child => {
|
|
70
|
+
processChild(child);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function firstIncompleteTaskLink() {
|
|
75
|
+
if (incompleteTaskIds.length > 0) {
|
|
76
|
+
return (<p><a href={'#' + incompleteTaskIds[0]} className="js-task-list-skip-link">Skip to first incomplete section</a></p>);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
react_1.Children.forEach(children, child => {
|
|
80
|
+
processChild(child);
|
|
81
|
+
});
|
|
82
|
+
return (<div className={className} {...props}>
|
|
83
|
+
<h2 id={`${headingId}-status`} className="ds_task-list-status-heading">{title}</h2>
|
|
84
|
+
<nav aria-labelledby={`${headingId}-status`} className="ds_task-list-status">
|
|
85
|
+
<p>You have completed {completedTasksCount} of {taskCount} sections.</p>
|
|
86
|
+
{firstIncompleteTaskLink()}
|
|
87
|
+
</nav>
|
|
88
|
+
<ul className="ds_task-list">
|
|
89
|
+
{children}
|
|
90
|
+
</ul>
|
|
91
|
+
</div>);
|
|
92
|
+
};
|
|
93
|
+
TaskList.displayName = 'TaskList';
|
|
94
|
+
exports.Task.displayName = 'Task';
|
|
95
|
+
exports.TaskGroup.displayName = 'TaskGroup';
|
|
96
|
+
exports.default = TaskList;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const character_count_1 = __importDefault(require("@scottish-government/design-system/src/forms/character-count/character-count"));
|
|
9
|
+
const button_1 = __importDefault(require("../button/button"));
|
|
10
|
+
const conditional_wrapper_1 = __importDefault(require("../../common/conditional-wrapper"));
|
|
11
|
+
const error_message_1 = __importDefault(require("../error-message/error-message"));
|
|
12
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
13
|
+
const TextInput = ({ buttonIcon, buttonText, children, className, countThreshold, width, currency, currencySymbol, error, errorMessage, hasButton = false, hintText, id, label, maxlength, name, onBlur, onChange, placeholder, type = 'text', value, ...props }) => {
|
|
14
|
+
const errorMessageId = `error-message-${id}`;
|
|
15
|
+
const hintTextId = `hint-text-${id}`;
|
|
16
|
+
const ref = (0, react_1.useRef)(null);
|
|
17
|
+
const inputWrapperClasses = `${hasButton ? 'ds_input__wrapper ds_input__wrapper--has-icon' : ''} ${currency ? 'ds_currency-wrapper' : ''}`;
|
|
18
|
+
const describedbys = [];
|
|
19
|
+
if (hintText) {
|
|
20
|
+
describedbys.push(hintTextId);
|
|
21
|
+
}
|
|
22
|
+
;
|
|
23
|
+
if (errorMessage) {
|
|
24
|
+
describedbys.push(errorMessageId);
|
|
25
|
+
}
|
|
26
|
+
;
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (ref.current) {
|
|
29
|
+
new character_count_1.default(ref.current).init();
|
|
30
|
+
}
|
|
31
|
+
}, [ref]);
|
|
32
|
+
function handleBlur(event) {
|
|
33
|
+
if (typeof onBlur === 'function') {
|
|
34
|
+
onBlur(event);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function handleChange(event) {
|
|
38
|
+
if (typeof onChange === 'function') {
|
|
39
|
+
onChange(event);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return (<conditional_wrapper_1.default condition={typeof maxlength !== 'undefined' && maxlength > 0} wrapper={(children) => <div ref={ref} data-threshold={countThreshold} data-module="ds-character-count">{children}</div>}>
|
|
43
|
+
<label className="ds_label" htmlFor={id}>{label}</label>
|
|
44
|
+
{hintText && <hint_text_1.default id={hintTextId} text={hintText}/>}
|
|
45
|
+
{errorMessage && <error_message_1.default id={errorMessageId} text={errorMessage}/>}
|
|
46
|
+
<conditional_wrapper_1.default condition={hasButton || typeof currency !== 'undefined' && currency} wrapper={(children) => <div className={inputWrapperClasses} data-symbol={currencySymbol}>{children}</div>}>
|
|
47
|
+
<input aria-describedby={describedbys.join(' ')} className={[
|
|
48
|
+
'ds_input',
|
|
49
|
+
className,
|
|
50
|
+
error ? 'ds_input--error' : '',
|
|
51
|
+
width ? `ds_input--${width}` : '',
|
|
52
|
+
].join(' ')} defaultValue={value} id={id} maxLength={maxlength} name={name || id} onBlur={handleBlur} onChange={handleChange} placeholder={placeholder} type={type} {...props}/>
|
|
53
|
+
{hasButton && (buttonText || buttonIcon) && <button_1.default iconOnly icon={buttonIcon}>{buttonText}</button_1.default>}
|
|
54
|
+
</conditional_wrapper_1.default>
|
|
55
|
+
</conditional_wrapper_1.default>);
|
|
56
|
+
};
|
|
57
|
+
TextInput.displayName = 'TextInput';
|
|
58
|
+
exports.default = TextInput;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const character_count_1 = __importDefault(require("@scottish-government/design-system/src/forms/character-count/character-count"));
|
|
9
|
+
const conditional_wrapper_1 = __importDefault(require("../../common/conditional-wrapper"));
|
|
10
|
+
const error_message_1 = __importDefault(require("../error-message/error-message"));
|
|
11
|
+
const hint_text_1 = __importDefault(require("../../common/hint-text"));
|
|
12
|
+
const Textarea = ({ className, countThreshold, error, errorMessage, hintText, id, label, maxlength, name, onBlur, onChange, placeholder, rows = 4, value, ...props }) => {
|
|
13
|
+
const errorMessageId = `error-message-${id}`;
|
|
14
|
+
const hintTextId = `hint-text-${id}`;
|
|
15
|
+
const ref = (0, react_1.useRef)(null);
|
|
16
|
+
const describedbys = [];
|
|
17
|
+
if (hintText) {
|
|
18
|
+
describedbys.push(hintTextId);
|
|
19
|
+
}
|
|
20
|
+
;
|
|
21
|
+
if (errorMessage) {
|
|
22
|
+
describedbys.push(errorMessageId);
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
if (ref.current) {
|
|
27
|
+
new character_count_1.default(ref.current).init();
|
|
28
|
+
}
|
|
29
|
+
}, [ref]);
|
|
30
|
+
function handleBlur(event) {
|
|
31
|
+
if (typeof onBlur === 'function') {
|
|
32
|
+
onBlur(event);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function handleChange(event) {
|
|
36
|
+
if (typeof onChange === 'function') {
|
|
37
|
+
onChange(event);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return (<conditional_wrapper_1.default condition={typeof maxlength !== 'undefined' && maxlength > 0} wrapper={(children) => <div ref={ref} data-threshold={countThreshold} data-module="ds-character-count">{children}</div>}>
|
|
41
|
+
<label className="ds_label" htmlFor={id}>{label}</label>
|
|
42
|
+
{hintText && <hint_text_1.default id={hintTextId} text={hintText}/>}
|
|
43
|
+
{errorMessage && <error_message_1.default id={errorMessageId} text={errorMessage}/>}
|
|
44
|
+
|
|
45
|
+
<textarea aria-describedby={describedbys.join(' ')} className={[
|
|
46
|
+
'ds_input',
|
|
47
|
+
error && 'ds_input--error',
|
|
48
|
+
className
|
|
49
|
+
].join(' ')} defaultValue={value} id={id} maxLength={maxlength} name={name || id} onBlur={handleBlur} onChange={handleChange} placeholder={placeholder} rows={rows} {...props}/>
|
|
50
|
+
|
|
51
|
+
</conditional_wrapper_1.default>);
|
|
52
|
+
};
|
|
53
|
+
Textarea.displayName = 'Textarea';
|
|
54
|
+
exports.default = Textarea;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const WarningText = ({ children, className, ...props }) => {
|
|
4
|
+
return (<div className={[
|
|
5
|
+
'ds_warning-text',
|
|
6
|
+
className
|
|
7
|
+
].join(' ')} {...props}>
|
|
8
|
+
<strong className="ds_warning-text__icon" aria-hidden="true"></strong>
|
|
9
|
+
<strong className="visually-hidden">Warning</strong>
|
|
10
|
+
<div className="ds_warning-text__text">
|
|
11
|
+
{children}
|
|
12
|
+
</div>
|
|
13
|
+
</div>);
|
|
14
|
+
};
|
|
15
|
+
WarningText.displayName = 'WarningText';
|
|
16
|
+
exports.default = WarningText;
|