@not-govuk/back-link 0.10.0 → 0.11.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/dist/BackLink.js +3 -2
- package/package.json +8 -8
- package/src/BackLink.tsx +4 -3
package/dist/BackLink.js
CHANGED
|
@@ -9,9 +9,10 @@ require("../assets/BackLink.scss");
|
|
|
9
9
|
const BackLink = ({ children, classBlock, classModifiers, className, href, text: _text, ...attrs }) => {
|
|
10
10
|
const defaultClassBlock = 'govuk-back-link';
|
|
11
11
|
const classes = (0, component_helpers_1.classBuilder)(defaultClassBlock, classBlock, classModifiers, className);
|
|
12
|
-
const
|
|
12
|
+
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
13
13
|
const text = _text || children || 'Back';
|
|
14
|
-
|
|
14
|
+
const goBack = () => navigate(-1);
|
|
15
|
+
return href ? ((0, react_1.createElement)(link_1.A, { ...attrs, classBlock: classBlock || defaultClassBlock, classModifiers: classModifiers, className: className, href: href }, text)) : ((0, react_1.createElement)("a", { ...attrs, className: classes(), href: "#", onClick: goBack }, text));
|
|
15
16
|
};
|
|
16
17
|
exports.BackLink = BackLink;
|
|
17
18
|
exports.default = exports.BackLink;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@not-govuk/back-link",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "A component to help users navigate back one page.",
|
|
5
5
|
"main": "dist/BackLink.js",
|
|
6
6
|
"sass": "assets/BackLink.scss",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"react-components"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@not-govuk/component-helpers": "^0.
|
|
18
|
-
"@not-govuk/link": "^0.
|
|
19
|
-
"@not-govuk/sass-base": "^0.
|
|
17
|
+
"@not-govuk/component-helpers": "^0.11.1",
|
|
18
|
+
"@not-govuk/link": "^0.11.1",
|
|
19
|
+
"@not-govuk/sass-base": "^0.11.1",
|
|
20
20
|
"govuk-frontend": "4.8.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@not-govuk/docs-components": "^0.
|
|
23
|
+
"@not-govuk/docs-components": "^0.11.1",
|
|
24
24
|
"@storybook/addon-docs": "^6.5.16",
|
|
25
25
|
"react": "^16.14.0 || ^18.0.0"
|
|
26
26
|
},
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@mdx-js/react": "1.6.22",
|
|
37
|
-
"@not-govuk/component-test-helpers": "^0.
|
|
38
|
-
"@not-govuk/panel": "^0.
|
|
37
|
+
"@not-govuk/component-test-helpers": "^0.11.1",
|
|
38
|
+
"@not-govuk/panel": "^0.11.1",
|
|
39
39
|
"@types/react": "16.14.60",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
41
|
"jest-environment-jsdom": "29.7.0",
|
|
42
|
-
"ts-jest": "29.2.
|
|
42
|
+
"ts-jest": "29.2.5",
|
|
43
43
|
"typescript": "4.9.5"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
package/src/BackLink.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC, ReactNode, createElement as h } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
3
|
import { StandardProps, classBuilder } from '@not-govuk/component-helpers';
|
|
4
4
|
import { A } from '@not-govuk/link';
|
|
5
5
|
|
|
@@ -26,8 +26,9 @@ export const BackLink: FC<BackLinkProps> = ({
|
|
|
26
26
|
}) => {
|
|
27
27
|
const defaultClassBlock = 'govuk-back-link';
|
|
28
28
|
const classes = classBuilder(defaultClassBlock, classBlock, classModifiers, className);
|
|
29
|
-
const
|
|
29
|
+
const navigate = useNavigate();
|
|
30
30
|
const text = _text || children || 'Back';
|
|
31
|
+
const goBack = () => navigate(-1);
|
|
31
32
|
|
|
32
33
|
return href ? (
|
|
33
34
|
<A {...attrs}
|
|
@@ -42,7 +43,7 @@ export const BackLink: FC<BackLinkProps> = ({
|
|
|
42
43
|
<a {...attrs}
|
|
43
44
|
className={classes()}
|
|
44
45
|
href="#"
|
|
45
|
-
onClick={
|
|
46
|
+
onClick={goBack}
|
|
46
47
|
>
|
|
47
48
|
{text}
|
|
48
49
|
</a>
|