ikoncomponents 1.7.2 → 1.7.3

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,7 +10,7 @@ import { DataTablePageSize } from "./DataTablePageSize";
10
10
  import { Button } from "../../shadcn/button";
11
11
  import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, } from "../../shadcn/dropdown-menu";
12
12
  export function DataTableLayout({ data, columns, extraTools, }) {
13
- const { keyExtractor, totalPages, currentPage, filterComponent, actionNode, onRowClick, gridComponent, isLoading, onReload, themeColor, onLoadMore, hasMore, onFilterChange, } = extraTools !== null && extraTools !== void 0 ? extraTools : {};
13
+ const { keyExtractor, totalPages, currentPage, filterComponent, actionNode, onRowClick, gridComponent, isLoading, onReload, themeColor, onLoadMore, hasMore, onFilterChange, unfilteredData, } = extraTools !== null && extraTools !== void 0 ? extraTools : {};
14
14
  const [viewMode, setViewMode] = useState("list");
15
15
  const observerTarget = useRef(null);
16
16
  useEffect(() => {
@@ -38,20 +38,19 @@ export function DataTableLayout({ data, columns, extraTools, }) {
38
38
  setVisibleColumns(prev => prev.includes(header) ? prev.filter(h => h !== header) : [...prev, header]);
39
39
  };
40
40
  const handleToggleFilterValue = (column, value) => {
41
- setTableFilters(prev => {
42
- const currentValues = prev[column] || [];
43
- const nextValues = currentValues.includes(value)
44
- ? currentValues.filter(v => v !== value)
45
- : [...currentValues, value];
46
- const next = Object.assign({}, prev);
47
- if (nextValues.length === 0) {
48
- delete next[column];
49
- }
50
- else {
51
- next[column] = nextValues;
52
- }
53
- return next;
54
- });
41
+ const currentValues = tableFilters[column] || [];
42
+ const nextValues = currentValues.includes(value)
43
+ ? currentValues.filter(v => v !== value)
44
+ : [...currentValues, value];
45
+ const nextFilters = Object.assign({}, tableFilters);
46
+ if (nextValues.length === 0) {
47
+ delete nextFilters[column];
48
+ }
49
+ else {
50
+ nextFilters[column] = nextValues;
51
+ }
52
+ setTableFilters(nextFilters);
53
+ onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(nextFilters);
55
54
  };
56
55
  const removeActiveFilterColumn = (column) => {
57
56
  const nextActiveColumns = activeFilterColumns.filter(c => c !== column);
@@ -68,7 +67,8 @@ export function DataTableLayout({ data, columns, extraTools, }) {
68
67
  const col = columns.find(c => c.header === header);
69
68
  if (!col || !col.accessorKey)
70
69
  return [];
71
- const values = data.map(row => String(row[col.accessorKey] || ""));
70
+ const sourceData = unfilteredData || data;
71
+ const values = sourceData.map(row => String(row[col.accessorKey] || ""));
72
72
  return Array.from(new Set(values)).filter(Boolean).sort();
73
73
  };
74
74
  const handleToggleGroup = (columnHeader) => {
@@ -149,7 +149,12 @@ export function DataTableLayout({ data, columns, extraTools, }) {
149
149
  }, children: _jsx(X, { className: "w-3.5 h-3.5" }) })] }) }), _jsxs(DropdownMenuContent, { align: "start", className: "w-56 p-2 space-y-2", children: [_jsxs("div", { className: "px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider", children: ["Filter ", colHeader] }), _jsxs("div", { className: "px-2 relative", children: [_jsx(Search, { className: "absolute left-4 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground" }), _jsx("input", { type: "text", placeholder: "Search items...", value: searchQuery, onChange: (e) => setColumnSearchQueries(prev => (Object.assign(Object.assign({}, prev), { [colHeader]: e.target.value }))), className: "w-full h-8 pl-8 pr-2 text-xs rounded-md border border-border bg-muted/20 focus:outline-none focus:ring-1 focus:ring-foreground/30" })] }), _jsxs("div", { className: "space-y-1 max-h-[200px] overflow-y-auto pr-1", children: [filteredValues.map(val => {
150
150
  const isSelected = (tableFilters[colHeader] || []).includes(val);
151
151
  return (_jsxs("button", { onClick: () => handleToggleFilterValue(colHeader, val), className: "flex w-full items-center gap-2 px-2 py-1.5 text-sm rounded-sm hover:bg-muted transition-colors", children: [_jsx("div", { className: `flex h-4 w-4 items-center justify-center rounded-sm border`, style: isSelected ? { backgroundColor: 'hsl(var(--foreground))', borderColor: 'hsl(var(--foreground))', color: 'hsl(var(--background))' } : { borderColor: 'hsl(var(--border))' }, children: isSelected && _jsx(Check, { className: "h-3 w-3" }) }), _jsx("span", { className: "truncate text-left", children: val })] }, val));
152
- }), filteredValues.length === 0 && (_jsx("div", { className: "px-2 py-2 text-xs text-muted-foreground text-center", children: "No items found." }))] }), (tableFilters[colHeader] || []).length > 0 && (_jsx("div", { className: "px-2 pt-1 border-t", children: _jsx(Button, { variant: "ghost", size: "sm", className: "w-full text-xs", onClick: () => setTableFilters(prev => { const next = Object.assign({}, prev); delete next[colHeader]; return next; }), children: "Clear Selections" }) }))] })] }, colHeader));
152
+ }), filteredValues.length === 0 && (_jsx("div", { className: "px-2 py-2 text-xs text-muted-foreground text-center", children: "No items found." }))] }), (tableFilters[colHeader] || []).length > 0 && (_jsx("div", { className: "px-2 pt-1 border-t", children: _jsx(Button, { variant: "ghost", size: "sm", className: "w-full text-xs", onClick: () => {
153
+ const nextFilters = Object.assign({}, tableFilters);
154
+ delete nextFilters[colHeader];
155
+ setTableFilters(nextFilters);
156
+ onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(nextFilters);
157
+ }, children: "Clear Selections" }) }))] })] }, colHeader));
153
158
  }) })), _jsxs("div", { className: "w-full flex items-center gap-2 p-2 border border-dashed border-border rounded-lg bg-muted/20 min-h-[48px] transition-all hover:bg-muted/40 group shadow-sm", onDragOver: (e) => e.preventDefault(), onDrop: (e) => {
154
159
  e.preventDefault();
155
160
  const columnHeader = e.dataTransfer.getData("columnHeader");
@@ -30,4 +30,5 @@ export type ExtraPrams<T> = {
30
30
  onLoadMore?: () => void;
31
31
  hasMore?: boolean;
32
32
  onFilterChange?: (filters: Record<string, string[]>) => void;
33
+ unfilteredData?: T[];
33
34
  };