opus-toolkit-components 1.9.6 → 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.
@@ -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: string;
10
- name: string;
11
- onChange?: (event: CheckboxChangeEvent) => void;
12
- value?: boolean;
13
- isValid?: boolean;
14
- errorMessage?: string;
15
- disabled?: boolean;
16
- title?: string;
17
- dataCy?: string;
18
- }
19
-
20
- export const Checkbox: React.ComponentType<CheckboxProps>;
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>;
@@ -16,6 +16,7 @@ export interface DatePickerProps extends React.HTMLAttributes<HTMLDivElement> {
16
16
  className?: string;
17
17
  title?: string;
18
18
  required?: boolean;
19
+ hideLabel?: boolean;
19
20
  dataCy?: string;
20
21
  disabled?: boolean;
21
22
  minDate?: string;
@@ -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;
@@ -11,7 +11,7 @@ export interface RadioChangeEvent {
11
11
  }
12
12
 
13
13
  export interface RadioButtonProps extends React.HTMLAttributes<HTMLDivElement> {
14
- label: string;
14
+ label?: string;
15
15
  options?: RadioOption[];
16
16
  name: string;
17
17
  value?: string | number;
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 = "Select a Date:",
1327
+ label,
1319
1328
  isValid = true,
1320
- errorMessage = "Error message",
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: errorMessage
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 = "Test 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 = "Test 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 = "Test 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]",
@@ -2478,7 +2501,7 @@ __webpack_require__.r(__webpack_exports__);
2478
2501
  *
2479
2502
  * @typedef {Object} RadioButtonProps
2480
2503
  *
2481
- * @property {string} label
2504
+ * @property {string} [label]
2482
2505
  * Form label above the radio group.
2483
2506
  *
2484
2507
  * @property {RadioOption[]} [options]
@@ -2541,7 +2564,7 @@ const RadioButton = _ref => {
2541
2564
  tabIndex = "",
2542
2565
  title = "",
2543
2566
  isValid = true,
2544
- errorMessage = `${label} is required`,
2567
+ errorMessage,
2545
2568
  required = false,
2546
2569
  hideLabel = false,
2547
2570
  dataCy,
@@ -2549,6 +2572,10 @@ const RadioButton = _ref => {
2549
2572
  ...rest
2550
2573
  } = _ref;
2551
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");
2552
2579
  const handleChange = item => {
2553
2580
  if (disabled) return;
2554
2581
  const event = {
@@ -2562,7 +2589,8 @@ const RadioButton = _ref => {
2562
2589
  return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)("div", {
2563
2590
  className: `mb-4 flex flex-col ${className}`,
2564
2591
  ...rest,
2565
- 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,
2566
2594
  as: "label",
2567
2595
  variant: "label",
2568
2596
  className: hideLabel ? "sr-only" : "mb-2 flex items-center text-[--color-text-strong]",
@@ -2573,6 +2601,9 @@ const RadioButton = _ref => {
2573
2601
  children: "*"
2574
2602
  })]
2575
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,
2576
2607
  className: "flex flex-wrap gap-4 md:flex-nowrap md:gap-0 md:space-x-4",
2577
2608
  children: options.map(option => {
2578
2609
  const id = `${name}-${option.value}`;
@@ -2595,16 +2626,16 @@ const RadioButton = _ref => {
2595
2626
  value: option.value,
2596
2627
  dataCy
2597
2628
  }),
2598
- "aria-describedby": !isValid ? `${name}-error` : undefined
2629
+ "aria-describedby": !isValid ? errorId : undefined
2599
2630
  }), option.label]
2600
2631
  }, option.value);
2601
2632
  })
2602
2633
  }), !isValid && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
2603
2634
  as: "span",
2604
2635
  variant: "small",
2605
- id: `${name}-error`,
2636
+ id: errorId,
2606
2637
  className: "text-[--color-util-red]",
2607
- children: errorMessage
2638
+ children: resolvedErrorMessage
2608
2639
  })]
2609
2640
  });
2610
2641
  };