@uktrade/react-component-library 0.21.3 → 0.21.5
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/Inputs/CheckBoxesInput/CheckBoxGroupInput.d.ts +1 -0
- package/dist/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.d.ts.map +1 -1
- package/dist/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.js +2 -1
- package/dist/components/Inputs/SelectInput/SelectInput.d.ts +2 -1
- package/dist/components/Inputs/SelectInput/SelectInput.d.ts.map +1 -1
- package/dist/components/Inputs/SelectInput/SelectInput.js +4 -3
- package/dist/components/Inputs/TextInput/TextInput.d.ts +2 -1
- package/dist/components/Inputs/TextInput/TextInput.d.ts.map +1 -1
- package/dist/components/Inputs/TextInput/TextInput.js +4 -3
- package/dist/components/SummaryList/SummaryList.d.ts +2 -1
- package/dist/components/SummaryList/SummaryList.d.ts.map +1 -1
- package/dist/components/SummaryList/SummaryList.js +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +8 -0
- package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip/Tooltip.js +28 -0
- package/dist/components/Tooltip/Tooltip.module.css +37 -0
- package/dist/components/Tooltip/TooltipInfoIcon.d.ts +3 -0
- package/dist/components/Tooltip/TooltipInfoIcon.d.ts.map +1 -0
- package/dist/components/Tooltip/TooltipInfoIcon.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/components/Inputs/CheckBoxesInput/CheckBoxGroupInput.tsx +9 -0
- package/src/components/Inputs/SelectInput/SelectInput.tsx +10 -0
- package/src/components/Inputs/TextInput/TextInput.tsx +10 -0
- package/src/components/SummaryList/SummaryList.tsx +7 -3
- package/src/components/Tooltip/Tooltip.module.css +37 -0
- package/src/components/Tooltip/Tooltip.tsx +73 -0
- package/src/components/Tooltip/TooltipInfoIcon.tsx +21 -0
- package/src/index.ts +1 -0
|
@@ -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;
|
|
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 }),
|
|
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;
|
|
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
|
-
|
|
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 = (
|
|
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;
|
|
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
|
-
|
|
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 = (
|
|
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,
|
|
@@ -14,6 +14,7 @@ export interface SummaryCardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
14
14
|
className?: string;
|
|
15
15
|
titleBackground?: string;
|
|
16
16
|
subSectionNode?: React.ReactNode;
|
|
17
|
+
titleClassName?: string;
|
|
17
18
|
}
|
|
18
|
-
export declare const SummaryCard: ({ title, children, actions, className, titleBackground, subSectionNode, ...props }: SummaryCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const SummaryCard: ({ title, children, actions, className, titleBackground, subSectionNode, titleClassName, ...props }: SummaryCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
20
|
//# 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;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,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;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,GAAI,oGASzB,gBAAgB,4CA2ClB,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, 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 })] }) }));
|
|
7
|
+
export const SummaryCard = ({ title, children, actions, className, titleBackground, subSectionNode, titleClassName, ...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: clsx("govuk-summary-card__title", titleClassName), 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 })] }) }));
|
|
@@ -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 @@
|
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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
package/package.json
CHANGED
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
"use client"
|
|
1
|
+
"use client";
|
|
2
2
|
|
|
3
3
|
import type React from "react";
|
|
4
4
|
import clsx from "clsx";
|
|
@@ -29,6 +29,7 @@ export interface SummaryCardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
29
29
|
className?: string;
|
|
30
30
|
titleBackground?: string;
|
|
31
31
|
subSectionNode?: React.ReactNode;
|
|
32
|
+
titleClassName?: string;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export const SummaryCard = ({
|
|
@@ -38,6 +39,7 @@ export const SummaryCard = ({
|
|
|
38
39
|
className,
|
|
39
40
|
titleBackground,
|
|
40
41
|
subSectionNode,
|
|
42
|
+
titleClassName,
|
|
41
43
|
...props
|
|
42
44
|
}: SummaryCardProps) => (
|
|
43
45
|
<div className={clsx(styles.root, className)}>
|
|
@@ -46,7 +48,9 @@ export const SummaryCard = ({
|
|
|
46
48
|
className="govuk-summary-card__title-wrapper"
|
|
47
49
|
style={titleBackground ? { background: titleBackground } : undefined}
|
|
48
50
|
>
|
|
49
|
-
<h2 className="govuk-summary-card__title"
|
|
51
|
+
<h2 className={clsx("govuk-summary-card__title", titleClassName)}>
|
|
52
|
+
{title}
|
|
53
|
+
</h2>
|
|
50
54
|
|
|
51
55
|
{actions && (
|
|
52
56
|
<ul
|
|
@@ -80,4 +84,4 @@ export const SummaryCard = ({
|
|
|
80
84
|
</div>
|
|
81
85
|
</div>
|
|
82
86
|
</div>
|
|
83
|
-
);
|
|
87
|
+
);
|
|
@@ -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