@uktrade/react-component-library 0.18.1 → 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.
@@ -1,10 +1,9 @@
1
1
  interface ApiBoundaryProps {
2
- isLoading: boolean;
3
- isError: boolean;
4
- error?: unknown;
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 const ApiBoundary: ({ isLoading, isError, error, onRetry, children, }: ApiBoundaryProps) => import("react/jsx-runtime").JSX.Element;
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":"AAKA,UAAU,gBAAgB;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAGD,eAAO,MAAM,WAAW,GAAI,mDAMzB,gBAAgB,4CAwBlB,CAAC"}
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
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- // import { LoadingBox } from "govuk-react";
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { LoadingSpinner } from "../LoadingSpinner/LoadingSpinner";
4
- import styles from "./ApiBoundary.module.css";
5
- import { Button } from "../Button";
6
- /* Boundary for API-related states: loading, success, and error */
7
- export const ApiBoundary = ({ isLoading, isError, error, onRetry, children, }) => (_jsxs("div", { className: styles.root, "aria-live": "polite", children: [isLoading && _jsx(LoadingSpinner, {}), !isLoading && !isError && children, isError && (_jsxs(_Fragment, { children: [_jsx("div", { className: styles.errorBackdrop }), _jsxs("section", { className: styles.error, children: [_jsx("h2", { className: "govuk-heading-m", children: "Error!" }), _jsx("pre", { className: styles.description, children: typeof error === "string" ? error : JSON.stringify(error, null, 2) }), onRetry && (_jsx(Button, { variant: "warning", onClick: onRetry, children: "Retry" }))] })] }))] }));
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
+ ;
@@ -7,6 +7,7 @@ interface CheckboxOption {
7
7
  label: ReactNode;
8
8
  checked?: boolean;
9
9
  hint?: string;
10
+ ariaLabel?: string;
10
11
  }
11
12
  interface CheckboxGroupProps {
12
13
  legend: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"CheckBoxGroupInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAA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AAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,UAAU,kBAAkB;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,GAAI,+FAW3B,kBAAkB,4CA8EpB,CAAC"}
@@ -19,5 +19,5 @@ export const CheckboxGroup = ({ legend, hint, error, options, name, values, lege
19
19
  [`govuk-fieldset__legend--${legendSize}`]: legendSize !== "m",
20
20
  }), children: legendHeading }), hint && _jsx("div", { className: "govuk-hint", children: hint }), hasError && (_jsxs("p", { id: errorId, className: "govuk-error-message", children: [_jsx("span", { className: "govuk-visually-hidden", children: "Error:" }), " ", error] })), _jsx("div", { className: clsx("govuk-checkboxes", {
21
21
  "govuk-checkboxes--small": checkboxSize === "small",
22
- }), "data-module": "govuk-checkboxes", children: options.map((opt) => (_jsxs("div", { className: "govuk-checkboxes__item", children: [_jsx("input", { className: "govuk-checkboxes__input", id: opt.id, name: name, type: "checkbox", value: opt.value, checked: values.includes(opt.value), onChange: handleChange }), _jsx("label", { className: "govuk-label govuk-checkboxes__label", htmlFor: opt.id, children: opt.label }), opt.hint && (_jsx("div", { className: "govuk-hint govuk-checkboxes__hint", children: opt.hint }))] }, opt.id))) })] }) }));
22
+ }), "data-module": "govuk-checkboxes", children: options.map((opt) => (_jsxs("div", { className: "govuk-checkboxes__item", children: [_jsx("input", { className: "govuk-checkboxes__input", id: opt.id, name: name, type: "checkbox", value: opt.value, checked: values.includes(opt.value), onChange: handleChange, "aria-label": opt.ariaLabel }), _jsx("label", { className: "govuk-label govuk-checkboxes__label", htmlFor: opt.id, children: opt.label }), opt.hint && (_jsx("div", { className: "govuk-hint govuk-checkboxes__hint", children: opt.hint }))] }, opt.id))) })] }) }));
23
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uktrade/react-component-library",
3
- "version": "0.18.1",
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.53.1",
58
- "@typescript-eslint/parser": "^8.53.1",
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.2.0",
63
+ "globals": "^17.5.0",
64
64
  "jsdom": "^27.4.0",
65
- "openapi-typescript": "^7.10.1",
65
+ "openapi-typescript": "^7.13.0",
66
66
  "typescript": "^5.9.3",
67
- "typescript-eslint": "^8.53.1",
67
+ "typescript-eslint": "^8.59.0",
68
68
  "vitest": "^4.0.18"
69
69
  },
70
70
  "engines": {
@@ -1,45 +1,30 @@
1
- // import { LoadingBox } from "govuk-react";
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: boolean;
8
- isError: boolean;
9
- error?: unknown;
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
- /* Boundary for API-related states: loading, success, and error */
15
- export const ApiBoundary = ({
12
+ export function ApiBoundary({
16
13
  isLoading,
17
- isError,
14
+ isError = false,
18
15
  error,
19
- onRetry,
20
- children,
21
- }: ApiBoundaryProps) => (
22
- <div className={styles.root} aria-live="polite">
23
- {isLoading && <LoadingSpinner />}
16
+ children
17
+ }: ApiBoundaryProps) {
18
+ if (isLoading) {
19
+ return <LoadingSpinner />;
20
+ }
24
21
 
25
- {!isLoading && !isError && children}
22
+ if (isError) {
23
+ if (error instanceof Error) {
24
+ return <p>{error.message}</p>;
25
+ }
26
+ return <>{error}</>;
27
+ }
26
28
 
27
- {isError && (
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
+ };
@@ -13,6 +13,7 @@ interface CheckboxOption {
13
13
  label: ReactNode;
14
14
  checked?: boolean;
15
15
  hint?: string;
16
+ ariaLabel?: string
16
17
  }
17
18
 
18
19
  interface CheckboxGroupProps {
@@ -98,6 +99,7 @@ export const CheckboxGroup = ({
98
99
  value={opt.value}
99
100
  checked={values.includes(opt.value)}
100
101
  onChange={handleChange}
102
+ aria-label={opt.ariaLabel}
101
103
  />
102
104
  <label
103
105
  className="govuk-label govuk-checkboxes__label"
@@ -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
- }