@uktrade/react-component-library 0.14.0 → 0.15.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.
@@ -16,7 +16,8 @@ interface CheckboxGroupProps {
16
16
  legendAs?: LegendAs;
17
17
  legendSize?: LegendSize;
18
18
  checkboxSize?: "small" | "default";
19
+ onChange?: (values: string[]) => void;
19
20
  }
20
- export declare const CheckboxGroup: ({ legend, hint, error, options, name, legendAs, legendSize, checkboxSize }: CheckboxGroupProps) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const CheckboxGroup: ({ legend, hint, error, options, name, legendAs, legendSize, checkboxSize, onChange, }: CheckboxGroupProps) => import("react/jsx-runtime").JSX.Element;
21
22
  export {};
22
23
  //# sourceMappingURL=CheckBoxGroupInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CheckBoxGroupInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,KAAK,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1C,KAAK,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzC,UAAU,cAAc;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;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;CACtC;AAED,eAAO,MAAM,aAAa,GAAI,4EAS3B,kBAAkB,4CA+DpB,CAAC"}
1
+ {"version":3,"file":"CheckBoxGroupInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,KAAK,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1C,KAAK,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzC,UAAU,cAAc;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;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;CACzC;AAED,eAAO,MAAM,aAAa,GAAI,uFAU3B,kBAAkB,4CAwEpB,CAAC"}
@@ -2,15 +2,22 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import clsx from "clsx";
4
4
  import { createElement } from "react";
