@yusufalperendumlu/component-library 0.1.3 → 0.1.4
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.d.ts
CHANGED
package/package.json
CHANGED
@@ -19,13 +19,21 @@ function Table<T extends Record<string, any>>({
|
|
19
19
|
const sortedData = useMemo(() => {
|
20
20
|
if (!sortKey) return data;
|
21
21
|
|
22
|
+
const column = columns.find(col => col.key === sortKey);
|
23
|
+
|
22
24
|
const sorted = [...data].sort((a, b) => {
|
25
|
+
if (column?.sortFn) {
|
26
|
+
const result = column.sortFn(a, b);
|
27
|
+
return sortOrder === 'asc' ? result : -result;
|
28
|
+
}
|
29
|
+
|
23
30
|
if (a[sortKey] < b[sortKey]) return sortOrder === 'asc' ? -1 : 1;
|
24
31
|
if (a[sortKey] > b[sortKey]) return sortOrder === 'asc' ? 1 : -1;
|
25
32
|
return 0;
|
26
33
|
});
|
34
|
+
|
27
35
|
return sorted;
|
28
|
-
}, [data, sortKey, sortOrder]);
|
36
|
+
}, [data, sortKey, sortOrder, columns]);
|
29
37
|
|
30
38
|
const handleSort = (key: keyof T, sortable?: boolean) => {
|
31
39
|
if (!sortable) return;
|
@@ -3,6 +3,7 @@ export interface TableColumn<T> {
|
|
3
3
|
label: string;
|
4
4
|
sortable?: boolean;
|
5
5
|
render?: (value: any, row: T) => React.ReactNode;
|
6
|
+
sortFn?: (a: T, b: T) => number;
|
6
7
|
}
|
7
8
|
|
8
9
|
export interface TableProps<T> {
|
@@ -11,6 +12,7 @@ export interface TableProps<T> {
|
|
11
12
|
label: string;
|
12
13
|
sortable: boolean;
|
13
14
|
render?: (value: any, row: T) => React.ReactNode;
|
15
|
+
sortFn?: (a: T, b: T) => number;
|
14
16
|
}[];
|
15
17
|
data: T[];
|
16
18
|
onRowClick?: (row: T) => void;
|