UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

70 lines (62 loc) 2.31 kB
import React, { useCallback, useContext } from 'react'; import isFunction from 'lodash/isFunction'; import TableContext from './TableContext'; import { DragColumnAlign } from './enum'; import TableRow from './TableRow'; import { isDraggingStyle, isStickySupport } from './utils'; export function useRenderClone(columnGroups) { var _useContext = useContext(TableContext), tableStore = _useContext.tableStore, dataSet = _useContext.dataSet, rowDragRender = _useContext.rowDragRender, prefixCls = _useContext.prefixCls; return useCallback(function (provided, snapshot, rubric) { if (!isStickySupport() && snapshot.isDragging && tableStore.overflowX && tableStore.dragColumnAlign === DragColumnAlign.right) { var style = provided.draggableProps.style; if (isDraggingStyle(style)) { var left = style.left, width = style.width; style.left = left - Math.max(tableStore.columnGroups.leafColumnsWidth - tableStore.columnGroups.rightLeafColumnsWidth, width); } } var record = dataSet.find(function (record) { return String(record.key) === rubric.draggableId; }); if (record) { var leafColumnsBody = columnGroups || tableStore.columnGroups; var renderClone = rowDragRender && rowDragRender.renderClone; var id = record.id; if (renderClone && isFunction(renderClone)) { return renderClone({ provided: provided, snapshot: snapshot, rubric: rubric, key: id, hidden: false, lock: false, prefixCls: prefixCls, columns: leafColumnsBody.leafs.map(function (_ref) { var column = _ref.column; return column; }), columnGroups: leafColumnsBody, record: record, index: 0 }); } return /*#__PURE__*/React.createElement(TableRow, { provided: provided, snapshot: snapshot, key: id, hidden: false, lock: false, columnGroups: leafColumnsBody, record: record, index: id, className: "dragging-row" }); } return /*#__PURE__*/React.createElement("span", null); }, [tableStore, dataSet, rowDragRender, columnGroups]); } //# sourceMappingURL=hooks.js.map