@dimaan/ui 0.0.18 → 0.0.19

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.cjs CHANGED
@@ -2192,11 +2192,15 @@ function useTableState(props) {
2192
2192
  };
2193
2193
  }
2194
2194
  var DEFAULT_PAGE_SIZE_OPTIONS = [10, 25, 50];
2195
+ function defaultGetRowId(row, index) {
2196
+ const rowId = row.id;
2197
+ return rowId === void 0 || rowId === null ? String(index) : String(rowId);
2198
+ }
2195
2199
  function Table(props) {
2196
2200
  const {
2197
2201
  data,
2198
2202
  columns,
2199
- getRowId,
2203
+ getRowId = defaultGetRowId,
2200
2204
  enableRowSelection = false,
2201
2205
  isRowSelectable,
2202
2206
  bulkActions,
@@ -2521,7 +2525,11 @@ function ListPage({
2521
2525
  isLoading = false,
2522
2526
  loadingRowCount,
2523
2527
  searchKeys,
2528
+ searchValue: searchValueProp,
2529
+ onSearchChange,
2524
2530
  filters,
2531
+ filterValues: filterValuesProp,
2532
+ onFilterChange,
2525
2533
  enableRowSelection,
2526
2534
  bulkActions,
2527
2535
  pagination,
@@ -2542,14 +2550,30 @@ function ListPage({
2542
2550
  }
2543
2551
  return init;
2544
2552
  }, [filters]);
2545
- const [search, setSearch] = react.useState("");
2546
- const [filterValues, setFilterValues] = react.useState(initialFilterValues);
2553
+ const isSearchControlled = searchValueProp !== void 0;
2554
+ const isFiltersControlled = filterValuesProp !== void 0;
2555
+ const [internalSearch, setInternalSearch] = react.useState("");
2556
+ const [internalFilterValues, setInternalFilterValues] = react.useState(initialFilterValues);
2557
+ const search = isSearchControlled ? searchValueProp : internalSearch;
2558
+ const filterValues = isFiltersControlled ? filterValuesProp : internalFilterValues;
2559
+ const setSearch = (next) => {
2560
+ if (!isSearchControlled) setInternalSearch(next);
2561
+ onSearchChange?.(next);
2562
+ };
2547
2563
  const setFilter = (key, value) => {
2548
- setFilterValues((prev) => ({ ...prev, [key]: value }));
2564
+ if (!isFiltersControlled) {
2565
+ setInternalFilterValues((prev) => ({ ...prev, [key]: value }));
2566
+ }
2567
+ onFilterChange?.(key, value);
2549
2568
  };
2550
2569
  const reset = () => {
2551
- setSearch("");
2552
- setFilterValues(initialFilterValues);
2570
+ if (!isSearchControlled) setInternalSearch("");
2571
+ onSearchChange?.("");
2572
+ if (!isFiltersControlled) setInternalFilterValues(initialFilterValues);
2573
+ for (const f of filters ?? []) {
2574
+ const def = f.defaultValue ?? f.options[0]?.value ?? "";
2575
+ onFilterChange?.(f.key, def);
2576
+ }
2553
2577
  };
2554
2578
  const hasActiveFilters = react.useMemo(() => {
2555
2579
  if (search.trim() !== "") return true;
@@ -2562,7 +2586,7 @@ function ListPage({
2562
2586
  }, [search, filters, filterValues]);
2563
2587
  const filtered = react.useMemo(() => {
2564
2588
  return data.filter((row) => {
2565
- if (search.trim() && searchKeys && searchKeys.length > 0) {
2589
+ if (!isSearchControlled && search.trim() && searchKeys && searchKeys.length > 0) {
2566
2590
  const q = search.trim().toLowerCase();
2567
2591
  const matches = searchKeys.some((key) => {
2568
2592
  const val = row[key];
@@ -2570,16 +2594,18 @@ function ListPage({
2570
2594
  });
2571
2595
  if (!matches) return false;
2572
2596
  }
2573
- for (const f of filters ?? []) {
2574
- const value = filterValues[f.key];
2575
- const def = f.defaultValue ?? f.options[0]?.value ?? "";
2576
- if (value !== void 0 && value !== def) {
2577
- if (f.accessor(row) !== value) return false;
2597
+ if (!isFiltersControlled) {
2598
+ for (const f of filters ?? []) {
2599
+ const value = filterValues[f.key];
2600
+ const def = f.defaultValue ?? f.options[0]?.value ?? "";
2601
+ if (value !== void 0 && value !== def) {
2602
+ if (f.accessor(row) !== value) return false;
2603
+ }
2578
2604
  }
2579
2605
  }
2580
2606
  return true;
2581
2607
  });
2582
- }, [data, search, searchKeys, filters, filterValues]);
2608
+ }, [data, search, searchKeys, filters, filterValues, isSearchControlled, isFiltersControlled]);
2583
2609
  const showFilterBar = Boolean(searchKeys?.length) || Boolean(filters?.length);
2584
2610
  const tableMode = isLoading ? "loading" : data.length === 0 && !hasActiveFilters ? "no-data" : filtered.length === 0 ? "no-results" : "rows";
2585
2611
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-slot": "list-page", className: cn("space-y-6", className), children: [