@eztrak/shared 0.7.4 → 0.8.1

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/index.js CHANGED
@@ -39,6 +39,8 @@ __export(src_exports, {
39
39
  ResetFiltersButton: () => ResetFiltersButton,
40
40
  SearchInput: () => SearchInput,
41
41
  TableLayoutToolbarControls: () => TableLayoutToolbarControls,
42
+ ToolTip: () => ToolTip,
43
+ TooltipText: () => TooltipText,
42
44
  capitalizeText: () => capitalizeText,
43
45
  checkIfExistsInArray: () => checkIfExistsInArray,
44
46
  cn: () => cn,
@@ -1316,12 +1318,108 @@ function Modal({
1316
1318
  return (0, import_react_dom.createPortal)(modalContent, modalRoot);
1317
1319
  }
1318
1320
 
1319
- // src/components/cell-editor/CustomCellEditor.tsx
1321
+ // src/components/tooltip/ToolTip.tsx
1320
1322
  var import_react6 = require("react");
1321
- var import_react_hot_toast2 = __toESM(require("react-hot-toast"));
1323
+ var import_react_tooltip = require("react-tooltip");
1322
1324
  var import_jsx_runtime7 = require("react/jsx-runtime");
1325
+ var defaultTooltipStyle = {
1326
+ color: "#fff",
1327
+ borderRadius: "5px",
1328
+ zIndex: 999,
1329
+ textAlign: "justify",
1330
+ maxWidth: "300px",
1331
+ whiteSpace: "pre-wrap",
1332
+ wordWrap: "break-word",
1333
+ overflowWrap: "break-word"
1334
+ };
1335
+ function ToolTip({
1336
+ text = "tool tip",
1337
+ placement = "top",
1338
+ delayShow,
1339
+ delayHide,
1340
+ className,
1341
+ tooltipClassName,
1342
+ tooltipStyle,
1343
+ wrapperTabIndex,
1344
+ disabled = false,
1345
+ children
1346
+ }) {
1347
+ const generatedId = (0, import_react6.useId)();
1348
+ const tooltipId = `eztrak-tooltip-${generatedId.replace(/:/g, "")}`;
1349
+ const tooltipText = String(text ?? "");
1350
+ if (disabled || !tooltipText) {
1351
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className, children });
1352
+ }
1353
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1354
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1355
+ "span",
1356
+ {
1357
+ className,
1358
+ "data-tooltip-id": tooltipId,
1359
+ "data-tooltip-content": tooltipText,
1360
+ tabIndex: wrapperTabIndex,
1361
+ children
1362
+ }
1363
+ ),
1364
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1365
+ import_react_tooltip.Tooltip,
1366
+ {
1367
+ id: tooltipId,
1368
+ place: placement,
1369
+ positionStrategy: "fixed",
1370
+ delayShow,
1371
+ delayHide,
1372
+ className: tooltipClassName,
1373
+ style: { ...defaultTooltipStyle, ...tooltipStyle }
1374
+ }
1375
+ )
1376
+ ] });
1377
+ }
1378
+
1379
+ // src/components/tooltip/TooltipText.tsx
1380
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1381
+ function TooltipText({
1382
+ text = "",
1383
+ maxLength = 20,
1384
+ fallback = "-",
1385
+ placement = "top",
1386
+ delayShow,
1387
+ delayHide,
1388
+ className,
1389
+ textClassName,
1390
+ tooltipClassName,
1391
+ tooltipStyle,
1392
+ showTooltip = true,
1393
+ tooltipWhenTruncatedOnly = false
1394
+ }) {
1395
+ const hasValue = text !== null && text !== void 0 && text !== "";
1396
+ const fullText = hasValue ? String(text) : fallback;
1397
+ const displayText = truncateText(fullText, maxLength);
1398
+ const isTruncated = displayText !== fullText;
1399
+ const tooltipDisabled = !showTooltip || !hasValue || tooltipWhenTruncatedOnly && !isTruncated;
1400
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1401
+ ToolTip,
1402
+ {
1403
+ text: fullText,
1404
+ placement,
1405
+ delayShow,
1406
+ delayHide,
1407
+ className: cn("inline-block max-w-full", className),
1408
+ tooltipClassName,
1409
+ tooltipStyle,
1410
+ wrapperTabIndex: tooltipDisabled ? void 0 : 0,
1411
+ disabled: tooltipDisabled,
1412
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: cn("inline-block max-w-full align-bottom", textClassName), children: displayText })
1413
+ }
1414
+ );
1415
+ }
1416
+
1417
+ // src/components/cell-editor/CustomCellEditor.tsx
1418
+ var import_react7 = require("react");
1419
+ var import_react_hot_toast2 = __toESM(require("react-hot-toast"));
1420
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1323
1421
  function ButtonSpinner() {
1324
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1422
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1325
1423
  "svg",
1326
1424
  {
1327
1425
  className: "animate-spin",
@@ -1331,7 +1429,7 @@ function ButtonSpinner() {
1331
1429
  fill: "none",
1332
1430
  "aria-hidden": true,
1333
1431
  children: [
1334
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1432
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1335
1433
  "circle",
1336
1434
  {
1337
1435
  cx: "12",
@@ -1342,7 +1440,7 @@ function ButtonSpinner() {
1342
1440
  strokeOpacity: "0.25"
1343
1441
  }
1344
1442
  ),
1345
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1443
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1346
1444
  "path",
1347
1445
  {
1348
1446
  d: "M12 2a10 10 0 0 1 10 10",
@@ -1364,7 +1462,7 @@ function normalizeInitialValue(initialValue, inputType) {
1364
1462
  }
1365
1463
  return initialValue;
1366
1464
  }
1367
- var CustomCellEditor = (0, import_react6.forwardRef)(
1465
+ var CustomCellEditor = (0, import_react7.forwardRef)(
1368
1466
  ({
1369
1467
  value: initialValue,
1370
1468
  name,
@@ -1389,11 +1487,11 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1389
1487
  cancelButtonClassName
1390
1488
  }, ref) => {
1391
1489
  const normalizedInitial = normalizeInitialValue(initialValue, inputType);
1392
- const [value, setValue] = (0, import_react6.useState)(normalizedInitial);
1393
- const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
1394
- const inputRef = (0, import_react6.useRef)(null);
1395
- const selectRef = (0, import_react6.useRef)(null);
1396
- const normalizedOptions = (0, import_react6.useMemo)(() => {
1490
+ const [value, setValue] = (0, import_react7.useState)(normalizedInitial);
1491
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
1492
+ const inputRef = (0, import_react7.useRef)(null);
1493
+ const selectRef = (0, import_react7.useRef)(null);
1494
+ const normalizedOptions = (0, import_react7.useMemo)(() => {
1397
1495
  if (customOptions && customOptions.length > 0) {
1398
1496
  return customOptions.map((opt) => ({
1399
1497
  value: String(opt[valueKey] ?? ""),
@@ -1403,13 +1501,13 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1403
1501
  return dropdownOptions;
1404
1502
  }, [customOptions, dropdownOptions, valueKey, labelKey]);
1405
1503
  const isDropdown = inputType === "dropdown" || normalizedOptions.length > 0;
1406
- (0, import_react6.useImperativeHandle)(ref, () => ({
1504
+ (0, import_react7.useImperativeHandle)(ref, () => ({
1407
1505
  getValue: () => value,
1408
1506
  isCancelBeforeStart: () => false,
1409
1507
  isCancelAfterEnd: () => false,
1410
1508
  isPopup: () => true
1411
1509
  }));
1412
- (0, import_react6.useEffect)(() => {
1510
+ (0, import_react7.useEffect)(() => {
1413
1511
  if (isDropdown) {
1414
1512
  selectRef.current?.focus();
1415
1513
  return;
@@ -1478,7 +1576,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1478
1576
  const defaultInputClass = "w-48 px-2 py-1 text-sm border border-gray-200 rounded-md bg-white focus:outline-none focus:ring-1 focus:ring-blue-400";
1479
1577
  const defaultSaveBtnClass = "px-3 py-1 text-sm font-medium text-white bg-green-500 rounded-md hover:bg-green-600 disabled:opacity-50 whitespace-nowrap shrink-0";
1480
1578
  const defaultCancelBtnClass = "px-3 py-1 text-sm font-medium text-white bg-red-500 rounded-md hover:bg-red-600 disabled:opacity-50 whitespace-nowrap shrink-0";
1481
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1579
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1482
1580
  "div",
1483
1581
  {
1484
1582
  className: cn(
@@ -1487,7 +1585,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1487
1585
  ),
1488
1586
  style: containerStyle,
1489
1587
  children: [
1490
- isDropdown ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1588
+ isDropdown ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1491
1589
  "select",
1492
1590
  {
1493
1591
  ref: selectRef,
@@ -1497,11 +1595,11 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1497
1595
  className: inputClassName ?? defaultInputClass,
1498
1596
  disabled: isLoading,
1499
1597
  children: [
1500
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
1501
- normalizedOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
1598
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
1599
+ normalizedOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
1502
1600
  ]
1503
1601
  }
1504
- ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1602
+ ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1505
1603
  "input",
1506
1604
  {
1507
1605
  ref: inputRef,
@@ -1514,7 +1612,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1514
1612
  disabled: isLoading
1515
1613
  }
1516
1614
  ),
1517
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1615
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1518
1616
  "button",
1519
1617
  {
1520
1618
  type: "button",
@@ -1523,10 +1621,10 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1523
1621
  className: saveButtonClassName ?? (saveButtonStyle ? void 0 : defaultSaveBtnClass),
1524
1622
  style: saveButtonStyle,
1525
1623
  title: "Save (Enter)",
1526
- children: isLoading ? loadingIndicator ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ButtonSpinner, {}) : saveButtonContent ?? "Save"
1624
+ children: isLoading ? loadingIndicator ?? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ButtonSpinner, {}) : saveButtonContent ?? "Save"
1527
1625
  }
1528
1626
  ),
1529
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1627
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1530
1628
  "button",
1531
1629
  {
1532
1630
  type: "button",
@@ -1555,6 +1653,8 @@ CustomCellEditor.displayName = "CustomCellEditor";
1555
1653
  ResetFiltersButton,
1556
1654
  SearchInput,
1557
1655
  TableLayoutToolbarControls,
1656
+ ToolTip,
1657
+ TooltipText,
1558
1658
  capitalizeText,
1559
1659
  checkIfExistsInArray,
1560
1660
  cn,