@uktrade/react-component-library 0.16.0 → 0.18.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.
@@ -6,6 +6,7 @@ interface CheckboxOption {
6
6
  value: string;
7
7
  label: ReactNode;
8
8
  checked?: boolean;
9
+ hint?: string;
9
10
  }
10
11
  interface CheckboxGroupProps {
11
12
  legend: ReactNode;
@@ -17,7 +18,8 @@ interface CheckboxGroupProps {
17
18
  legendSize?: LegendSize;
18
19
  checkboxSize?: "small" | "default";
19
20
  onChange?: (values: string[]) => void;
21
+ values: string[];
20
22
  }
21
- export declare const CheckboxGroup: ({ legend, hint, error, options, name, legendAs, legendSize, checkboxSize, onChange, }: CheckboxGroupProps) => import("react/jsx-runtime").JSX.Element;
23
+ export declare const CheckboxGroup: ({ legend, hint, error, options, name, values, legendAs, legendSize, checkboxSize, onChange, }: CheckboxGroupProps) => import("react/jsx-runtime").JSX.Element;
22
24
  export {};
23
25
  //# 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,EA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ACtC,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,GAAI,+FAW3B,kBAAkB,4CA6EpB,CAAC"}
@@ -2,7 +2,7 @@
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", onChange, }) => {
5
+ export const CheckboxGroup = ({ legend, hint, error, options, name, values, 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);
@@ -19,5 +19,5 @@ export const CheckboxGroup = ({ legend, hint, error, options, name, legendAs = "
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, defaultChecked: opt.checked, onChange: handleChange }), _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, 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))) })] }) }));
23
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uktrade/react-component-library",
3
- "version": "0.16.0",
3
+ "version": "0.18.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",
@@ -12,6 +12,7 @@ interface CheckboxOption {
12
12
  value: string;
13
13
  label: ReactNode;
14
14
  checked?: boolean;
15
+ hint?: string;
15
16
  }
16
17
 
17
18
  interface CheckboxGroupProps {
@@ -24,6 +25,7 @@ interface CheckboxGroupProps {
24
25
  legendSize?: LegendSize;
25
26
  checkboxSize?: "small" | "default";
26
27
  onChange?: (values: string[]) => void;
28
+ values: string[];
27
29
  }
28
30
 
29
31
  export const CheckboxGroup = ({
@@ -32,6 +34,7 @@ export const CheckboxGroup = ({
32
34
  error,
33
35
  options,
34
36
  name,
37
+ values,
35
38
  legendAs = "h4",
36
39
  legendSize = "m",
37
40
  checkboxSize = "default",
@@ -93,7 +96,7 @@ export const CheckboxGroup = ({
93
96
  name={name}
94
97
  type="checkbox"
95
98
  value={opt.value}
96
- defaultChecked={opt.checked}
99
+ checked={values.includes(opt.value)}
97
100
  onChange={handleChange}
98
101
  />
99
102
  <label
@@ -102,6 +105,11 @@ export const CheckboxGroup = ({
102
105
  >
103
106
  {opt.label}
104
107
  </label>
108
+ {opt.hint && (
109
+ <div className="govuk-hint govuk-checkboxes__hint">
110
+ {opt.hint}
111
+ </div>
112
+ )}
105
113
  </div>
106
114
  ))}
107
115
  </div>