@uktrade/react-component-library 0.18.2 → 0.19.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/dist/components/ApiBoundary/ApiBoundary.d.ts +4 -5
- package/dist/components/ApiBoundary/ApiBoundary.d.ts.map +1 -1
- package/dist/components/ApiBoundary/ApiBoundary.js +15 -6
- package/package.json +6 -6
- package/src/components/ApiBoundary/ApiBoundary.tsx +20 -35
- package/dist/components/ApiBoundary/ApiBoundary.module.css +0 -30
- package/src/components/ApiBoundary/ApiBoundary.module.css +0 -30
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
interface ApiBoundaryProps {
|
|
2
|
-
isLoading
|
|
3
|
-
isError
|
|
4
|
-
error?:
|
|
5
|
-
onRetry?: () => void;
|
|
2
|
+
isLoading?: boolean;
|
|
3
|
+
isError?: boolean;
|
|
4
|
+
error?: React.ReactNode | Error | null;
|
|
6
5
|
children: React.ReactNode;
|
|
7
6
|
}
|
|
8
|
-
export declare
|
|
7
|
+
export declare function ApiBoundary({ isLoading, isError, error, children }: ApiBoundaryProps): import("react/jsx-runtime").JSX.Element;
|
|
9
8
|
export {};
|
|
10
9
|
//# sourceMappingURL=ApiBoundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ApiBoundary/ApiBoundary.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApiBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ApiBoundary/ApiBoundary.tsx"],"names":[],"mappings":"AAIA,UAAU,gBAAgB;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,OAAe,EACf,KAAK,EACL,QAAQ,EACT,EAAE,gBAAgB,2CAalB"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { LoadingSpinner } from "../LoadingSpinner/LoadingSpinner";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export function ApiBoundary({ isLoading, isError = false, error, children }) {
|
|
5
|
+
if (isLoading) {
|
|
6
|
+
return _jsx(LoadingSpinner, {});
|
|
7
|
+
}
|
|
8
|
+
if (isError) {
|
|
9
|
+
if (error instanceof Error) {
|
|
10
|
+
return _jsx("p", { children: error.message });
|
|
11
|
+
}
|
|
12
|
+
return _jsx(_Fragment, { children: error });
|
|
13
|
+
}
|
|
14
|
+
return _jsx(_Fragment, { children: children });
|
|
15
|
+
}
|
|
16
|
+
;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uktrade/react-component-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A collection of reusable React components following GOV.UK design patterns.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
"@testing-library/user-event": "^14.6.1",
|
|
55
55
|
"@types/react": "^19.2.9",
|
|
56
56
|
"@types/react-dom": "^19.2.3",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
58
|
-
"@typescript-eslint/parser": "^8.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^8.59.0",
|
|
58
|
+
"@typescript-eslint/parser": "^8.59.0",
|
|
59
59
|
"@vitest/coverage-v8": "^4.0.18",
|
|
60
60
|
"@vitest/ui": "^4.0.18",
|
|
61
61
|
"eslint": "^9.39.2",
|
|
62
62
|
"eslint-plugin-react": "^7.37.5",
|
|
63
|
-
"globals": "^17.
|
|
63
|
+
"globals": "^17.5.0",
|
|
64
64
|
"jsdom": "^27.4.0",
|
|
65
|
-
"openapi-typescript": "^7.
|
|
65
|
+
"openapi-typescript": "^7.13.0",
|
|
66
66
|
"typescript": "^5.9.3",
|
|
67
|
-
"typescript-eslint": "^8.
|
|
67
|
+
"typescript-eslint": "^8.59.0",
|
|
68
68
|
"vitest": "^4.0.18"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
@@ -1,45 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
2
3
|
import { LoadingSpinner } from "../LoadingSpinner/LoadingSpinner";
|
|
3
|
-
import styles from "./ApiBoundary.module.css";
|
|
4
|
-
import { Button } from "../Button";
|
|
5
4
|
|
|
6
5
|
interface ApiBoundaryProps {
|
|
7
|
-
isLoading
|
|
8
|
-
isError
|
|
9
|
-
error?:
|
|
10
|
-
onRetry?: () => void;
|
|
6
|
+
isLoading?: boolean;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
error?: React.ReactNode | Error | null;
|
|
11
9
|
children: React.ReactNode;
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
export const ApiBoundary = ({
|
|
12
|
+
export function ApiBoundary({
|
|
16
13
|
isLoading,
|
|
17
|
-
isError,
|
|
14
|
+
isError = false,
|
|
18
15
|
error,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
children
|
|
17
|
+
}: ApiBoundaryProps) {
|
|
18
|
+
if (isLoading) {
|
|
19
|
+
return <LoadingSpinner />;
|
|
20
|
+
}
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
if (isError) {
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
return <p>{error.message}</p>;
|
|
25
|
+
}
|
|
26
|
+
return <>{error}</>;
|
|
27
|
+
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<div className={styles.errorBackdrop} />
|
|
30
|
-
<section className={styles.error}>
|
|
31
|
-
<h2 className="govuk-heading-m">Error!</h2>
|
|
32
|
-
<pre className={styles.description}>
|
|
33
|
-
{typeof error === "string" ? error : JSON.stringify(error, null, 2)}
|
|
34
|
-
</pre>
|
|
35
|
-
|
|
36
|
-
{onRetry && (
|
|
37
|
-
<Button variant="warning" onClick={onRetry}>
|
|
38
|
-
Retry
|
|
39
|
-
</Button>
|
|
40
|
-
)}
|
|
41
|
-
</section>
|
|
42
|
-
</>
|
|
43
|
-
)}
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
29
|
+
return <>{children}</>;
|
|
30
|
+
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
.hods-loading-spinner {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
align-items: center;
|
|
5
|
-
justify-content: center;
|
|
6
|
-
padding-top: 1rem;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.hods-loading-spinner__spinner {
|
|
10
|
-
width: 80px;
|
|
11
|
-
height: 80px;
|
|
12
|
-
border: 12px solid #dee0e2;
|
|
13
|
-
border-top-color: #1d70b8; /* GOV.UK blue */
|
|
14
|
-
border-radius: 50%;
|
|
15
|
-
animation: hods-loading-spinner-rotate 1.5s linear infinite;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.hods-loading-spinner__content {
|
|
19
|
-
margin-top: 1rem;
|
|
20
|
-
text-align: center;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@keyframes hods-loading-spinner-rotate {
|
|
24
|
-
from {
|
|
25
|
-
transform: rotate(0deg);
|
|
26
|
-
}
|
|
27
|
-
to {
|
|
28
|
-
transform: rotate(360deg);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
.hods-loading-spinner {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
align-items: center;
|
|
5
|
-
justify-content: center;
|
|
6
|
-
padding-top: 1rem;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.hods-loading-spinner__spinner {
|
|
10
|
-
width: 80px;
|
|
11
|
-
height: 80px;
|
|
12
|
-
border: 12px solid #dee0e2;
|
|
13
|
-
border-top-color: #1d70b8; /* GOV.UK blue */
|
|
14
|
-
border-radius: 50%;
|
|
15
|
-
animation: hods-loading-spinner-rotate 1.5s linear infinite;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.hods-loading-spinner__content {
|
|
19
|
-
margin-top: 1rem;
|
|
20
|
-
text-align: center;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@keyframes hods-loading-spinner-rotate {
|
|
24
|
-
from {
|
|
25
|
-
transform: rotate(0deg);
|
|
26
|
-
}
|
|
27
|
-
to {
|
|
28
|
-
transform: rotate(360deg);
|
|
29
|
-
}
|
|
30
|
-
}
|