@uktrade/react-component-library 0.21.2 → 0.21.4

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.
Files changed (31) hide show
  1. package/dist/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.d.ts +1 -0
  2. package/dist/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.d.ts.map +1 -1
  3. package/dist/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.js +2 -1
  4. package/dist/components/Inputs/SelectInput/SelectInput.d.ts +2 -1
  5. package/dist/components/Inputs/SelectInput/SelectInput.d.ts.map +1 -1
  6. package/dist/components/Inputs/SelectInput/SelectInput.js +4 -3
  7. package/dist/components/Inputs/TextInput/TextInput.d.ts +2 -1
  8. package/dist/components/Inputs/TextInput/TextInput.d.ts.map +1 -1
  9. package/dist/components/Inputs/TextInput/TextInput.js +4 -3
  10. package/dist/components/SummaryItem/SummaryItem.d.ts.map +1 -1
  11. package/dist/components/SummaryItem/SummaryItem.module.css +2 -1
  12. package/dist/components/Tooltip/Tooltip.d.ts +8 -0
  13. package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
  14. package/dist/components/Tooltip/Tooltip.js +28 -0
  15. package/dist/components/Tooltip/Tooltip.module.css +37 -0
  16. package/dist/components/Tooltip/TooltipInfoIcon.d.ts +3 -0
  17. package/dist/components/Tooltip/TooltipInfoIcon.d.ts.map +1 -0
  18. package/dist/components/Tooltip/TooltipInfoIcon.js +2 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -0
  22. package/package.json +1 -1
  23. package/src/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.tsx +9 -0
  24. package/src/components/Inputs/SelectInput/SelectInput.tsx +10 -0
  25. package/src/components/Inputs/TextInput/TextInput.tsx +10 -0
  26. package/src/components/SummaryItem/SummaryItem.module.css +2 -1
  27. package/src/components/SummaryItem/SummaryItem.tsx +1 -2
  28. package/src/components/Tooltip/Tooltip.module.css +37 -0
  29. package/src/components/Tooltip/Tooltip.tsx +73 -0
  30. package/src/components/Tooltip/TooltipInfoIcon.tsx +21 -0
  31. package/src/index.ts +1 -0
@@ -8,6 +8,7 @@ interface CheckboxOption {
8
8
  checked?: boolean;
9
9
  hint?: string;
10
10
  ariaLabel?: string;
11
+ tooltip?: string;
11
12
  }
12
13
  interface CheckboxGroupProps {
13
14
  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,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;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"}
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;AAIvC,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;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;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,4CAqFpB,CAAC"}
@@ -2,6 +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
+ import { Tooltip } from "../../Tooltip/Tooltip";
5
6
  export const CheckboxGroup = ({ legend, hint, error, options, name, values, legendAs = "h4", legendSize = "m", checkboxSize = "default", onChange, }) => {
6
7
  const hasError = Boolean(error);
7
8
  const errorId = hasError ? `${name}-error` : undefined;
@@ -19,5 +20,5 @@ export const CheckboxGroup = ({ legend, hint, error, options, name, values, lege
19
20
  [`govuk-fieldset__legend--${legendSize}`]: true,
20
21
  }), 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
22
  "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, "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
+ }), "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 }), _jsxs("label", { className: "govuk-label govuk-checkboxes__label", htmlFor: opt.id, children: [opt.label, opt.tooltip && (_jsx(Tooltip, { text: opt.tooltip, label: `Help for ${opt.label} field` }))] }), opt.hint && (_jsx("div", { className: "govuk-hint govuk-checkboxes__hint", children: opt.hint }))] }, opt.id))) })] }) }));
23
24
  };
@@ -15,7 +15,8 @@ interface SelectInputProps extends SelectProps {
15
15
  labelAs?: LabelAs;
16
16
  labelSize?: LabelSize;
17
17
  className?: string;
18
+ tooltip?: string;
18
19
  }
