@lifhcp/rc-grid
Advanced tools
Comparing version 1.0.1 to 1.1.1
@@ -65,3 +65,3 @@ "use strict"; | ||
var GridContainer = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative;\n"], ["\n position: relative;\n"]))); | ||
var Grid = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: relative;\n overflow: auto;\n border: 1px solid #ddd;\n outline: none;\n"], ["\n position: relative;\n overflow: auto;\n border: 1px solid #ddd;\n outline: none;\n"]))); | ||
var Grid = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: relative;\n overflow: auto;\n scroll-behavior: smooth;\n border: 1px solid #ddd;\n outline: none;\n"], ["\n position: relative;\n overflow: auto;\n scroll-behavior: smooth;\n border: 1px solid #ddd;\n outline: none;\n"]))); | ||
var ExpandableIcon = styled_components_1.default.i(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 16px;\n height: 16px;\n cursor: pointer;\n"], ["\n width: 16px;\n height: 16px;\n cursor: pointer;\n"]))); | ||
@@ -99,3 +99,3 @@ function useExpandableRender(row, isExpandable) { | ||
function DataGrid(props) { | ||
var className = props.className, _a = props.style, style = _a === void 0 ? {} : _a, rows = props.rows, height = props.height, width = props.width, columns = props.columns, estimatedRowHeight = props.estimatedRowHeight, estimatedColumnWidth = props.estimatedColumnWidth, headerRowHeight = props.headerRowHeight, cacheRemoveCount = props.cacheRemoveCount, defaultColumnWidth = props.defaultColumnWidth, expandable = props.expandable, select = props.select, selectedRows = props.selectedRows, onChangeSelectedRows = props.onChangeSelectedRows, onEmptyRowsRenderer = props.onEmptyRowsRenderer, _b = props.onHeaderRowRender, onHeaderRowRender = _b === void 0 ? function (node) { return node; } : _b, onChildrenRows = props.onChildrenRows; | ||
var className = props.className, _a = props.style, style = _a === void 0 ? {} : _a, rows = props.rows, height = props.height, width = props.width, columns = props.columns, estimatedRowHeight = props.estimatedRowHeight, estimatedColumnWidth = props.estimatedColumnWidth, headerRowHeight = props.headerRowHeight, cacheRemoveCount = props.cacheRemoveCount, defaultColumnWidth = props.defaultColumnWidth, expandable = props.expandable, select = props.select, selectedRows = props.selectedRows, onChangeSelectedRows = props.onChangeSelectedRows, onEmptyRowsRenderer = props.onEmptyRowsRenderer, _b = props.onHeaderRowRender, onHeaderRowRender = _b === void 0 ? function (node) { return node; } : _b, onChildrenRows = props.onChildrenRows, grid = props.grid; | ||
var _c = react_1.useReducer(Context_1.reducer, { | ||
@@ -318,2 +318,53 @@ editorChange: [], | ||
]); | ||
var scrollRow = function (row) { | ||
var tempScrollTop = 0; | ||
filterRows.some(function (data, index) { | ||
if (index === row) { | ||
return true; | ||
} | ||
tempScrollTop += data.height; | ||
return false; | ||
}); | ||
gridRef.current.scrollTo({ | ||
top: tempScrollTop | ||
}); | ||
}; | ||
var scrollCol = function (colIdx) { | ||
var tempScrollLeft = 0; | ||
sortColumns.some(function (data, index) { | ||
if (index === colIdx) { | ||
return true; | ||
} | ||
tempScrollLeft += data.width || defaultColumnWidth; | ||
return false; | ||
}); | ||
gridRef.current.scrollTo({ | ||
left: tempScrollLeft | ||
}); | ||
}; | ||
react_1.useLayoutEffect(function () { | ||
if (grid) { | ||
grid.current = { | ||
element: gridRef.current, | ||
scrollToRow: scrollRow, | ||
scrollToColumn: scrollCol, | ||
selectCell: function (position, enableEditor) { | ||
var index = filterRows.findIndex(function (ele) { return ele.key === position.rowKey; }); | ||
dispatch({ | ||
type: 'setSelectPosition', | ||
payload: { | ||
x: index, | ||
y: position.colName | ||
} | ||
}); | ||
if (enableEditor) { | ||
dispatch({ | ||
type: 'setEditPosition', | ||
payload: position | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}, [sortColumns, filterRows]); | ||
var lastScrollTop = react_1.useRef(0); | ||
@@ -320,0 +371,0 @@ var lastScrollLeft = react_1.useRef(0); |
import DataGrid from './DataGrid'; | ||
import AutoSize from './AutoSize'; | ||
export type { Row, Column, Cell, EditorProps, DataGridProps } from './types'; | ||
export type { Row, Column, Cell, EditorProps, DataGridProps, GridHandle } from './types'; | ||
export { AutoSize }; | ||
export default DataGrid; |
@@ -46,3 +46,8 @@ "use strict"; | ||
style: props.styled, | ||
}); })(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n background-color: #fff;\n :hover {\n background-color: hsl(0deg 0% 96%);\n }\n"], ["\n position: absolute;\n background-color: #fff;\n :hover {\n background-color: hsl(0deg 0% 96%);\n }\n"]))); | ||
}); })(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n background-color: ", ";\n :hover {\n background-color: hsl(0deg 0% 96%);\n }\n"], ["\n position: absolute;\n background-color: ", ";\n :hover {\n background-color: hsl(0deg 0% 96%);\n }\n"])), function (props) { | ||
if (props.isSelect) { | ||
return 'hsl(0deg 0% 96%)'; | ||
} | ||
return '#fff'; | ||
}); | ||
function Row(_a) { | ||
@@ -161,3 +166,3 @@ var rows = _a.rows, rowIndex = _a.rowIndex, scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth, _b = _a.styled, tempStyled = _b === void 0 ? {} : _b, rowIndexCode = _a.rowIndexCode, level = _a.level, gridProps = _a.gridProps; | ||
]); | ||
return (react_1.default.createElement(GridRow, { styled: tempStyled, onClick: function () { | ||
return (react_1.default.createElement(GridRow, { styled: tempStyled, isSelect: gridProps.selectedRows.includes(key), onClick: function () { | ||
onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(rows[rowIndex]); | ||
@@ -164,0 +169,0 @@ }, onDoubleClick: function () { |
@@ -1,2 +0,2 @@ | ||
import { ComponentType, CSSProperties, HTMLAttributes, ReactNode, DragEvent, Key } from 'react'; | ||
import { ComponentType, CSSProperties, HTMLAttributes, ReactNode, DragEvent, Key, MutableRefObject } from 'react'; | ||
declare type SharedDivProps = Pick<HTMLAttributes<HTMLDivElement>, 'className' | 'style'>; | ||
@@ -14,2 +14,15 @@ declare type SortDirection = 'ASC' | 'DESC'; | ||
}; | ||
export interface GridHandle { | ||
/** HTML 元素 */ | ||
element: HTMLDivElement | null; | ||
/** 滚动到指定的列 */ | ||
scrollToColumn: (colIdx: number) => void; | ||
/** 滚动到指定的行 */ | ||
scrollToRow: (rowIdx: number) => void; | ||
/** 选中 */ | ||
selectCell: (position: { | ||
rowKey?: string; | ||
colName?: string; | ||
}, enableEditor?: boolean | null) => void; | ||
} | ||
export interface DataGridProps<R> extends SharedDivProps { | ||
@@ -34,2 +47,4 @@ /** 表格的行数据信息 */ | ||
defaultColumnWidth?: number; | ||
/** 表格的方法 */ | ||
grid?: MutableRefObject<GridHandle | null>; | ||
/** 选中的配置信息 */ | ||
@@ -36,0 +51,0 @@ select?: { |
{ | ||
"name": "@lifhcp/rc-grid", | ||
"version": "1.0.1", | ||
"version": "1.1.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86104
1717