@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.
package/dist/index.mjs CHANGED
@@ -3058,11 +3058,12 @@ var DataTable = ({
3058
3058
  translateFn,
3059
3059
  enableHideColumns,
3060
3060
  enableSelection,
3061
+ enableFiltering,
3061
3062
  enableSearch,
3062
3063
  enableGoTo,
3063
3064
  ...props
3064
3065
  }) => {
3065
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3066
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
3066
3067
  const [sorting, setSorting] = React24.useState(
3067
3068
  props.defaultSort ? [{ id: props.defaultSort, desc: false }] : []
3068
3069
  );
@@ -3076,6 +3077,7 @@ var DataTable = ({
3076
3077
  return savedVisibility ? JSON.parse(savedVisibility) : {};
3077
3078
  });
3078
3079
  const [rowSelection, setRowSelection] = React24.useState({});
3080
+ const [selectedFilters, setSelectedFilters] = React24.useState([]);
3079
3081
  let mainColumns = enableSelection ? [
3080
3082
  {
3081
3083
  id: "select",
@@ -3155,6 +3157,19 @@ var DataTable = ({
3155
3157
  return newColumnVisibility;
3156
3158
  });
3157
3159
  }, [columns]);
3160
+ React24.useEffect(() => {
3161
+ var _a2;
3162
+ (_a2 = props.filters) == null ? void 0 : _a2.forEach((filter) => {
3163
+ var _a3;
3164
+ const activeFilter = selectedFilters.find(
3165
+ (selectedFilter) => {
3166
+ var _a4, _b2;
3167
+ return filter.accessorKey === ((_b2 = (_a4 = props.filters) == null ? void 0 : _a4.find((f) => f.value === selectedFilter)) == null ? void 0 : _b2.accessorKey);
3168
+ }
3169
+ );
3170
+ (_a3 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a3.setFilterValue(activeFilter || "");
3171
+ });
3172
+ }, [selectedFilters, props.filters]);
3158
3173
  return /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-w-full hawa-flex-col hawa-gap-4" }, (enableSearch || enableHideColumns) && /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-gap-4" }, enableSearch && /* @__PURE__ */ React24.createElement(
3159
3174
  Input,
3160
3175
  {
@@ -3238,7 +3253,33 @@ var DataTable = ({
3238
3253
  ) : column.id
3239
3254
  );
3240
3255
  })
3241
- ))), props.isLoading ? /* @__PURE__ */ React24.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React24.createElement(
3256
+ ))), enableFiltering && /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex-row hawa-gap-2 hawa-flex" }, (_e = props.filters) == null ? void 0 : _e.map((filter) => {
3257
+ return /* @__PURE__ */ React24.createElement(
3258
+ Button,
3259
+ {
3260
+ variant: "outline",
3261
+ className: selectedFilters.includes(filter.value) ? "!hawa-bg-primary !hawa-text-primary-foreground" : "",
3262
+ size: "xs",
3263
+ onClick: () => {
3264
+ var _a2, _b2;
3265
+ let newSelectedFilters = selectedFilters.filter(
3266
+ (item) => {
3267
+ var _a3, _b3;
3268
+ return ((_b3 = (_a3 = props.filters) == null ? void 0 : _a3.find((f) => f.value === item)) == null ? void 0 : _b3.accessorKey) !== filter.accessorKey;
3269
+ }
3270
+ );
3271
+ if (!selectedFilters.includes(filter.value)) {
3272
+ newSelectedFilters.push(filter.value);
3273
+ (_a2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _a2.setFilterValue(filter.value);
3274
+ } else {
3275
+ (_b2 = table.getColumn(filter.accessorKey)) == null ? void 0 : _b2.setFilterValue("");
3276
+ }
3277
+ setSelectedFilters(newSelectedFilters);
3278
+ }
3279
+ },
3280
+ filter.label
3281
+ );
3282
+ })), props.isLoading ? /* @__PURE__ */ React24.createElement(Skeleton, { className: "hawa-h-[130px] hawa-w-full" }) : /* @__PURE__ */ React24.createElement(
3242
3283
  "div",
3243
3284
  {
3244
3285
  className: cn(
@@ -3267,7 +3308,7 @@ var DataTable = ({
3267
3308
  header.getContext()
3268
3309
  )
3269
3310
  );
3270
- })))), /* @__PURE__ */ React24.createElement(TableBody, null, ((_e = table.getRowModel().rows) == null ? void 0 : _e.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React24.createElement(
3311
+ })))), /* @__PURE__ */ React24.createElement(TableBody, null, ((_f = table.getRowModel().rows) == null ? void 0 : _f.length) ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React24.createElement(
3271
3312
  TableRow,
3272
3313
  {
3273
3314
  key: row.id,
@@ -3299,7 +3340,7 @@ var DataTable = ({
3299
3340
  colSpan: columns.length,
3300
3341
  className: "hawa-h-24 hawa-text-center"
3301
3342
  },
3302
- (_f = props.texts) == null ? void 0 : _f.noData
3343
+ (_g = props.texts) == null ? void 0 : _g.noData
3303
3344
  ))))),