19
- export declare const SelectInput: ({ id, label, hint, error, options, placeholder, labelAs, labelSize, className, ...props }: SelectInputProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const SelectInput: ({ id, label, hint, error, options, placeholder, labelAs, labelSize, className, tooltip, ...props }: SelectInputProps) => import("react/jsx-runtime").JSX.Element;
20
21
  export {};
21
22
  //# sourceMappingURL=SelectInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/SelectInput/SelectInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG5C,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,KAAK,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AACxC,KAAK,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;AAE/D,UAAU,gBAAiB,SAAQ,WAAW;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,WAAW,GAAI,2FAWzB,gBAAgB,4CAoElB,CAAC"}
1
+ {"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/SelectInput/SelectInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5C,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,KAAK,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AACxC,KAAK,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;AAE/D,UAAU,gBAAiB,SAAQ,WAAW;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,GAAI,oGAYzB,gBAAgB,4CA2ElB,CAAC"}
@@ -2,14 +2,15 @@
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 SelectInput = ({ id, label, hint, error, options, placeholder, labelAs, labelSize = "m", className, ...props }) => {
5
+ import { Tooltip } from "../../Tooltip/Tooltip";
6
+ export const SelectInput = ({ id, label, hint, error, options, placeholder, labelAs, labelSize = "m", className, tooltip, ...props }) => {
6
7
  const hasError = Boolean(error);
7
8
  const hintId = hint ? `${id}-hint` : undefined;
8
9
  const errorId = hasError ? `${id}-error` : undefined;
9
10
  const ariaDescribedBy = [hintId, errorId].filter(Boolean).join(" ") || undefined;
10
- const labelElement = (_jsx("label", { htmlFor: id, className: clsx("govuk-label", {
11
+ const labelElement = (_jsxs("label", { htmlFor: id, className: clsx("govuk-label", {
11
12
  [`govuk-label--${labelSize}`]: true,
12
- }), children: label }));
13
+ }), children: [label, tooltip && (_jsx(Tooltip, { text: tooltip, label: `Help for ${label} field` }))] }));
13
14
  return (_jsxs("div", { className: clsx("govuk-form-group", {
14
15
  "govuk-form-group--error": hasError,
15
16
  }), children: [labelAs
@@ -11,7 +11,8 @@ interface TextInputProps extends InputProps {
11
11
  labelAs?: LabelAs;
12
12
  placeholder?: string;
13
13
  suffix?: ReactNode;
14
+ tooltip?: string;
14
15
  }
15
- export declare const TextInput: ({ id, label, hint, error, width, labelSize, labelAs, className, placeholder, suffix, ...props }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
16
+ export declare const TextInput: ({ id, label, hint, error, width, labelSize, labelAs, className, placeholder, suffix, tooltip, ...props }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
16
17
  export {};
17
18
  //# sourceMappingURL=TextInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/TextInput/TextInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG5C,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;AAE7D,UAAU,cAAe,SAAQ,UAAU;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,GAAI,iGAYvB,cAAc,4CAuEhB,CAAC"}
1
+ {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Inputs/TextInput/TextInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5C,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;AAE7D,UAAU,cAAe,SAAQ,UAAU;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,GAAI,0GAavB,cAAc,4CA8EhB,CAAC"}
@@ -2,14 +2,15 @@
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 TextInput = ({ id, label, hint, error, width = "20", labelSize = "m", labelAs, className, placeholder, suffix, ...props }) => {
5
+ import { Tooltip } from "../../Tooltip/Tooltip";
6
+ export const TextInput = ({ id, label, hint, error, width = "20", labelSize = "m", labelAs, className, placeholder, suffix, tooltip, ...props }) => {
6
7
  const hasError = Boolean(error);
7
8
  const hintId = hint ? `${id}-hint` : undefined;
8
9
  const errorId = hasError ? `${id}-error` : undefined;
9
10
  const describedBy = [hintId, errorId].filter(Boolean).join(" ") || undefined;
10
- const labelElement = (_jsx("label", { htmlFor: id, className: clsx("govuk-label", {
11
+ const labelElement = (_jsxs("label", { htmlFor: id, className: clsx("govuk-label", {
11
12
  [`govuk-label--${labelSize}`]: true,
12
- }), children: label }));
13
+ }), children: [label, tooltip && (_jsx(Tooltip, { text: tooltip, label: `Help for ${label} field` }))] }));
13
14
  const input = (_jsx("input", { id: id, className: clsx("govuk-input", `govuk-input--width-${width}`, className), "aria-invalid": hasError, "aria-describedby": describedBy, placeholder: placeholder, ...props }));
14
15
  return (_jsxs("div", { className: clsx("govuk-form-group", {
15
16
  "govuk-form-group--error": hasError,
@@ -1 +1 @@
1
- {"version":3,"file":"SummaryItem.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAE/B,sBAAsB,KAAG,KAAK,CAAC,GAAG,CAAC,OAYrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,cAEpC,2BAA2B,KAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAqBpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,wCAKzB,gBAAgB,KAAG,KAAK,CAAC,GAAG,CAAC,OAU/B,CAAC"}
1
+ {"version":3,"file":"SummaryItem.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAE/B,sBAAsB,KAAG,KAAK,CAAC,GAAG,CAAC,OAYrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,cAEpC,2BAA2B,KAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAqBpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,wCAKzB,gBAAgB,KAAG,KAAK,CAAC,GAAG,CAAC,OAU/B,CAAC"}
@@ -1,3 +1,4 @@
1
1
  .wordWrap {
2
- word-wrap: break-word;
2
+ overflow-wrap: anywhere;
3
+ word-break: break-word;
3
4
  }
@@ -0,0 +1,8 @@
1
+ interface TooltipProps {
2
+ text: string;
3
+ label?: string;
4
+ className?: string;
5
+ }
6
+ export declare const Tooltip: ({ text, label, className, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=Tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAOA,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,OAAO,GAAI,6BAIrB,YAAY,4CAuDd,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import clsx from "clsx";
5
+ import styles from "./Tooltip.module.css";
6
+ import { TooltipInfoIcon } from "./TooltipInfoIcon";
7
+ export const Tooltip = ({ text, label = "Show help information", className, }) => {
8
+ const [open, setOpen] = useState(false);
9
+ const tooltipId = useId();
10
+ const wrapperRef = useRef(null);
11
+ useEffect(() => {
12
+ const handleClickOutside = (event) => {
13
+ if (wrapperRef.current &&
14
+ !wrapperRef.current.contains(event.target)) {
15
+ setOpen(false);
16
+ }
17
+ };
18
+ document.addEventListener("mousedown", handleClickOutside);
19
+ return () => {
20
+ document.removeEventListener("mousedown", handleClickOutside);
21
+ };
22
+ }, []);
23
+ return (_jsxs("span", { ref: wrapperRef, className: styles.tooltip, children: [_jsxs("button", { type: "button", className: styles.button, "aria-expanded": open, "aria-controls": tooltipId, "aria-describedby": open ? tooltipId : undefined, onClick: () => setOpen(!open), onKeyDown: (e) => {
24
+ if (e.key === "Escape") {
25
+ setOpen(false);
26
+ }
27
+ }, children: [_jsx(TooltipInfoIcon, { "aria-hidden": "true", className: styles.icon }), _jsx("span", { className: "govuk-visually-hidden", children: label })] }), _jsx("div", { id: tooltipId, className: clsx(styles.content, "govuk-body-s", className), hidden: !open, children: text })] }));
28
+ };
@@ -0,0 +1,37 @@
1
+ .tooltip {
2
+ position: relative;
3
+ display: inline-flex;
4
+ vertical-align: middle;
5
+ margin-left: 0.5rem;
6
+ }
7
+
8
+ .button {
9
+ display: inline-flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ padding: 0;
13
+ margin: 0;
14
+ border: 0;
15
+ background: transparent;
16
+ color: #1d70b8;
17
+ cursor: pointer;
18
+ }
19
+
20
+ .icon {
21
+ width: 16px;
22
+ height: 16px;
23
+ display: block;
24
+ flex-shrink: 0;
25
+ }
26
+
27
+ .content {
28
+ position: absolute;
29
+ top: 0;
30
+ left: 1.5rem;
31
+ z-index: 10;
32
+ width: 16rem;
33
+ padding: 0.5rem;
34
+ background: #F5F5F5;
35
+ border-color: #000000;
36
+ border: 1px solid;
37
+ }
@@ -0,0 +1,3 @@
1
+ import type { SVGProps } from "react";
2
+ export declare const TooltipInfoIcon: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=TooltipInfoIcon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TooltipInfoIcon.d.ts","sourceRoot":"","sources":["../../../src/components/Tooltip/TooltipInfoIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,eAAO,MAAM,eAAe,GACxB,OAAO,QAAQ,CAAC,aAAa,CAAC,4CAiBjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const TooltipInfoIcon = (props) => (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M8 0C12.4181 0 16 3.58187 16 8C16 12.4181 12.4181 16 8 16C3.58187 16 0 12.4181 0 8C0 3.58187 3.58187 0 8 0ZM8 6.22222C7.50903 6.22222 7.11111 6.62014 7.11111 7.11111V12.6222C7.11111 13.1132 7.50903 13.5111 8 13.5111C8.49097 13.5111 8.88889 13.1132 8.88889 12.6222V7.11111C8.88889 6.62014 8 6.22222 8 6.22222ZM8 2.48889C7.3125 2.48889 6.75556 3.04583 6.75556 3.73333C6.75556 4.42084 7.3125 4.97778 8 4.97778C8.6875 4.97778 9.24444 4.42084 9.24444 3.73333C9.24444 3.04583 8.6875 2.48889 8 2.48889Z", fill: "currentColor" }) }));
package/dist/index.d.ts CHANGED
@@ -14,4 +14,5 @@ export * from "./components/ApiQuery";
14
14
  export * from "./components/Inputs";
15
15
  export * from "./components/NotificationBanner/NotificationBanner";
16
16
  export * from "./components/Details/Details";
17
+ export * from "./components/Tooltip/Tooltip";
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oDAAoD,CAAC;AACnE,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oDAAoD,CAAC;AACnE,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -14,3 +14,4 @@ export * from "./components/ApiQuery";
14
14
  export * from "./components/Inputs";
15
15
  export * from "./components/NotificationBanner/NotificationBanner";
16
16
  export * from "./components/Details/Details";
17
+ export * from "./components/Tooltip/Tooltip";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uktrade/react-component-library",
3
- "version": "0.21.2",
3
+ "version": "0.21.4",
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",
@@ -3,6 +3,7 @@
3
3
  import clsx from "clsx";
4
4
  import type { ReactNode } from "react";
5
5
  import { createElement } from "react";
6
+ import { Tooltip } from "../../Tooltip/Tooltip";
6
7
 
7
8
  type LegendAs = "h1" | "h2" | "h3" | "h4";
8
9
  type LegendSize = "s" | "m" | "l" | "xl";
@@ -14,6 +15,7 @@ interface CheckboxOption {
14
15
  checked?: boolean;
15
16
  hint?: string;
16
17
  ariaLabel?: string
18
+ tooltip?: string;
17
19
  }
18
20
 
19
21
  interface CheckboxGroupProps {
@@ -106,6 +108,13 @@ export const CheckboxGroup = ({
106
108
  htmlFor={opt.id}
107
109
  >
108
110
  {opt.label}
111
+
112
+ {opt.tooltip && (
113
+ <Tooltip
114
+ text={opt.tooltip}
115
+ label={`Help for ${opt.label} field`}
116
+ />
117
+ )}
109
118
  </label>
110
119
  {opt.hint && (
111
120
  <div className="govuk-hint govuk-checkboxes__hint">
@@ -3,6 +3,7 @@
3
3
  import clsx from "clsx";
4
4
  import type { JSX, ReactNode } from "react";
5
5
  import { createElement } from "react";
6
+ import { Tooltip } from "../../Tooltip/Tooltip";
6
7
 
7
8
  type LabelAs = "h1" | "h2" | "h3" | "h4";
8
9
  type LabelSize = "s" | "m" | "l" | "xl";
@@ -18,6 +19,7 @@ interface SelectInputProps extends SelectProps {
18
19
  labelAs?: LabelAs;
19
20
  labelSize?: LabelSize;
20
21
  className?: string;
22
+ tooltip?: string;
21
23
  }
22
24
 
23
25
  export const SelectInput = ({
@@ -30,6 +32,7 @@ export const SelectInput = ({
30
32
  labelAs,
31
33
  labelSize = "m",
32
34
  className,
35
+ tooltip,
33
36
  ...props
34
37
  }: SelectInputProps) => {
35
38
  const hasError = Boolean(error);
@@ -46,6 +49,13 @@ export const SelectInput = ({
46
49
  })}
47
50
  >
48
51
  {label}
52
+
53
+ {tooltip && (
54
+ <Tooltip
55
+ text={tooltip}
56
+ label={`Help for ${label} field`}
57
+ />
58
+ )}
49
59
  </label>
50
60
  );
51
61
 
@@ -3,6 +3,7 @@
3
3
  import clsx from "clsx";
4
4
  import type { JSX, ReactNode } from "react";
5
5
  import { createElement } from "react";
6
+ import { Tooltip } from "../../Tooltip/Tooltip";
6
7
 
7
8
  type LabelAs = "h1" | "h2" | "h3" | "h4";
8
9
  type InputProps = Omit<JSX.IntrinsicElements["input"], "id">;
@@ -17,6 +18,7 @@ interface TextInputProps extends InputProps {
17
18
  labelAs?: LabelAs;
18
19
  placeholder?: string;
19
20
  suffix?: ReactNode;
21
+ tooltip?: string;
20
22
  }
21
23
 
22
24
  export const TextInput = ({
@@ -30,6 +32,7 @@ export const TextInput = ({
30
32
  className,
31
33
  placeholder,
32
34
  suffix,
35
+ tooltip,
33
36
  ...props
34
37
  }: TextInputProps) => {
35
38
  const hasError = Boolean(error);
@@ -46,6 +49,13 @@ export const TextInput = ({
46
49
  })}
47
50
  >
48
51
  {label}
52
+
53
+ {tooltip && (
54
+ <Tooltip
55
+ text={tooltip}
56
+ label={`Help for ${label} field`}
57
+ />
58
+ )}
49
59
  </label>
50
60
  );
51
61
 
@@ -1,3 +1,4 @@
1
1
  .wordWrap {
2
- word-wrap: break-word;
2
+ overflow-wrap: anywhere;
3
+ word-break: break-word;
3
4
  }
@@ -2,8 +2,7 @@
2
2
 
3
3
  import clsx from "clsx";
4
4
  import type React from "react";
5
- import styles from "./SummaryItem.module.css"
6
-
5
+ import styles from "./SummaryItem.module.css";
7
6
 
8
7
  export interface SummaryItemConfig {
9
8
  name: string;
@@ -0,0 +1,37 @@
1
+ .tooltip {
2
+ position: relative;
3
+ display: inline-flex;
4
+ vertical-align: middle;
5
+ margin-left: 0.5rem;
6
+ }
7
+
8
+ .button {
9
+ display: inline-flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ padding: 0;
13
+ margin: 0;
14
+ border: 0;
15
+ background: transparent;
16
+ color: #1d70b8;
17
+ cursor: pointer;
18
+ }
19
+
20
+ .icon {
21
+ width: 16px;
22
+ height: 16px;
23
+ display: block;
24
+ flex-shrink: 0;
25
+ }
26
+
27
+ .content {
28
+ position: absolute;
29
+ top: 0;
30
+ left: 1.5rem;
31
+ z-index: 10;
32
+ width: 16rem;
33
+ padding: 0.5rem;
34
+ background: #F5F5F5;
35
+ border-color: #000000;
36
+ border: 1px solid;
37
+ }
@@ -0,0 +1,73 @@
1
+ "use client";
2
+
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import clsx from "clsx";
5
+ import styles from "./Tooltip.module.css";
6
+ import { TooltipInfoIcon } from "./TooltipInfoIcon";
7
+
8
+ interface TooltipProps {
9
+ text: string;
10
+ label?: string;
11
+ className?: string;
12
+ }
13
+
14
+ export const Tooltip = ({
15
+ text,
16
+ label = "Show help information",
17
+ className,
18
+ }: TooltipProps) => {
19
+ const [open, setOpen] = useState(false);
20
+ const tooltipId = useId();
21
+ const wrapperRef = useRef<HTMLSpanElement | null>(null);
22
+
23
+ useEffect(() => {
24
+ const handleClickOutside = (event: MouseEvent) => {
25
+ if (
26
+ wrapperRef.current &&
27
+ !wrapperRef.current.contains(event.target as Node)
28
+ ) {
29
+ setOpen(false);
30
+ }
31
+ };
32
+
33
+ document.addEventListener("mousedown", handleClickOutside);
34
+ return () => {
35
+ document.removeEventListener("mousedown", handleClickOutside);
36
+ };
37
+ }, []);
38
+
39
+ return (
40
+ <span ref={wrapperRef} className={styles.tooltip}>
41
+ <button
42
+ type="button"
43
+ className={styles.button}
44
+ aria-expanded={open}
45
+ aria-controls={tooltipId}
46
+ aria-describedby={open ? tooltipId : undefined}
47
+ onClick={() => setOpen(!open)}
48
+ onKeyDown={(e) => {
49
+ if (e.key === "Escape") {
50
+ setOpen(false);
51
+ }
52
+ }}
53
+ >
54
+ <TooltipInfoIcon
55
+ aria-hidden="true"
56
+ className={styles.icon}
57
+ />
58
+
59
+ <span className="govuk-visually-hidden">
60
+ {label}
61
+ </span>
62
+ </button>
63
+
64
+ <div
65
+ id={tooltipId}
66
+ className={clsx(styles.content, "govuk-body-s", className)}
67
+ hidden={!open}
68
+ >
69
+ {text}
70
+ </div>
71
+ </span>
72
+ );
73
+ };
@@ -0,0 +1,21 @@
1
+ import type { SVGProps } from "react";
2
+
3
+ export const TooltipInfoIcon = (
4
+ props: SVGProps<SVGSVGElement>
5
+ ) => (
6
+ <svg
7
+ width="16"
8
+ height="16"
9
+ viewBox="0 0 16 16"
10
+ fill="none"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ {...props}
13
+ >
14
+ <path
15
+ fillRule="evenodd"
16
+ clipRule="evenodd"
17
+ d="M8 0C12.4181 0 16 3.58187 16 8C16 12.4181 12.4181 16 8 16C3.58187 16 0 12.4181 0 8C0 3.58187 3.58187 0 8 0ZM8 6.22222C7.50903 6.22222 7.11111 6.62014 7.11111 7.11111V12.6222C7.11111 13.1132 7.50903 13.5111 8 13.5111C8.49097 13.5111 8.88889 13.1132 8.88889 12.6222V7.11111C8.88889 6.62014 8 6.22222 8 6.22222ZM8 2.48889C7.3125 2.48889 6.75556 3.04583 6.75556 3.73333C6.75556 4.42084 7.3125 4.97778 8 4.97778C8.6875 4.97778 9.24444 4.42084 9.24444 3.73333C9.24444 3.04583 8.6875 2.48889 8 2.48889Z"
18
+ fill="currentColor"
19
+ />
20
+ </svg>
21
+ );
package/src/index.ts CHANGED
@@ -14,3 +14,4 @@ export * from "./components/ApiQuery";
14
14
  export * from "./components/Inputs";
15
15
  export * from "./components/NotificationBanner/NotificationBanner";
16
16
  export * from "./components/Details/Details";
17
+ export * from "./components/Tooltip/Tooltip";