@yusufalperendumlu/component-library 0.0.18 → 0.0.20
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,20 +65,21 @@ 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
|
-
}
|
74
68
|
interface TableProps<T> {
|
75
|
-
columns:
|
69
|
+
columns: {
|
70
|
+
key: keyof T;
|
71
|
+
label: string;
|
72
|
+
sortable: boolean;
|
73
|
+
render?: (value: any, row: T) => React.ReactNode;
|
74
|
+
}[];
|
76
75
|
data: T[];
|
77
76
|
onRowClick?: (row: T) => void;
|
78
77
|
className?: string;
|
78
|
+
selectedRowId?: string | number | null;
|
79
|
+
rowIdKey?: keyof T;
|
79
80
|
}
|
80
81
|
|
81
|
-
declare function Table<T extends Record<string, any>>({ columns, data, onRowClick, className, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
82
|
+
declare function Table<T extends Record<string, any>>({ columns, data, onRowClick, className, selectedRowId, rowIdKey, }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
82
83
|
|
83
84
|
type ToastProps = {
|
84
85
|
title: string;
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import clsx from 'clsx';
|
2
|
-
import React, { useState } from 'react';
|
2
|
+
import React, { useState, useMemo } from 'react';
|
3
3
|
import { FaArrowDown, FaArrowUp } from 'react-icons/fa';
|
4
4
|
|
5
5
|
import { TableProps } from './Table.types';
|
@@ -9,12 +9,14 @@ function Table<T extends Record<string, any>>({
|
|
9
9
|
data,
|
10
10
|
onRowClick,
|
11
11
|
className,
|
12
|
+
selectedRowId,
|
13
|
+
rowIdKey = 'id',
|
12
14
|
}: TableProps<T>) {
|
13
15
|
const [sortKey, setSortKey] = useState<keyof T | null>(null);
|
14
16
|
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('asc');
|
15
17
|
const [selectedRowIndex, setSelectedRowIndex] = useState<number | null>(null);
|
16
18
|
|
17
|
-
const sortedData =
|
19
|
+
const sortedData = useMemo(() => {
|
18
20
|
if (!sortKey) return data;
|
19
21
|
|
20
22
|
const sorted = [...data].sort((a, b) => {
|
@@ -66,32 +68,39 @@ function Table<T extends Record<string, any>>({
|
|
66
68
|
</tr>
|
67
69
|
</thead>
|
68
70
|
<tbody>
|
69
|
-
{sortedData.map((row, idx) =>
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
71
|
+
{sortedData.map((row, idx) => {
|
72
|
+
const isSelected =
|
73
|
+
selectedRowId !== undefined &&
|
74
|
+
selectedRowId !== null &&
|
75
|
+
row[rowIdKey] === selectedRowId;
|
76
|
+
|
77
|
+
return (
|
78
|
+
<tr
|
79
|
+
key={idx}
|
80
|
+
onClick={() => {
|
81
|
+
setSelectedRowIndex(idx);
|
82
|
+
onRowClick?.(row);
|
83
|
+
}}
|
84
|
+
className={clsx(
|
85
|
+
isSelected
|
86
|
+
? 'bg-[#BDC311]'
|
87
|
+
: idx % 2 === 0
|
88
|
+
? 'bg-[#1D1B1D]'
|
89
|
+
: 'bg-[#424242]',
|
90
|
+
'cursor-pointer'
|
91
|
+
)}
|
92
|
+
>
|
93
|
+
{columns.map(({ key, render }) => (
|
94
|
+
<td
|
95
|
+
key={key as string}
|
96
|
+
className='whitespace-nowrap px-6 py-4'
|
97
|
+
>
|
98
|
+
{render ? render(row[key], row) : row[key]}
|
99
|
+
</td>
|
100
|
+
))}
|
101
|
+
</tr>
|
102
|
+
);
|
103
|
+
})}
|
95
104
|
</tbody>
|
96
105
|
</table>
|
97
106
|
</div>
|
@@ -6,8 +6,15 @@ export interface TableColumn<T> {
|
|
6
6
|
}
|
7
7
|
|
8
8
|
export interface TableProps<T> {
|
9
|
-
columns:
|
9
|
+
columns: {
|
10
|
+
key: keyof T;
|
11
|
+
label: string;
|
12
|
+
sortable: boolean;
|
13
|
+
render?: (value: any, row: T) => React.ReactNode;
|
14
|
+
}[];
|
10
15
|
data: T[];
|
11
16
|
onRowClick?: (row: T) => void;
|
12
17
|
className?: string;
|
18
|
+
selectedRowId?: string | number | null;
|
19
|
+
rowIdKey?: keyof T;
|
13
20
|
}
|