3304
3345
  /* @__PURE__ */ React24.createElement(
3305
3346
  "div",
@@ -3316,7 +3357,7 @@ var DataTable = ({
3316
3357
  className: "hawa-text-muted-foreground hawa-text-sm",
3317
3358
  dir: props.direction
3318
3359
  },
3319
- /* @__PURE__ */ React24.createElement("span", null, (_g = props.texts) == null ? void 0 : _g.total),
3360
+ /* @__PURE__ */ React24.createElement("span", null, (_h = props.texts) == null ? void 0 : _h.total),
3320
3361
  " ",
3321
3362
  /* @__PURE__ */ React24.createElement("span", null, table.getFilteredRowModel().rows.length.toLocaleString())
3322
3363
  ), props.showCount && table.getFilteredSelectedRowModel().rows.length > 0 && props.showSelectionCount && /* @__PURE__ */ React24.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__ */ React24.createElement(
@@ -3327,11 +3368,11 @@ var DataTable = ({
3327
3368
  },
3328
3369
  table.getFilteredSelectedRowModel().rows.length,
3329
3370
  " ",
3330
- (_h = props.texts) == null ? void 0 : _h.of,
3371
+ (_i = props.texts) == null ? void 0 : _i.of,
3331
3372
  " ",
3332
3373
  table.getFilteredRowModel().rows.length,
3333
3374
  " ",
3334
- (_i = props.texts) == null ? void 0 : _i.selectedRows
3375
+ (_j = props.texts) == null ? void 0 : _j.selectedRows
3335
3376
  )), table.getFilteredSelectedRowModel().rows.length > 0 && /* @__PURE__ */ React24.createElement("div", { className: "" }, /* @__PURE__ */ React24.createElement(
3336
3377
  DropdownMenu,
3337
3378
  {
@@ -3344,10 +3385,10 @@ var DataTable = ({
3344
3385
  table.getFilteredSelectedRowModel().rows
3345
3386
  )
3346
3387
  })),
3347
- trigger: /* @__PURE__ */ React24.createElement(Button, { size: "xs" }, ((_j = props.texts) == null ? void 0 : _j.bulkAction) || "Bulk Action")
3388
+ trigger: /* @__PURE__ */ React24.createElement(Button, { size: "xs" }, ((_k = props.texts) == null ? void 0 : _k.bulkAction) || "Bulk Action")
3348
3389
  }
3349
3390
  ))) : null,
3350
- /* @__PURE__ */ React24.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__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-2" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-text-sm" }, (_k = props.texts) == null ? void 0 : _k.goTo), /* @__PURE__ */ React24.createElement(
3391
+ /* @__PURE__ */ React24.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__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-2" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-text-sm" }, (_l = props.texts) == null ? void 0 : _l.goTo), /* @__PURE__ */ React24.createElement(
3351
3392
  "input",
3352
3393
  {
3353
3394
  max: table.getPageCount(),
@@ -3384,11 +3425,11 @@ var DataTable = ({
3384
3425
  size: "icon",
3385
3426
  className: "hawa-h-fit hawa-w-fit hawa-p-0 hawa-px-2 hawa-py-1 hawa-whitespace-nowrap"
3386
3427
  },
3387
- `${table.getState().pagination.pageSize} / ${(_l = props.texts) == null ? void 0 : _l.page}`
3428
+ `${table.getState().pagination.pageSize} / ${(_m = props.texts) == null ? void 0 : _m.page}`
3388
3429
  ),
3389
3430
  onItemSelect: (e) => table.setPageSize(Number(e))
3390
3431
  }
3391
- ), table.getPageCount() > 1 && /* @__PURE__ */ React24.createElement("div", { className: "hawa-bg--500 hawa-flex hawa-flex-row hawa-gap-2" }, /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-bg--500 hawa-w-fit hawa-flex-row hawa-items-center hawa-gap-2 hawa-text-sm" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-flex hawa-items-center hawa-gap-1" }, /* @__PURE__ */ React24.createElement("div", null, (_m = props.texts) == null ? void 0 : _m.page), /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-1" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-font-bold" }, table.getState().pagination.pageIndex + 1), /* @__PURE__ */ React24.createElement("span", null, (_n = props.texts) == null ? void 0 : _n.of), /* @__PURE__ */ React24.createElement("span", { className: "hawa-font-bold" }, table.getPageCount())))), /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-2 hawa-items-center hawa-bg--500" }, /* @__PURE__ */ React24.createElement(
3432
+ ), table.getPageCount() > 1 && /* @__PURE__ */ React24.createElement("div", { className: "hawa-bg--500 hawa-flex hawa-flex-row hawa-gap-2" }, /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-bg--500 hawa-w-fit hawa-flex-row hawa-items-center hawa-gap-2 hawa-text-sm" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-flex hawa-items-center hawa-gap-1" }, /* @__PURE__ */ React24.createElement("div", null, (_n = props.texts) == null ? void 0 : _n.page), /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-1" }, /* @__PURE__ */ React24.createElement("span", { className: "hawa-font-bold" }, table.getState().pagination.pageIndex + 1), /* @__PURE__ */ React24.createElement("span", null, (_o = props.texts) == null ? void 0 : _o.of), /* @__PURE__ */ React24.createElement("span", { className: "hawa-font-bold" }, table.getPageCount())))), /* @__PURE__ */ React24.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-2 hawa-items-center hawa-bg--500" }, /* @__PURE__ */ React24.createElement(
3392
3433
  Button,
3393
3434
  {
3394
3435
  "aria-label": "Next Table Page",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sikka/hawa",
3
- "version": "0.41.2-next",
3
+ "version": "0.42.0-next",
4
4
  "description": "Modern UI Kit made with Tailwind",
5
5
  "author": {
6
6
  "name": "Sikka Software",