@sikka/hawa 0.41.1-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.
@@ -10,6 +10,12 @@ type DataTableProps<DataProps = {}> = {
10
10
  enableHideColumns?: boolean;
11
11
  enableGoTo?: boolean;
12
12
  enableSelection?: boolean;
13
+ enableFiltering?: boolean;
14
+ filters?: {
15
+ accessorKey: string;
16
+ value: string;
17
+ label: string;
18
+ }[];
13
19
  hideHeader?: boolean;
14
20
  data: DataProps[];
15
21
  itemsPerPage?: any[];
@@ -43,6 +49,6 @@ declare module "@tanstack/table-core" {
43
49
  i18nKey?: string;
44
50
  }
45
51
  }
46
- declare const DataTable: <DataProps extends {}>({ columns, data, paginationPosition, translateFn, enableHideColumns, enableSelection, enableSearch, enableGoTo, ...props }: DataTableProps<DataProps>) => React.JSX.Element;
52
+ declare const DataTable: <DataProps extends {}>({ columns, data, paginationPosition, translateFn, enableHideColumns, enableSelection, enableFiltering, enableSearch, enableGoTo, ...props }: DataTableProps<DataProps>) => React.JSX.Element;
47
53
 
48
54
  export { DataTable };
@@ -10,6 +10,12 @@ type DataTableProps<DataProps = {}> = {
10
10
  enableHideColumns?: boolean;
11
11
  enableGoTo?: boolean;
12
12
  enableSelection?: boolean;
13
+ enableFiltering?: boolean;
14
+ filters?: {
15
+ accessorKey: string;
16
+ value: string;
17
+ label: string;
18
+ }[];
13
19
  hideHeader?: boolean;
14
20
  data: DataProps[];
15
21
  itemsPerPage?: any[];
@@ -43,6 +49,6 @@ declare module "@tanstack/table-core" {
43
49
  i18nKey?: string;
44
50
  }
45
51
  }
46
- declare const DataTable: <DataProps extends {}>({ columns, data, paginationPosition, translateFn, enableHideColumns, enableSelection, enableSearch, enableGoTo, ...props }: DataTableProps<DataProps>) => React.JSX.Element;
52
+ declare const DataTable: <DataProps extends {}>({ columns, data, paginationPosition, translateFn, enableHideColumns, enableSelection, enableFiltering, enableSearch, enableGoTo, ...props }: DataTableProps<DataProps>) => React.JSX.Element;
47
53
 
48
54
  export { DataTable };
@@ -1334,11 +1334,12 @@ var DataTable = ({
1334
1334
  translateFn,
1335
1335
  enableHideColumns,
1336
1336
  enableSelection,
1337
+ enableFiltering,
1337
1338
  enableSearch,
1338
1339
  enableGoTo,
1339
1340
  ...props
1340
1341
  }) => {
1341
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1342
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1342
1343
  const [sorting, setSorting] = React11.useState(
1343
1344
  props.defaultSort ? [{ id: props.defaultSort, desc: false }] : []
1344
1345
  );
@@ -1352,6 +1353,7 @@ var DataTable = ({
1352
1353
  return savedVisibility ? JSON.parse(savedVisibility) : {};
1353
1354
  });
1354
1355
  const [rowSelection, setRowSelection] = React11.useState({});
1356
+ const [selectedFilters, setSelectedFilters] = React11.useState([]);
1355
1357
  let mainColumns = enableSelection ? [
1356
1358
  {
1357
1359
  id: "select",
@@ -1431,6 +1433,19 @@ var DataTable = ({
1431
1433
  return newColumnVisibility;
1432
1434
  });
1433
1435
  }, [columns]);
1436
+ React11.useEffect(() => {
1437
+ var _a2;
1438
+ (_a2 = props.filters) == null ? void 0 : _a2.forEach((filter) => {
1439
+ var _a3;
1440
+ const activeFilter = selectedFilters.find(
1441
+ (selectedFilter) => {
1442
+ var _a4, _b2;
1443
+ return filter.accessorKey === ((_b2 = (_a4 = props.filters) == null ? void 0 : _a4.find((f) => f.value === selectedFilter)) == null ? void 0 : _b2.accessorKey);
1444
+ }
1445
+ );
1446
+ (_a3 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a3.setFilterValue(activeFilter || "");
1447
+ });
1448
+ }, [selectedFilters, props.filters]);
1434
1449
  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(
1435
1450
  Input,
1436
1451
  {
@@ -1514,7 +1529,33 @@ var DataTable = ({
1514
1529
  ) : column.id
1515
1530
  );
1516
1531
  })
1517
- ))), props.isLoading ? /* @__PURE__ */ React11.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React11.createElement(
1532
+ ))), enableFiltering && /* @__PURE__ */ React11.createElement("div", { className: "hawa-flex-row hawa-gap-2 hawa-flex" }, (_e = props.filters) == null ? void 0 : _e.map((filter) => {
1533
+ return /* @__PURE__ */ React11.createElement(
1534
+ Button,
1535
+ {
1536
+ variant: "outline",
1537
+ className: selectedFilters.includes(filter.value) ? "!hawa-bg-primary !hawa-text-primary-foreground" : "",
1538
+ size: "xs",
1539
+ onClick: () => {
1540
+ var _a2, _b2;
1541
+ let newSelectedFilters = selectedFilters.filter(
1542
+ (item) => {
1543
+ var _a3, _b3;
1544
+ return ((_b3 = (_a3 = props.filters) == null ? void 0 : _a3.find((f) => f.value === item)) == null ? void 0 : _b3.accessorKey) !== filter.accessorKey;
1545
+ }
1546
+ );
1547
+ if (!selectedFilters.includes(filter.value)) {
1548
+ newSelectedFilters.push(filter.value);
1549
+ (_a2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a2.setFilterValue(filter.value);
1550
+ } else {
1551
+ (_b2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _b2.setFilterValue("");
1552
+ }
1553
+ setSelectedFilters(newSelectedFilters);
1554
+ }
1555
+ },
1556
+ filter.label
1557
+ );
1558
+ })), props.isLoading ? /* @__PURE__ */ React11.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React11.createElement(
1518
1559
  "div",
1519
1560
  {
1520
1561
  className: cn(
@@ -1543,7 +1584,7 @@ var DataTable = ({
1543
1584
  header.getContext()
1544
1585
  )
1545
1586
  );
1546
- })))), /* @__PURE__ */ React11.createElement(TableBody, null, ((_e = table.getRowModel().rows) == null ? void 0 : _e.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React11.createElement(
1587
+ })))), /* @__PURE__ */ React11.createElement(TableBody, null, ((_f = table.getRowModel().rows) == null ? void 0 : _f.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React11.createElement(
1547
1588
  TableRow,
1548
1589
  {
1549
1590
  key: row.id,
@@ -1575,7 +1616,7 @@ var DataTable = ({
1575
1616
  colSpan: columns.length,
1576
1617
  className: "hawa-h-24 hawa-text-center"
1577
1618
  },
1578
- (_f = props.texts) == null ? void 0 : _f.noData
1619
+ (_g = props.texts) == null ? void 0 : _g.noData
1579
1620
  ))))),
