opus-toolkit-components 1.9.5 → 1.9.7
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/lib/components/Forms/Checkbox/index.d.ts +21 -20
- package/lib/components/Forms/Datepickers/index.d.ts +1 -0
- package/lib/components/Forms/Dropdowns/index.d.ts +3 -0
- package/lib/components/Forms/Inputs/index.d.ts +1 -0
- package/lib/components/Forms/Radios/index.d.ts +1 -1
- package/lib/main.js +59 -24
- package/lib/main.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
export interface CheckboxChangeEvent {
|
|
2
|
-
target: {
|
|
3
|
-
name: string;
|
|
4
|
-
value: boolean;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface CheckboxProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
-
label
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
export interface CheckboxChangeEvent {
|
|
2
|
+
target: {
|
|
3
|
+
name: string;
|
|
4
|
+
value: boolean;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CheckboxProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
label?: string;
|
|
10
|
+
hideLabel?: boolean;
|
|
11
|
+
name: string;
|
|
12
|
+
onChange?: (event: CheckboxChangeEvent) => void;
|
|
13
|
+
value?: boolean;
|
|
14
|
+
isValid?: boolean;
|
|
15
|
+
errorMessage?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
title?: string;
|
|
18
|
+
dataCy?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const Checkbox: React.ComponentType<CheckboxProps>;
|
|
@@ -19,6 +19,7 @@ export interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
19
19
|
label?: string;
|
|
20
20
|
isValid?: boolean;
|
|
21
21
|
required?: boolean;
|
|
22
|
+
hideLabel?: boolean;
|
|
22
23
|
placeholder?: string;
|
|
23
24
|
name?: string;
|
|
24
25
|
className?: string;
|
|
@@ -39,6 +40,7 @@ export interface SearchDropdownProps extends React.HTMLAttributes<HTMLDivElement
|
|
|
39
40
|
label?: string;
|
|
40
41
|
isValid?: boolean;
|
|
41
42
|
required?: boolean;
|
|
43
|
+
hideLabel?: boolean;
|
|
42
44
|
placeholder?: string;
|
|
43
45
|
searchPlaceholder?: string;
|
|
44
46
|
name?: string;
|
|
@@ -68,6 +70,7 @@ export interface SearchMultiSelectDropdownProps extends React.HTMLAttributes<HTM
|
|
|
68
70
|
label?: string;
|
|
69
71
|
isValid?: boolean;
|
|
70
72
|
required?: boolean;
|
|
73
|
+
hideLabel?: boolean;
|
|
71
74
|
placeholder?: string;
|
|
72
75
|
searchPlaceholder?: string;
|
|
73
76
|
name?: string;
|
|
@@ -29,6 +29,7 @@ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement>
|
|
|
29
29
|
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
30
30
|
className?: string;
|
|
31
31
|
outerClassName?: string;
|
|
32
|
+
innerClassName?: string;
|
|
32
33
|
value?: string | number;
|
|
33
34
|
Icon?: IconComponent;
|
|
34
35
|
iconPosition?: "left" | "right";
|
package/lib/main.js
CHANGED
|
@@ -1141,9 +1141,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1141
1141
|
*
|
|
1142
1142
|
* @typedef {Object} CheckboxProps
|
|
1143
1143
|
*
|
|
1144
|
-
* @property {string} label
|
|
1144
|
+
* @property {string} [label]
|
|
1145
1145
|
* Label displayed next to the checkbox.
|
|
1146
1146
|
*
|
|
1147
|
+
* @property {boolean} [hideLabel]
|
|
1148
|
+
* Hides the visible label while keeping it available to assistive technology.
|
|
1149
|
+
*
|
|
1147
1150
|
* @property {string} name
|
|
1148
1151
|
* Name used in the emitted onChange event.
|
|
1149
1152
|
*
|
|
@@ -1175,6 +1178,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1175
1178
|
function Checkbox(_ref) {
|
|
1176
1179
|
let {
|
|
1177
1180
|
label,
|
|
1181
|
+
hideLabel = false,
|
|
1178
1182
|
name,
|
|
1179
1183
|
onChange,
|
|
1180
1184
|
value = false,
|
|
@@ -1189,6 +1193,7 @@ function Checkbox(_ref) {
|
|
|
1189
1193
|
const id = `checkbox-${name}`;
|
|
1190
1194
|
const errorId = `${id}-error`;
|
|
1191
1195
|
const showError = !isValid && errorMessage;
|
|
1196
|
+
const hasLabel = Boolean(label);
|
|
1192
1197
|
const handleChange = event => {
|
|
1193
1198
|
onChange?.({
|
|
1194
1199
|
target: {
|
|
@@ -1221,10 +1226,11 @@ function Checkbox(_ref) {
|
|
|
1221
1226
|
accentColor: "var(--color-primary-btn)"
|
|
1222
1227
|
},
|
|
1223
1228
|
className: `mr-2 rounded-sm ${disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"}`
|
|
1224
|
-
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1229
|
+
}), hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1225
1230
|
variant: "label",
|
|
1226
1231
|
as: "label",
|
|
1227
1232
|
htmlFor: id,
|
|
1233
|
+
className: hideLabel ? "sr-only" : undefined,
|
|
1228
1234
|
children: label
|
|
1229
1235
|
})]
|
|
1230
1236
|
}), !isValid && errorMessage && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
@@ -1297,6 +1303,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1297
1303
|
*
|
|
1298
1304
|
* @property {boolean} [required]
|
|
1299
1305
|
*
|
|
1306
|
+
* @property {boolean} [hideLabel]
|
|
1307
|
+
* Hides the visible label while keeping it available to assistive technology.
|
|
1308
|
+
*
|
|
1300
1309
|
* @property {string} [dataCy]
|
|
1301
1310
|
*
|
|
1302
1311
|
* @property {boolean} [disabled]
|
|
@@ -1315,15 +1324,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1315
1324
|
function DatePicker(_ref) {
|
|
1316
1325
|
let {
|
|
1317
1326
|
initialDate = "",
|
|
1318
|
-
label
|
|
1327
|
+
label,
|
|
1319
1328
|
isValid = true,
|
|
1320
|
-
errorMessage
|
|
1329
|
+
errorMessage,
|
|
1321
1330
|
name = "date",
|
|
1322
1331
|
onChange,
|
|
1323
1332
|
value,
|
|
1324
1333
|
className = "",
|
|
1325
1334
|
title = "",
|
|
1326
1335
|
required = false,
|
|
1336
|
+
hideLabel = false,
|
|
1327
1337
|
dataCy,
|
|
1328
1338
|
disabled = false,
|
|
1329
1339
|
minDate,
|
|
@@ -1332,6 +1342,8 @@ function DatePicker(_ref) {
|
|
|
1332
1342
|
} = _ref;
|
|
1333
1343
|
const [selectedDate, setSelectedDate] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)("");
|
|
1334
1344
|
const inputRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
|
|
1345
|
+
const hasLabel = Boolean(label);
|
|
1346
|
+
const resolvedErrorMessage = errorMessage || (hasLabel ? `${label} is required` : "This field is required");
|
|
1335
1347
|
const normalizeToInputFormat = dateString => {
|
|
1336
1348
|
if (!dateString) return "";
|
|
1337
1349
|
const [datePart] = dateString.split(" "); // Remove time if present
|
|
@@ -1380,11 +1392,11 @@ function DatePicker(_ref) {
|
|
|
1380
1392
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)("div", {
|
|
1381
1393
|
className: "relative mb-4 flex flex-col",
|
|
1382
1394
|
...rest,
|
|
1383
|
-
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1395
|
+
children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1384
1396
|
as: "label",
|
|
1385
1397
|
variant: "label",
|
|
1386
1398
|
htmlFor: name,
|
|
1387
|
-
className: "mb-1",
|
|
1399
|
+
className: hideLabel ? "sr-only" : "mb-1",
|
|
1388
1400
|
children: [label, required && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsx)("span", {
|
|
1389
1401
|
className: "ml-1 text-[--color-util-red]",
|
|
1390
1402
|
children: "*"
|
|
@@ -1422,7 +1434,7 @@ function DatePicker(_ref) {
|
|
|
1422
1434
|
id: `${name}-error`,
|
|
1423
1435
|
variant: "small",
|
|
1424
1436
|
className: "text-[--color-util-red]",
|
|
1425
|
-
children:
|
|
1437
|
+
children: resolvedErrorMessage
|
|
1426
1438
|
})]
|
|
1427
1439
|
});
|
|
1428
1440
|
}
|
|
@@ -1481,6 +1493,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1481
1493
|
* @property {boolean} [required]
|
|
1482
1494
|
* Whether a * is appended.
|
|
1483
1495
|
*
|
|
1496
|
+
* @property {boolean} [hideLabel]
|
|
1497
|
+
* Hides the visible label while keeping it available to assistive technology.
|
|
1498
|
+
*
|
|
1484
1499
|
* @property {string} [placeholder]
|
|
1485
1500
|
*
|
|
1486
1501
|
* @property {string} [name]
|
|
@@ -1515,9 +1530,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1515
1530
|
function Dropdown(_ref) {
|
|
1516
1531
|
let {
|
|
1517
1532
|
items = [],
|
|
1518
|
-
label
|
|
1533
|
+
label,
|
|
1519
1534
|
isValid = true,
|
|
1520
1535
|
required = false,
|
|
1536
|
+
hideLabel = false,
|
|
1521
1537
|
placeholder = "Example Placeholder",
|
|
1522
1538
|
name,
|
|
1523
1539
|
className = "",
|
|
@@ -1532,6 +1548,7 @@ function Dropdown(_ref) {
|
|
|
1532
1548
|
...rest
|
|
1533
1549
|
} = _ref;
|
|
1534
1550
|
const [selectedItem, setSelectedItem] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(null);
|
|
1551
|
+
const hasLabel = Boolean(label);
|
|
1535
1552
|
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1536
1553
|
const newSelectedItem = items.find(item => item.value === value) || null;
|
|
1537
1554
|
setSelectedItem(newSelectedItem);
|
|
@@ -1551,10 +1568,10 @@ function Dropdown(_ref) {
|
|
|
1551
1568
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)("div", {
|
|
1552
1569
|
className: `mb-4 flex flex-col ${className}`,
|
|
1553
1570
|
...rest,
|
|
1554
|
-
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1571
|
+
children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1555
1572
|
as: "label",
|
|
1556
1573
|
variant: "label",
|
|
1557
|
-
className: "mb-1",
|
|
1574
|
+
className: hideLabel ? "sr-only" : "mb-1",
|
|
1558
1575
|
htmlFor: name,
|
|
1559
1576
|
children: [label, required && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsx)("span", {
|
|
1560
1577
|
className: "ml-1 text-[--color-util-red]",
|
|
@@ -1665,6 +1682,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1665
1682
|
* @property {string} [label]
|
|
1666
1683
|
* @property {boolean} [isValid]
|
|
1667
1684
|
* @property {boolean} [required]
|
|
1685
|
+
* @property {boolean} [hideLabel]
|
|
1668
1686
|
* @property {string} [placeholder]
|
|
1669
1687
|
* @property {string} [searchPlaceholder]
|
|
1670
1688
|
* @property {string} [name]
|
|
@@ -1687,9 +1705,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1687
1705
|
function SearchDropdown(_ref) {
|
|
1688
1706
|
let {
|
|
1689
1707
|
items = [],
|
|
1690
|
-
label
|
|
1708
|
+
label,
|
|
1691
1709
|
isValid = true,
|
|
1692
1710
|
required = false,
|
|
1711
|
+
hideLabel = false,
|
|
1693
1712
|
placeholder = "Example Placeholder",
|
|
1694
1713
|
searchPlaceholder = "Search",
|
|
1695
1714
|
name,
|
|
@@ -1707,6 +1726,7 @@ function SearchDropdown(_ref) {
|
|
|
1707
1726
|
} = _ref;
|
|
1708
1727
|
const [selectedItem, setSelectedItem] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(null);
|
|
1709
1728
|
const [searchTerm, setSearchTerm] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)("");
|
|
1729
|
+
const hasLabel = Boolean(label);
|
|
1710
1730
|
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1711
1731
|
const newSelectedItem = items.find(item => item.value === value) || null;
|
|
1712
1732
|
setSelectedItem(newSelectedItem);
|
|
@@ -1734,10 +1754,10 @@ function SearchDropdown(_ref) {
|
|
|
1734
1754
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)("div", {
|
|
1735
1755
|
className: `mb-4 flex flex-col ${className}`,
|
|
1736
1756
|
...rest,
|
|
1737
|
-
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1757
|
+
children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1738
1758
|
as: "label",
|
|
1739
1759
|
variant: "label",
|
|
1740
|
-
className: "mb-1",
|
|
1760
|
+
className: hideLabel ? "sr-only" : "mb-1",
|
|
1741
1761
|
htmlFor: name,
|
|
1742
1762
|
children: [label, required && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsx)("span", {
|
|
1743
1763
|
className: "ml-1 text-[--color-util-red]",
|
|
@@ -1864,6 +1884,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1864
1884
|
* @property {string} [label]
|
|
1865
1885
|
* @property {boolean} [isValid]
|
|
1866
1886
|
* @property {boolean} [required]
|
|
1887
|
+
* @property {boolean} [hideLabel]
|
|
1867
1888
|
* @property {string} [placeholder]
|
|
1868
1889
|
* @property {string} [searchPlaceholder]
|
|
1869
1890
|
* @property {string} [name]
|
|
@@ -1896,9 +1917,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1896
1917
|
function SearchMultiSelectDropdown(_ref) {
|
|
1897
1918
|
let {
|
|
1898
1919
|
items = [],
|
|
1899
|
-
label
|
|
1920
|
+
label,
|
|
1900
1921
|
isValid = true,
|
|
1901
1922
|
required = false,
|
|
1923
|
+
hideLabel = false,
|
|
1902
1924
|
placeholder = "Select options",
|
|
1903
1925
|
searchPlaceholder = "Search",
|
|
1904
1926
|
name,
|
|
@@ -1919,6 +1941,7 @@ function SearchMultiSelectDropdown(_ref) {
|
|
|
1919
1941
|
} = _ref;
|
|
1920
1942
|
const [searchTerm, setSearchTerm] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)("");
|
|
1921
1943
|
const [localSelectedValues, setLocalSelectedValues] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(value);
|
|
1944
|
+
const hasLabel = Boolean(label);
|
|
1922
1945
|
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1923
1946
|
setLocalSelectedValues(value);
|
|
1924
1947
|
}, [value]);
|
|
@@ -1963,10 +1986,10 @@ function SearchMultiSelectDropdown(_ref) {
|
|
|
1963
1986
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("div", {
|
|
1964
1987
|
className: `mb-4 flex flex-col ${className}`,
|
|
1965
1988
|
...rest,
|
|
1966
|
-
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1989
|
+
children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
1967
1990
|
as: "label",
|
|
1968
1991
|
variant: "label",
|
|
1969
|
-
className: "mb-1",
|
|
1992
|
+
className: hideLabel ? "sr-only" : "mb-1",
|
|
1970
1993
|
htmlFor: name,
|
|
1971
1994
|
children: [label, required && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("span", {
|
|
1972
1995
|
className: "ml-1 text-[--color-util-red]",
|
|
@@ -2304,6 +2327,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2304
2327
|
* Extra class names applied to the outer container.
|
|
2305
2328
|
* Passing an mb-* class overrides the default mb-4 spacing.
|
|
2306
2329
|
*
|
|
2330
|
+
* @property {string} [innerClassName]
|
|
2331
|
+
* Extra class names applied directly to the native input element.
|
|
2332
|
+
*
|
|
2307
2333
|
* @property {string|number} [value]
|
|
2308
2334
|
*
|
|
2309
2335
|
* @property {IconComponent} [Icon]
|
|
@@ -2351,6 +2377,7 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
|
|
|
2351
2377
|
onChange,
|
|
2352
2378
|
className = "",
|
|
2353
2379
|
outerClassName = "",
|
|
2380
|
+
innerClassName = "",
|
|
2354
2381
|
value,
|
|
2355
2382
|
Icon,
|
|
2356
2383
|
// Icon component
|
|
@@ -2376,7 +2403,7 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
|
|
|
2376
2403
|
const resolvedErrorMessage = errorMessage || (hasLabel ? `${label} is required` : "This field is required");
|
|
2377
2404
|
const hasCustomBottomMargin = /\b(?:[a-z]+:)*mb-/.test(outerClassName);
|
|
2378
2405
|
const outerClasses = `${hasCustomBottomMargin ? "" : "mb-4"} flex flex-col ${outerClassName}`.trim();
|
|
2379
|
-
const inputClasses = `${className} flex items-center rounded-md
|
|
2406
|
+
const inputClasses = `${className} flex items-center rounded-md border ${isValid ? "border-[--color-stroke]" : "border-utilRed1000"} text-md font-normal text-[--color-text-strong] ${disabled ? "opacity-50 cursor-not-allowed" : ""}`;
|
|
2380
2407
|
const iconClasses = `h-5 w-5 ${isAnimated ? "transition-transform duration-200 group-focus-within:scale-125" : ""} text-[--color-text-weak]`;
|
|
2381
2408
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)("div", {
|
|
2382
2409
|
className: outerClasses,
|
|
@@ -2401,7 +2428,7 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
|
|
|
2401
2428
|
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)("input", {
|
|
2402
2429
|
id: name,
|
|
2403
2430
|
ref: ref,
|
|
2404
|
-
className: `w-full ${Icon ? iconPosition === "left" ? "pl-10" : "pr-10" : ""} rounded-md border-none bg-[--color-input-bg] px-3 py-2 focus:outline-none focus:ring-0`,
|
|
2431
|
+
className: `w-full ${Icon ? iconPosition === "left" ? "pl-10" : "pr-10" : ""} rounded-md border-none bg-[--color-input-bg] px-3 py-2 focus:outline-none focus:ring-0 ${innerClassName}`,
|
|
2405
2432
|
type: type,
|
|
2406
2433
|
name: name,
|
|
2407
2434
|
placeholder: placeholder,
|
|
@@ -2474,7 +2501,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2474
2501
|
*
|
|
2475
2502
|
* @typedef {Object} RadioButtonProps
|
|
2476
2503
|
*
|
|
2477
|
-
* @property {string} label
|
|
2504
|
+
* @property {string} [label]
|
|
2478
2505
|
* Form label above the radio group.
|
|
2479
2506
|
*
|
|
2480
2507
|
* @property {RadioOption[]} [options]
|
|
@@ -2537,7 +2564,7 @@ const RadioButton = _ref => {
|
|
|
2537
2564
|
tabIndex = "",
|
|
2538
2565
|
title = "",
|
|
2539
2566
|
isValid = true,
|
|
2540
|
-
errorMessage
|
|
2567
|
+
errorMessage,
|
|
2541
2568
|
required = false,
|
|
2542
2569
|
hideLabel = false,
|
|
2543
2570
|
dataCy,
|
|
@@ -2545,6 +2572,10 @@ const RadioButton = _ref => {
|
|
|
2545
2572
|
...rest
|
|
2546
2573
|
} = _ref;
|
|
2547
2574
|
const selectedValue = value;
|
|
2575
|
+
const hasLabel = Boolean(label);
|
|
2576
|
+
const labelId = `${name}-label`;
|
|
2577
|
+
const errorId = `${name}-error`;
|
|
2578
|
+
const resolvedErrorMessage = errorMessage || (hasLabel ? `${label} is required` : "This field is required");
|
|
2548
2579
|
const handleChange = item => {
|
|
2549
2580
|
if (disabled) return;
|
|
2550
2581
|
const event = {
|
|
@@ -2558,7 +2589,8 @@ const RadioButton = _ref => {
|
|
|
2558
2589
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)("div", {
|
|
2559
2590
|
className: `mb-4 flex flex-col ${className}`,
|
|
2560
2591
|
...rest,
|
|
2561
|
-
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
2592
|
+
children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
2593
|
+
id: labelId,
|
|
2562
2594
|
as: "label",
|
|
2563
2595
|
variant: "label",
|
|
2564
2596
|
className: hideLabel ? "sr-only" : "mb-2 flex items-center text-[--color-text-strong]",
|
|
@@ -2569,6 +2601,9 @@ const RadioButton = _ref => {
|
|
|
2569
2601
|
children: "*"
|
|
2570
2602
|
})]
|
|
2571
2603
|
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)("div", {
|
|
2604
|
+
role: "radiogroup",
|
|
2605
|
+
"aria-labelledby": hasLabel ? labelId : undefined,
|
|
2606
|
+
"aria-describedby": !isValid ? errorId : undefined,
|
|
2572
2607
|
className: "flex flex-wrap gap-4 md:flex-nowrap md:gap-0 md:space-x-4",
|
|
2573
2608
|
children: options.map(option => {
|
|
2574
2609
|
const id = `${name}-${option.value}`;
|
|
@@ -2591,16 +2626,16 @@ const RadioButton = _ref => {
|
|
|
2591
2626
|
value: option.value,
|
|
2592
2627
|
dataCy
|
|
2593
2628
|
}),
|
|
2594
|
-
"aria-describedby": !isValid ?
|
|
2629
|
+
"aria-describedby": !isValid ? errorId : undefined
|
|
2595
2630
|
}), option.label]
|
|
2596
2631
|
}, option.value);
|
|
2597
2632
|
})
|
|
2598
2633
|
}), !isValid && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
|
|
2599
2634
|
as: "span",
|
|
2600
2635
|
variant: "small",
|
|
2601
|
-
id:
|
|
2636
|
+
id: errorId,
|
|
2602
2637
|
className: "text-[--color-util-red]",
|
|
2603
|
-
children:
|
|
2638
|
+
children: resolvedErrorMessage
|
|
2604
2639
|
})]
|
|
2605
2640
|
});
|
|
2606
2641
|
};
|