|
|
@@ -1,75 +1,86 @@
|
|
|
import {useSortable} from '@dnd-kit/sortable';
|
|
|
-import {Cell, flexRender} from '@tanstack/react-table';
|
|
|
+import {Row, flexRender} from '@tanstack/react-table';
|
|
|
import classNames from 'classnames';
|
|
|
-import {CSSProperties, FC} from 'react';
|
|
|
+import {CSSProperties, FC, ReactNode} from 'react';
|
|
|
|
|
|
type Props = {
|
|
|
- getVisibleCells: () => Cell<Record<string, any>, unknown>[],
|
|
|
- id: string,
|
|
|
highlight?: boolean,
|
|
|
enableDnd?: boolean,
|
|
|
preview?: boolean,
|
|
|
+ row: Row<Record<string, any>>,
|
|
|
+ renderSubComponent?: (row: Row<Record<string, any>>) => ReactNode;
|
|
|
};
|
|
|
|
|
|
const BodyTr: FC<Props> = function({
|
|
|
- getVisibleCells,
|
|
|
+ row,
|
|
|
highlight,
|
|
|
- id,
|
|
|
enableDnd,
|
|
|
preview,
|
|
|
+ renderSubComponent,
|
|
|
}) {
|
|
|
- const trList = getVisibleCells();
|
|
|
+ const trList = row.getVisibleCells();
|
|
|
const {setNodeRef, listeners, attributes} = useSortable({
|
|
|
- id,
|
|
|
+ id: row.id,
|
|
|
disabled: !enableDnd,
|
|
|
data: {
|
|
|
- getVisibleCells,
|
|
|
- id,
|
|
|
+ row,
|
|
|
},
|
|
|
});
|
|
|
|
|
|
return (
|
|
|
- <tr
|
|
|
- ref={setNodeRef}
|
|
|
- {...listeners}
|
|
|
- {...attributes}
|
|
|
- style={{cursor: enableDnd || preview ? 'move' : 'auto'}}
|
|
|
- className={classNames('ld-table-body-tr ', {
|
|
|
- 'ld-table-tr-highlight': highlight,
|
|
|
- 'ld-table-tr-preview': preview,
|
|
|
- })}
|
|
|
- >
|
|
|
- {trList.map(function({
|
|
|
- id,
|
|
|
- column,
|
|
|
- getContext,
|
|
|
- }) {
|
|
|
- const {align, fixed, fixedStyle} = column.columnDef.meta as {
|
|
|
- align?: 'left' | 'center' | 'right';
|
|
|
- fixed?: 'right' | 'left';
|
|
|
- fixedStyle: CSSProperties,
|
|
|
- };
|
|
|
- return (
|
|
|
- <td
|
|
|
- key={id}
|
|
|
- className={classNames({
|
|
|
- 'ld-table-fixed-right ld-table-right-fixed-shadow': fixed === 'right',
|
|
|
- 'ld-table-fixed-left ld-table-left-fixed-shadow': fixed === 'left',
|
|
|
- })}
|
|
|
- style={{
|
|
|
- width: column.getSize(),
|
|
|
- textAlign: align ?? 'left',
|
|
|
- ...fixedStyle,
|
|
|
- }}
|
|
|
- >
|
|
|
- {flexRender(
|
|
|
- column.columnDef.cell,
|
|
|
- getContext(),
|
|
|
- )}
|
|
|
- </td>
|
|
|
- );
|
|
|
- })}
|
|
|
- </tr>
|
|
|
+ <>
|
|
|
+ <tr
|
|
|
+ ref={setNodeRef}
|
|
|
+ {...listeners}
|
|
|
+ {...attributes}
|
|
|
+ style={{cursor: enableDnd || preview ? 'move' : 'auto'}}
|
|
|
+ className={classNames('ld-table-body-tr ', {
|
|
|
+ 'ld-table-tr-highlight': highlight,
|
|
|
+ 'ld-table-tr-preview': preview,
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {trList.map(function({
|
|
|
+ id,
|
|
|
+ column,
|
|
|
+ getContext,
|
|
|
+ }) {
|
|
|
+ const {align, fixed, fixedStyle} = column.columnDef.meta as {
|
|
|
+ align?: 'left' | 'center' | 'right';
|
|
|
+ fixed?: 'right' | 'left';
|
|
|
+ fixedStyle: CSSProperties,
|
|
|
+ };
|
|
|
+ return (
|
|
|
+ <td
|
|
|
+ key={id}
|
|
|
+ className={classNames({
|
|
|
+ 'ld-table-fixed-right ld-table-right-fixed-shadow': fixed === 'right',
|
|
|
+ 'ld-table-fixed-left ld-table-left-fixed-shadow': fixed === 'left',
|
|
|
+ })}
|
|
|
+ style={{
|
|
|
+ width: column.getSize(),
|
|
|
+ textAlign: align ?? 'left',
|
|
|
+ ...fixedStyle,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {flexRender(
|
|
|
+ column.columnDef.cell,
|
|
|
+ getContext(),
|
|
|
+ )}
|
|
|
+ </td>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </tr>
|
|
|
+
|
|
|
+ {row.getIsExpanded() && Boolean(renderSubComponent)
|
|
|
+ ? (
|
|
|
+ <tr className="ld-table-body-tr">
|
|
|
+ <td colSpan={row.getVisibleCells().length}>
|
|
|
+ {renderSubComponent?.(row)}
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ )
|
|
|
+ : null}
|
|
|
+ </>
|
|
|
);
|
|
|
};
|
|
|
|