Skip to content

Commit

Permalink
chore: tmp of columns
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Aug 20, 2023
1 parent e2453e8 commit 278a471
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
14 changes: 13 additions & 1 deletion docs/examples/virtual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ const columns: ColumnsType = [
},
];

function cleanOnCell(cols: any = []) {
cols.forEach(col => {
delete (col as any).onCell;

cleanOnCell((col as any).children);
});
}
cleanOnCell(columns);

const data: RecordType[] = new Array(4 * 10000).fill(null).map((_, index) => ({
a: `a${index}`,
b: `b${index}`,
Expand Down Expand Up @@ -192,7 +201,10 @@ const Demo = () => {
scroll={{ x: 1200, y: scrollY ? 200 : null }}
data={data}
rowKey="indexKey"
expandable={{}}
expandable={{
expandedRowRender: () => 2333,
columnWidth: 60,
}}
/>
</div>
);
Expand Down
16 changes: 5 additions & 11 deletions src/Body/BodyRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useContext } from '@rc-component/context';
import classNames from 'classnames';
import * as React from 'react';
import Cell from '../Cell';
import TableContext, { responseImmutable } from '../context/TableContext';
import { responseImmutable } from '../context/TableContext';
import devRenderTimes from '../hooks/useRenderTimes';
import type { ColumnType, CustomizeComponent, GetComponentProps, GetRowKey } from '../interface';
import ExpandedRow from './ExpandedRow';
Expand Down Expand Up @@ -110,20 +109,18 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
const {
prefixCls,
flattenColumns,
expandableType,
expandRowByClick,
onTriggerExpand,
rowClassName,
expandedRowClassName,
expandedRowRender,

// Misc
nestExpandable,
expanded,
supportExpand,
expandable,
} = rowInfo;

const { rowExpandable } = useContext(TableContext, ['rowExpandable']);

const [expandRended, setExpandRended] = React.useState(false);

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -136,14 +133,11 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
}
}, [expanded]);

const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
const mergedExpandable = rowSupportExpand || nestExpandable;

// =========================== onRow ===========================
const additionalProps = onRow?.(record, index);

const onClick: React.MouseEventHandler<HTMLElement> = (event, ...args) => {
if (expandRowByClick && mergedExpandable) {
if (expandRowByClick && expandable) {
onTriggerExpand(record, event);
}

Expand Down Expand Up @@ -212,7 +206,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(

// ======================== Expand Row =========================
let expandRowNode: React.ReactElement;
if (rowSupportExpand && (expandRended || expanded)) {
if (supportExpand && (expandRended || expanded)) {
const expandContent = expandedRowRender(record, index, indent + 1, expanded);
const computedExpandedRowClassName =
expandedRowClassName && expandedRowClassName(record, index, indent);
Expand Down
1 change: 1 addition & 0 deletions src/StaticTable/BodyGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
() => columnsWidth.map(colWidth => colWidth[2]),
[columnsWidth],
);
console.log('~~~~>', flattenColumns, columnsWidth);

React.useEffect(() => {
columnsWidth.forEach(([key, width]) => {
Expand Down
1 change: 0 additions & 1 deletion src/StaticTable/BodyLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
const rowInfo = useRowInfo(record, rowKey);

// ========================== Expand ==========================
const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));

// ========================== Render ==========================

Expand Down
24 changes: 20 additions & 4 deletions src/hooks/useRowInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default function useRowInfo<RecordType>(
expanded: boolean;
hasNestChildren: boolean;
record: RecordType;
supportExpand: boolean;
expandable: boolean;
} {
const context: TableContextProps = useContext(TableContext, [
'prefixCls',
Expand All @@ -45,22 +47,34 @@ export default function useRowInfo<RecordType>(
'expandIconColumnIndex',
'expandedKeys',
'childrenColumnName',
'rowExpandable',
]);

const { flattenColumns, expandableType, expandedKeys, childrenColumnName, onTriggerExpand } =
context;

const columnsKey = getColumnsKey(flattenColumns);
const {
flattenColumns,
expandableType,
expandedKeys,
childrenColumnName,
onTriggerExpand,
rowExpandable,
} = context;

// ======================= Expandable =======================
// Only when row is not expandable and `children` exist in record
const nestExpandable = expandableType === 'nest';

const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
const mergedExpandable = rowSupportExpand || nestExpandable;

const expanded = expandedKeys && expandedKeys.has(rowKey);

const hasNestChildren = childrenColumnName && record && record[childrenColumnName];

const onInternalTriggerExpand = useEvent(onTriggerExpand);

// ========================= Column =========================
const columnsKey = getColumnsKey(flattenColumns);

return {
...context,
columnsKey,
Expand All @@ -69,5 +83,7 @@ export default function useRowInfo<RecordType>(
hasNestChildren,
record,
onTriggerExpand: onInternalTriggerExpand,
supportExpand: rowSupportExpand,
expandable: mergedExpandable,
};
}

0 comments on commit 278a471

Please sign in to comment.