@yusufalperendumlu/component-library 0.1.3 → 0.1.5

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
@@ -65,13 +65,15 @@ type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
65
65
 
66
66
  declare const Input: React$1.FC<InputProps>;
67
67
 
68
+ interface TableColumn<T> {
69
+ key: keyof T;
70
+ label: string;
71
+ sortable?: boolean;
72
+ render?: (value: any, row: T) => React.ReactNode;
73
+ sortFn?: (a: T, b: T) => number;
74
+ }
68
75
  interface TableProps<T> {
69
- columns: {
70
- key: keyof T;
71
- label: string;
72
- sortable: boolean;
73
- render?: (value: any, row: T) => React.ReactNode;
74
- }[];
76
+ columns: TableColumn<T>[];
75
77
  data: T[];
76
78
  onRowClick?: (row: T) => void;
77
79
  className?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yusufalperendumlu/component-library",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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,18 +3,15 @@ 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> {
9
- columns: {
10
- key: keyof T;
11
- label: string;
12
- sortable: boolean;
13
- render?: (value: any, row: T) => React.ReactNode;
14
- }[];
10
+ columns: TableColumn<T>[];
15
11
  data: T[];
16
12
  onRowClick?: (row: T) => void;
17
13
  className?: string;
18
14
  selectedRowId?: string | number | null;
19
- rowIdKey?: keyof T;
15
+ rowIdKey?: keyof T;
20
16
  }
17
+