@sikka/hawa 0.41.2-next → 0.42.0-next

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.
@@ -1307,11 +1307,12 @@ var DataTable = ({
1307
1307
  translateFn,
1308
1308
  enableHideColumns,
1309
1309
  enableSelection,
1310
+ enableFiltering,
1310
1311
  enableSearch,
1311
1312
  enableGoTo,
1312
1313
  ...props
1313
1314
  }) => {
1314
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1315
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1315
1316
  const [sorting, setSorting] = React11.useState(
1316
1317
  props.defaultSort ? [{ id: props.defaultSort, desc: false }] : []
1317
1318
  );
@@ -1325,6 +1326,7 @@ var DataTable = ({
1325
1326
  return savedVisibility ? JSON.parse(savedVisibility) : {};
1326
1327
  });
1327
1328
  const [rowSelection, setRowSelection] = React11.useState({});
1329
+ const [selectedFilters, setSelectedFilters] = React11.useState([]);
1328
1330
  let mainColumns = enableSelection ? [
1329
1331
  {
1330
1332
  id: "select",
@@ -1404,6 +1406,19 @@ var DataTable = ({
1404
1406
  return newColumnVisibility;
1405
1407
  });
1406
1408
  }, [columns]);
1409
+ React11.useEffect(() => {
1410
+ var _a2;
1411
+ (_a2 = props.filters) == null ? void 0 : _a2.forEach((filter) => {
1412
+ var _a3;
1413
+ const activeFilter = selectedFilters.find(
1414
+ (selectedFilter) => {
1415
+ var _a4, _b2;
1416
+ return filter.accessorKey === ((_b2 = (_a4 = props.filters) == null ? void 0 : _a4.find((f) => f.value === selectedFilter)) == null ? void 0 : _b2.accessorKey);
1417
+ }
1418
+ );
1419
+ (_a3 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a3.setFilterValue(activeFilter || "");
1420
+ });
1421
+ }, [selectedFilters, props.filters]);
1407
1422
  return /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-w-full hawa-flex-col hawa-gap-4" }, (enableSearch || enableHideColumns) && /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-gap-4" }, enableSearch && /* @__PURE__ */ React11.createElement(
1408
1423
  Input,
1409
1424
  {
@@ -1487,7 +1502,33 @@ var DataTable = ({
1487
1502
  ) : column.id
1488
1503
  );
1489
1504
  })
1490
- ))), props.isLoading ? /* @__PURE__ */ React11.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React11.createElement(
1505
+ ))), enableFiltering && /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex-row hawa-gap-2 hawa-flex" }, (_e = props.filters) == null ? void 0 : _e.map((filter) => {
1506
+ return /* @__PURE__ */ React11.createElement(
1507
+ Button,
1508
+ {
1509
+ variant: "outline",
1510
+ className: selectedFilters.includes(filter.value) ? "!hawa-bg-primary !hawa-text-primary-foreground" : "",
1511
+ size: "xs",
1512
+ onClick: () => {
1513
+ var _a2, _b2;
1514
+ let newSelectedFilters = selectedFilters.filter(
1515
+ (item) => {
1516
+ var _a3, _b3;
1517
+ return ((_b3 = (_a3 = props.filters) == null ? void 0 : _a3.find((f) => f.value === item)) == null ? void 0 : _b3.accessorKey) !== filter.accessorKey;
1518
+ }
1519
+ );
1520
+ if (!selectedFilters.includes(filter.value)) {
1521
+ newSelectedFilters.push(filter.value);
1522
+ (_a2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a2.setFilterValue(filter.value);
1523
+ } else {
1524
+ (_b2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _b2.setFilterValue("");
1525
+ }
1526
+ setSelectedFilters(newSelectedFilters);
1527
+ }
1528
+ },
1529
+ filter.label
1530
+ );
1531
+ })), props.isLoading ? /* @__PURE__ */ React11.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React11.createElement(
1491
1532
  "div",
1492
1533
  {
1493
1534
  className: cn(
@@ -1516,7 +1557,7 @@ var DataTable = ({
1516
1557
  header.getContext()
1517
1558
  )
1518
1559
  );
1519
- })))), /* @__PURE__ */ React11.createElement(TableBody, null, ((_e = table.getRowModel().rows) == null ? void 0 : _e.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React11.createElement(
1560
+ })))), /* @__PURE__ */ React11.createElement(TableBody, null, ((_f = table.getRowModel().rows) == null ? void 0 : _f.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React11.createElement(
1520
1561
  TableRow,
1521
1562
  {
1522
1563
  key: row.id,
@@ -1548,7 +1589,7 @@ var DataTable = ({
1548
1589
  colSpan: columns.length,
1549
1590
  className: "hawa-h-24 hawa-text-center"
1550
1591
  },
1551
- (_f = props.texts) == null ? void 0 : _f.noData
1592
+ (_g = props.texts) == null ? void 0 : _g.noData
1552
1593
  ))))),