1580
1621
  /* @__PURE__ */ React11.createElement(
1581
1622
  "div",
@@ -1592,7 +1633,7 @@ var DataTable = ({
1592
1633
  className: "hawa-text-muted-foreground hawa-text-sm",
1593
1634
  dir: props.direction
1594
1635
  },
1595
- /* @__PURE__ */ React11.createElement("span", null, (_g = props.texts) == null ? void 0 : _g.total),
1636
+ /* @__PURE__ */ React11.createElement("span", null, (_h = props.texts) == null ? void 0 : _h.total),
1596
1637
  " ",
1597
1638
  /* @__PURE__ */ React11.createElement("span", null, table.getFilteredRowModel().rows.length.toLocaleString())
1598
1639
  ), 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(
@@ -1603,11 +1644,11 @@ var DataTable = ({
1603
1644
  },
1604
1645
  table.getFilteredSelectedRowModel().rows.length,
1605
1646
  " ",
1606
- (_h = props.texts) == null ? void 0 : _h.of,
1647
+ (_i = props.texts) == null ? void 0 : _i.of,
1607
1648
  " ",
1608
1649
  table.getFilteredRowModel().rows.length,
1609
1650
  " ",
1610
- (_i = props.texts) == null ? void 0 : _i.selectedRows
1651
+ (_j = props.texts) == null ? void 0 : _j.selectedRows
1611
1652
  )), table.getFilteredSelectedRowModel().rows.length > 0 && /* @__PURE__ */ React11.createElement("div", { className: "" }, /* @__PURE__ */ React11.createElement(
1612
1653
  DropdownMenu,
1613
1654
  {
@@ -1620,10 +1661,10 @@ var DataTable = ({
1620
1661
  table.getFilteredSelectedRowModel().rows
1621
1662
  )
1622
1663
  })),
1623
- trigger: /* @__PURE__ */ React11.createElement(Button, { size: "xs" }, ((_j = props.texts) == null ? void 0 : _j.bulkAction) || "Bulk Action")
1664
+ trigger: /* @__PURE__ */ React11.createElement(Button, { size: "xs" }, ((_k = props.texts) == null ? void 0 : _k.bulkAction) || "Bulk Action")
1624
1665
  }
1625
1666
  ))) : null,
1626
- /* @__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(
1667
+ /* @__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(
1627
1668
  "input",
1628
1669
  {
1629
1670
  max: table.getPageCount(),
@@ -1660,11 +1701,11 @@ var DataTable = ({
1660
1701
  size: "icon",
1661
1702
  className: "hawa-h-fit hawa-w-fit hawa-p-0 hawa-px-2 hawa-py-1 hawa-whitespace-nowrap"
1662
1703
  },
1663
- `${table.getState().pagination.pageSize} / ${(_l = props.texts) == null ? void 0 : _l.page}`
1704
+ `${table.getState().pagination.pageSize} / ${(_m = props.texts) == null ? void 0 : _m.page}`
1664
1705
  ),
1665
1706
  onItemSelect: (e) => table.setPageSize(Number(e))
1666
1707
  }
1667
- ), 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(
1708
+ ), 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(
1668
1709
  Button,
1669
1710
  {
1670
1711
  "aria-label": "Next Table Page",