@eztrak/shared 0.7.4 → 0.8.0

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,107 @@ 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
+ delayShow,
1370
+ delayHide,
1371
+ className: tooltipClassName,
1372
+ style: { ...defaultTooltipStyle, ...tooltipStyle }
1373
+ }
1374
+ )
1375
+ ] });
1376
+ }
1377
+
1378
+ // src/components/tooltip/TooltipText.tsx
1379
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1380
+ function TooltipText({
1381
+ text = "",
1382
+ maxLength = 20,
1383
+ fallback = "-",
1384
+ placement = "top",
1385
+ delayShow,
1386
+ delayHide,
1387
+ className,
1388
+ textClassName,
1389
+ tooltipClassName,
1390
+ tooltipStyle,
1391
+ showTooltip = true,
1392
+ tooltipWhenTruncatedOnly = false
1393
+ }) {
1394
+ const hasValue = text !== null && text !== void 0 && text !== "";
1395
+ const fullText = hasValue ? String(text) : fallback;
1396
+ const displayText = truncateText(fullText, maxLength);
1397
+ const isTruncated = displayText !== fullText;
1398
+ const tooltipDisabled = !showTooltip || !hasValue || tooltipWhenTruncatedOnly && !isTruncated;
1399
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1400
+ ToolTip,
1401
+ {
1402
+ text: fullText,
1403
+ placement,
1404
+ delayShow,
1405
+ delayHide,
1406
+ className: cn("inline-block max-w-full", className),
1407
+ tooltipClassName,
1408
+ tooltipStyle,
1409
+ wrapperTabIndex: tooltipDisabled ? void 0 : 0,
1410
+ disabled: tooltipDisabled,
1411
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: cn("inline-block max-w-full align-bottom", textClassName), children: displayText })
1412
+ }
1413
+ );
1414
+ }
1415
+
1416
+ // src/components/cell-editor/CustomCellEditor.tsx
1417
+ var import_react7 = require("react");
1418
+ var import_react_hot_toast2 = __toESM(require("react-hot-toast"));
1419
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1323
1420
  function ButtonSpinner() {
1324
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1421
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1325
1422
  "svg",
1326
1423
  {
1327
1424
  className: "animate-spin",
@@ -1331,7 +1428,7 @@ function ButtonSpinner() {
1331
1428
  fill: "none",
1332
1429
  "aria-hidden": true,
1333
1430
  children: [
1334
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1431
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1335
1432
  "circle",
1336
1433
  {
1337
1434
  cx: "12",
@@ -1342,7 +1439,7 @@ function ButtonSpinner() {
1342
1439
  strokeOpacity: "0.25"
1343
1440
  }
1344
1441
  ),
1345
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1442
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1346
1443
  "path",
1347
1444
  {
1348
1445
  d: "M12 2a10 10 0 0 1 10 10",
@@ -1364,7 +1461,7 @@ function normalizeInitialValue(initialValue, inputType) {
1364
1461
  }
1365
1462
  return initialValue;
1366
1463
  }
1367
- var CustomCellEditor = (0, import_react6.forwardRef)(
1464
+ var CustomCellEditor = (0, import_react7.forwardRef)(
1368
1465
  ({
1369
1466
  value: initialValue,
1370
1467
  name,
@@ -1389,11 +1486,11 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1389
1486
  cancelButtonClassName
1390
1487
  }, ref) => {
1391
1488
  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)(() => {
1489
+ const [value, setValue] = (0, import_react7.useState)(normalizedInitial);
1490
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
1491
+ const inputRef = (0, import_react7.useRef)(null);
1492
+ const selectRef = (0, import_react7.useRef)(null);
1493
+ const normalizedOptions = (0, import_react7.useMemo)(() => {
1397
1494
  if (customOptions && customOptions.length > 0) {
1398
1495
  return customOptions.map((opt) => ({
1399
1496
  value: String(opt[valueKey] ?? ""),
@@ -1403,13 +1500,13 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1403
1500
  return dropdownOptions;
1404
1501
  }, [customOptions, dropdownOptions, valueKey, labelKey]);
1405
1502
  const isDropdown = inputType === "dropdown" || normalizedOptions.length > 0;
1406
- (0, import_react6.useImperativeHandle)(ref, () => ({
1503
+ (0, import_react7.useImperativeHandle)(ref, () => ({
1407
1504
  getValue: () => value,
1408
1505
  isCancelBeforeStart: () => false,
1409
1506
  isCancelAfterEnd: () => false,
1410
1507
  isPopup: () => true
1411
1508
  }));
1412
- (0, import_react6.useEffect)(() => {
1509
+ (0, import_react7.useEffect)(() => {
1413
1510
  if (isDropdown) {
1414
1511
  selectRef.current?.focus();
1415
1512
  return;
@@ -1478,7 +1575,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1478
1575
  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
1576
  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
1577
  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)(
1578
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1482
1579
  "div",
1483
1580
  {
1484
1581
  className: cn(
@@ -1487,7 +1584,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1487
1584
  ),
1488
1585
  style: containerStyle,
1489
1586
  children: [
1490
- isDropdown ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1587
+ isDropdown ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1491
1588
  "select",
1492
1589
  {
1493
1590
  ref: selectRef,
@@ -1497,11 +1594,11 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1497
1594
  className: inputClassName ?? defaultInputClass,
1498
1595
  disabled: isLoading,
1499
1596
  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))
1597
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
1598
+ normalizedOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
1502
1599
  ]
1503
1600
  }
1504
- ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1601
+ ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1505
1602
  "input",
1506
1603
  {
1507
1604
  ref: inputRef,
@@ -1514,7 +1611,7 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1514
1611
  disabled: isLoading
1515
1612
  }
1516
1613
  ),
1517
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1614
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1518
1615
  "button",
1519
1616
  {
1520
1617
  type: "button",
@@ -1523,10 +1620,10 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
1523
1620
  className: saveButtonClassName ?? (saveButtonStyle ? void 0 : defaultSaveBtnClass),
1524
1621
  style: saveButtonStyle,
1525
1622
  title: "Save (Enter)",
1526
- children: isLoading ? loadingIndicator ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ButtonSpinner, {}) : saveButtonContent ?? "Save"
1623
+ children: isLoading ? loadingIndicator ?? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ButtonSpinner, {}) : saveButtonContent ?? "Save"
1527
1624
  }
1528
1625
  ),
1529
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1626
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1530
1627
  "button",
1531
1628
  {
1532
1629
  type: "button",
@@ -1555,6 +1652,8 @@ CustomCellEditor.displayName = "CustomCellEditor";
1555
1652
  ResetFiltersButton,
1556
1653
  SearchInput,
1557
1654
  TableLayoutToolbarControls,
1655
+ ToolTip,
1656
+ TooltipText,
1558
1657
  capitalizeText,
1559
1658
  checkIfExistsInArray,
1560
1659
  cn,