1553
1594
  /* @__PURE__ */ React11.createElement(
1554
1595
  "div",
@@ -1565,7 +1606,7 @@ var DataTable = ({
1565
1606
  className: "hawa-text-muted-foreground hawa-text-sm",
1566
1607
  dir: props.direction
1567
1608
  },
1568
- /* @__PURE__ */ React11.createElement("span", null, (_g = props.texts) == null ? void 0 : _g.total),
1609
+ /* @__PURE__ */ React11.createElement("span", null, (_h = props.texts) == null ? void 0 : _h.total),
1569
1610
  " ",
1570
1611
  /* @__PURE__ */ React11.createElement("span", null, table.getFilteredRowModel().rows.length.toLocaleString())
1571
1612
  ), props.showCount && table.getFilteredSelectedRowModel().rows.length > 0 && props.showSelectionCount && /* @__PURE__ */ React11.createElement("div", { className: "hawa-w-[0.5px] hawa-mx-2 hawa-bg-red-500 hawa-h-full" }), table.getFilteredSelectedRowModel().rows.length > 0 && props.showSelectionCount && /* @__PURE__ */ React11.createElement(
@@ -1576,11 +1617,11 @@ var DataTable = ({
1576
1617
  },
1577
1618
  table.getFilteredSelectedRowModel().rows.length,
1578
1619
  " ",
1579
- (_h = props.texts) == null ? void 0 : _h.of,
1620
+ (_i = props.texts) == null ? void 0 : _i.of,
1580
1621
  " ",
1581
1622
  table.getFilteredRowModel().rows.length,
1582
1623
  " ",
1583
- (_i = props.texts) == null ? void 0 : _i.selectedRows
1624
+ (_j = props.texts) == null ? void 0 : _j.selectedRows
1584
1625
  )), table.getFilteredSelectedRowModel().rows.length > 0 && /* @__PURE__ */ React11.createElement("div", { className: "" }, /* @__PURE__ */ React11.createElement(
1585
1626
  DropdownMenu,
1586
1627
  {
@@ -1593,10 +1634,10 @@ var DataTable = ({
1593
1634
  table.getFilteredSelectedRowModel().rows
1594
1635
  )
1595
1636
  })),
1596
- trigger: /* @__PURE__ */ React11.createElement(Button, { size: "xs" }, ((_j = props.texts) == null ? void 0 : _j.bulkAction) || "Bulk Action")
1637
+ trigger: /* @__PURE__ */ React11.createElement(Button, { size: "xs" }, ((_k = props.texts) == null ? void 0 : _k.bulkAction) || "Bulk Action")
1597
1638
  }
1598
1639
  ))) : null,
1599
- /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-w-full hawa-flex-row hawa-items-center hawa-gap-2 hawa-bg--500 tablet:hawa-w-fit hawa-justify-between" }, enableGoTo && /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-2" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-text-sm" }, (_k = props.texts) == null ? void 0 : _k.goTo), /* @__PURE__ */ React11.createElement(
1640
+ /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-w-full hawa-flex-row hawa-items-center hawa-gap-2 hawa-bg--500 tablet:hawa-w-fit hawa-justify-between" }, enableGoTo && /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-2" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-text-sm" }, (_l = props.texts) == null ? void 0 : _l.goTo), /* @__PURE__ */ React11.createElement(
1600
1641
  "input",
1601
1642
  {
1602
1643
  max: table.getPageCount(),
@@ -1633,11 +1674,11 @@ var DataTable = ({
1633
1674
  size: "icon",
1634
1675
  className: "hawa-h-fit hawa-w-fit hawa-p-0 hawa-px-2 hawa-py-1 hawa-whitespace-nowrap"
1635
1676
  },
1636
- `${table.getState().pagination.pageSize} / ${(_l = props.texts) == null ? void 0 : _l.page}`
1677
+ `${table.getState().pagination.pageSize} / ${(_m = props.texts) == null ? void 0 : _m.page}`
1637
1678
  ),
1638
1679
  onItemSelect: (e) => table.setPageSize(Number(e))
1639
1680
  }
1640
- ), table.getPageCount() > 1 && /* @__PURE__ */ React11.createElement("div", { className: "hawa-bg--500 hawa-flex hawa-flex-row hawa-gap-2" }, /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-bg--500 hawa-w-fit hawa-flex-row hawa-items-center hawa-gap-2 hawa-text-sm" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-flex hawa-items-center hawa-gap-1" }, /* @__PURE__ */ React11.createElement("div", null, (_m = props.texts) == null ? void 0 : _m.page), /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-1" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-font-bold" }, table.getState().pagination.pageIndex + 1), /* @__PURE__ */ React11.createElement("span", null, (_n = props.texts) == null ? void 0 : _n.of), /* @__PURE__ */ React11.createElement("span", { className: "hawa-font-bold" }, table.getPageCount())))), /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-2 hawa-items-center hawa-bg--500" }, /* @__PURE__ */ React11.createElement(
1681
+ ), table.getPageCount() > 1 && /* @__PURE__ */ React11.createElement("div", { className: "hawa-bg--500 hawa-flex hawa-flex-row hawa-gap-2" }, /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-bg--500 hawa-w-fit hawa-flex-row hawa-items-center hawa-gap-2 hawa-text-sm" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-flex hawa-items-center hawa-gap-1" }, /* @__PURE__ */ React11.createElement("div", null, (_n = props.texts) == null ? void 0 : _n.page), /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-1" }, /* @__PURE__ */ React11.createElement("span", { className: "hawa-font-bold" }, table.getState().pagination.pageIndex + 1), /* @__PURE__ */ React11.createElement("span", null, (_o = props.texts) == null ? void 0 : _o.of), /* @__PURE__ */ React11.createElement("span", { className: "hawa-font-bold" }, table.getPageCount())))), /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-2 hawa-items-center hawa-bg--500" }, /* @__PURE__ */ React11.createElement(
1641
1682
  Button,
1642
1683
  {
1643
1684
  "aria-label": "Next Table Page",