@not-govuk/back-link 0.9.1 → 0.10.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.
@@ -1,7 +1,8 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  import { StandardProps } from '@not-govuk/component-helpers';
3
3
  import '../assets/BackLink.scss';
4
4
  export type BackLinkProps = StandardProps & {
5
+ children?: ReactNode;
5
6
  /** The location to link to */
6
7
  href?: string;
7
8
  /** The text of the link */
package/dist/BackLink.js CHANGED
@@ -6,10 +6,11 @@ const react_router_dom_1 = require("react-router-dom");
6
6
  const component_helpers_1 = require("@not-govuk/component-helpers");
7
7
  const link_1 = require("@not-govuk/link");
8
8
  require("../assets/BackLink.scss");
9
- const BackLink = ({ children, classBlock, classModifiers, className, href, text = 'Back', ...attrs }) => {
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
12
  const history = (0, react_router_dom_1.useHistory)();
13
+ const text = _text || children || 'Back';
13
14
  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: history.goBack }, text));
14
15
  };
15
16
  exports.BackLink = BackLink;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@not-govuk/back-link",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
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,15 +14,15 @@
14
14
  "react-components"
15
15
  ],
16
16
  "dependencies": {
17
- "@not-govuk/component-helpers": "^0.9.1",
18
- "@not-govuk/link": "^0.9.1",
19
- "@not-govuk/sass-base": "^0.9.1",
17
+ "@not-govuk/component-helpers": "^0.10.0",
18
+ "@not-govuk/link": "^0.10.0",
19
+ "@not-govuk/sass-base": "^0.10.0",
20
20
  "govuk-frontend": "4.8.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@not-govuk/docs-components": "^0.9.1",
23
+ "@not-govuk/docs-components": "^0.10.0",
24
24
  "@storybook/addon-docs": "^6.5.16",
25
- "react": "^16.14.0"
25
+ "react": "^16.14.0 || ^18.0.0"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@not-govuk/docs-components": {
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@mdx-js/react": "1.6.22",
37
- "@not-govuk/component-test-helpers": "^0.9.1",
38
- "@not-govuk/panel": "^0.9.1",
37
+ "@not-govuk/component-test-helpers": "^0.10.0",
38
+ "@not-govuk/panel": "^0.10.0",
39
39
  "@types/react": "16.14.60",
40
40
  "jest": "29.7.0",
41
41
  "jest-environment-jsdom": "29.7.0",
package/src/BackLink.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { FC, createElement as h } from 'react';
1
+ import { FC, ReactNode, createElement as h } from 'react';
2
2
  import { useHistory } from 'react-router-dom';
3
3
  import { StandardProps, classBuilder } from '@not-govuk/component-helpers';
4
4
  import { A } from '@not-govuk/link';
@@ -6,18 +6,28 @@ import { A } from '@not-govuk/link';
6
6
  import '../assets/BackLink.scss';
7
7
 
8
8
  export type BackLinkProps = StandardProps & {
9
+ children?: ReactNode
9
10
  /** The location to link to */
10
- href?: string,
11
+ href?: string
11
12
  /** The text of the link */
12
- text?: string,
13
+ text?: string
13
14
  /** The title of the link */
14
15
  title?: string
15
16
  };
16
17
 
17
- export const BackLink: FC<BackLinkProps> = ({ children, classBlock, classModifiers, className, href, text = 'Back', ...attrs }) => {
18
+ export const BackLink: FC<BackLinkProps> = ({
19
+ children,
20
+ classBlock,
21
+ classModifiers,
22
+ className,
23
+ href,
24
+ text: _text,
25
+ ...attrs
26
+ }) => {
18
27
  const defaultClassBlock = 'govuk-back-link';
19
28
  const classes = classBuilder(defaultClassBlock, classBlock, classModifiers, className);
20
29
  const history = useHistory();
30
+ const text = _text || children || 'Back';
21
31
 
22
32
  return href ? (
23
33
  <A {...attrs}