5
- export const CheckboxGroup = ({ legend, hint, error, options, name, legendAs = "h4", legendSize = "m", checkboxSize = "default" }) => {
5
+ export const CheckboxGroup = ({ legend, hint, error, options, name, legendAs = "h4", legendSize = "m", checkboxSize = "default", onChange, }) => {
6
6
  const hasError = Boolean(error);
7
7
  const errorId = hasError ? `${name}-error` : undefined;
8
8
  const legendHeading = createElement(legendAs, { className: "govuk-fieldset__heading" }, legend);
9
+ const handleChange = () => {
10
+ if (!onChange)
11
+ return;
12
+ const inputs = document.querySelectorAll(`input[name="${name}"]:checked`);
13
+ const values = Array.from(inputs).map((el) => el.value);
14
+ onChange(values);
15
+ };
9
16
  return (_jsx("div", { className: clsx("govuk-form-group", {
10
17
  "govuk-form-group--error": hasError,
11
18
  }), children: _jsxs("fieldset", { className: "govuk-fieldset", "aria-describedby": errorId, children: [_jsx("legend", { className: clsx("govuk-fieldset__legend", {
12
19
  [`govuk-fieldset__legend--${legendSize}`]: legendSize !== "m",
13
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", {
14
21
  "govuk-checkboxes--small": checkboxSize === "small",
15
- }), "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, defaultChecked: opt.checked }), _jsx("label", { className: "govuk-label govuk-checkboxes__label", htmlFor: opt.id, children: opt.label })] }, 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, defaultChecked: opt.checked, onChange: handleChange }), _jsx("label", { className: "govuk-label govuk-checkboxes__label", htmlFor: opt.id, children: opt.label })] }, opt.id))) })] }) }));
16
23
  };
@@ -12,6 +12,8 @@ export interface SummaryCardProps extends React.HTMLAttributes<HTMLDivElement> {
12
12
  children?: React.ReactNode;
13
13
  actions?: SummaryListAction[];
14
14
  className?: string;
15
+ titleBackground?: string;
16
+ subSectionNode?: React.ReactNode;
15
17
  }
16
- export declare const SummaryCard: ({ title, children, actions, className, ...props }: SummaryCardProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const SummaryCard: ({ title, children, actions, className, titleBackground, subSectionNode, ...props }: SummaryCardProps) => import("react/jsx-runtime").JSX.Element;
17
19
  //# sourceMappingURL=SummaryList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SummaryList.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryList/SummaryList.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,GAAI,0CAA0C,gBAAgB,4CAOrF,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,GAAI,mDAAmD,gBAAgB,4CAgC9F,CAAC"}
1
+ {"version":3,"file":"SummaryList.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryList/SummaryList.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,GAAI,0CAA0C,gBAAgB,4CAOrF,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAClC;AAED,eAAO,MAAM,WAAW,GAAI,oFAQzB,gBAAgB,4CAyClB,CAAC"}
@@ -4,4 +4,4 @@ import clsx from "clsx";
4
4
  import { SummaryListAction } from "../SummaryItem/SummaryItem";
5
5
  import styles from "./SummaryList.module.css";
6
6
  export const SummaryList = ({ title, children, className, ...props }) => (_jsxs(_Fragment, { children: [title && _jsx("h2", { className: "govuk-heading-l", children: title }), _jsx("dl", { className: clsx("govuk-summary-list", className), ...props, children: children })] }));
7
- export const SummaryCard = ({ title, children, actions, className, ...props }) => (_jsx("div", { className: clsx(styles.root, className), children: _jsxs("div", { className: "govuk-summary-card govuk-body", ...props, children: [_jsxs("div", { className: "govuk-summary-card__title-wrapper", children: [_jsx("h2", { className: "govuk-summary-card__title", children: title }), actions && (_jsx("ul", { className: clsx("govuk-summary-card__actions", styles.summaryCardTitleActions), children: actions.map((action) => (_jsx("li", { className: "govuk-summary-card__action", children: _jsx(SummaryListAction, { action: action }) }, action.text))) }))] }), _jsx("div", { className: clsx("govuk-summary-card__content", styles.govukSummaryCardContent), children: children })] }) }));
7
+ export const SummaryCard = ({ title, children, actions, className, titleBackground, subSectionNode, ...props }) => (_jsx("div", { className: clsx(styles.root, className), children: _jsxs("div", { className: "govuk-summary-card govuk-body", ...props, children: [_jsxs("div", { className: "govuk-summary-card__title-wrapper", style: titleBackground ? { background: titleBackground } : undefined, children: [_jsx("h2", { className: "govuk-summary-card__title", children: title }), actions && (_jsx("ul", { className: clsx("govuk-summary-card__actions", styles.summaryCardTitleActions), children: actions.map((action) => (_jsx("li", { className: "govuk-summary-card__action", children: _jsx(SummaryListAction, { action: action }) }, action.text))) }))] }), subSectionNode && (_jsx("div", { children: subSectionNode })), _jsx("div", { className: clsx("govuk-summary-card__content", styles.govukSummaryCardContent), children: children })] }) }));
@@ -11,4 +11,4 @@
11
11
  .summaryCardTitleActions {
12
12
  font-weight: 400;
13
13
  }
14
- }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uktrade/react-component-library",
3
- "version": "0.14.0",
3
+ "version": "0.15.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",
@@ -51,6 +51,7 @@
51
51
  "@eslint/js": "^9.39.2",
52
52
  "@testing-library/jest-dom": "^6.9.1",
53
53
  "@testing-library/react": "^16.3.2",
54
+ "@testing-library/user-event": "^14.6.1",
54
55
  "@types/react": "^19.2.9",
55
56
  "@types/react-dom": "^19.2.3",
56
57
  "@typescript-eslint/eslint-plugin": "^8.53.1",
@@ -23,6 +23,7 @@ interface CheckboxGroupProps {
23
23
  legendAs?: LegendAs;
24
24
  legendSize?: LegendSize;
25
25
  checkboxSize?: "small" | "default";
26
+ onChange?: (values: string[]) => void;
26
27
  }
27
28
 
28
29
  export const CheckboxGroup = ({
@@ -33,7 +34,8 @@ export const CheckboxGroup = ({
33
34
  name,
34
35
  legendAs = "h4",
35
36
  legendSize = "m",
36
- checkboxSize = "default"
37
+ checkboxSize = "default",
38
+ onChange,
37
39
  }: CheckboxGroupProps) => {
38
40
  const hasError = Boolean(error);
39
41
  const errorId = hasError ? `${name}-error` : undefined;
@@ -41,9 +43,19 @@ export const CheckboxGroup = ({
41
43
  const legendHeading = createElement(
42
44
  legendAs,
43
45
  { className: "govuk-fieldset__heading" },
44
- legend
46
+ legend,
45
47
  );
46
48
 
49
+ const handleChange = () => {
50
+ if (!onChange) return;
51
+
52
+ const inputs = document.querySelectorAll<HTMLInputElement>(
53
+ `input[name="${name}"]:checked`,
54
+ );
55
+ const values = Array.from(inputs).map((el) => el.value);
56
+ onChange(values);
57
+ };
58
+
47
59
  return (
48
60
  <div
49
61
  className={clsx("govuk-form-group", {
@@ -53,8 +65,7 @@ export const CheckboxGroup = ({
53
65
  <fieldset className="govuk-fieldset" aria-describedby={errorId}>
54
66
  <legend
55
67
  className={clsx("govuk-fieldset__legend", {
56
- [`govuk-fieldset__legend--${legendSize}`]:
57
- legendSize !== "m",
68
+ [`govuk-fieldset__legend--${legendSize}`]: legendSize !== "m",
58
69
  })}
59
70
  >
60
71
  {legendHeading}
@@ -64,8 +75,7 @@ export const CheckboxGroup = ({
64
75
 
65
76
  {hasError && (
66
77
  <p id={errorId} className="govuk-error-message">
67
- <span className="govuk-visually-hidden">Error:</span>{" "}
68
- {error}
78
+ <span className="govuk-visually-hidden">Error:</span> {error}
69
79
  </p>
70
80
  )}
71
81
 
@@ -84,6 +94,7 @@ export const CheckboxGroup = ({
84
94
  type="checkbox"
85
95
  value={opt.value}
86
96
  defaultChecked={opt.checked}
97
+ onChange={handleChange}
87
98
  />
88
99
  <label
89
100
  className="govuk-label govuk-checkboxes__label"
@@ -11,4 +11,4 @@
11
11
  .summaryCardTitleActions {
12
12
  font-weight: 400;
13
13
  }
14
- }
14
+ }
@@ -27,12 +27,25 @@ export interface SummaryCardProps extends React.HTMLAttributes<HTMLDivElement> {
27
27
  children?: React.ReactNode;
28
28
  actions?: SummaryListAction[];
29
29
  className?: string;
30
+ titleBackground?: string;
31
+ subSectionNode?: React.ReactNode;
30
32
  }
31
33
 
32
- export const SummaryCard = ({ title, children, actions, className, ...props }: SummaryCardProps) => (
34
+ export const SummaryCard = ({
35
+ title,
36
+ children,
37
+ actions,
38
+ className,
39
+ titleBackground,
40
+ subSectionNode,
41
+ ...props
42
+ }: SummaryCardProps) => (
33
43
  <div className={clsx(styles.root, className)}>
34
44
  <div className="govuk-summary-card govuk-body" {...props}>
35
- <div className="govuk-summary-card__title-wrapper">
45
+ <div
46
+ className="govuk-summary-card__title-wrapper"
47
+ style={titleBackground ? { background: titleBackground } : undefined}
48
+ >
36
49
  <h2 className="govuk-summary-card__title">{title}</h2>
37
50
 
38
51
  {actions && (
@@ -51,6 +64,12 @@ export const SummaryCard = ({ title, children, actions, className, ...props }: S
51
64
  )}
52
65
  </div>
53
66
 
67
+ {subSectionNode && (
68
+ <div>
69
+ {subSectionNode}
70
+ </div>
71
+ )}
72
+
54
73
  <div
55
74
  className={clsx(
56
75
  "govuk-summary-card__content",