mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-20 08:50:19 +00:00
Width options (`width`, `minWidth`, `maxWidth`) options are now a part of the core column object. useBlockLayout and useAbsoluteLayout hooks now use this new internalized information to implement their layouts. Those examples have been updated. A virtualized-rows example has also been added to show off how the useBlockLayout hook can be used to virtualize rows with react-window.
64 lines
1.2 KiB
JavaScript
64 lines
1.2 KiB
JavaScript
import PropTypes from 'prop-types'
|
|
|
|
const propTypes = {}
|
|
|
|
export const useAbsoluteLayout = hooks => {
|
|
hooks.useMain.push(useMain)
|
|
}
|
|
|
|
useAbsoluteLayout.pluginName = 'useAbsoluteLayout'
|
|
|
|
const useMain = instance => {
|
|
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useAbsoluteLayout')
|
|
|
|
const {
|
|
totalColumnsWidth,
|
|
hooks: {
|
|
getRowProps,
|
|
getTableBodyProps,
|
|
getHeaderGroupProps,
|
|
getHeaderProps,
|
|
getCellProps,
|
|
},
|
|
} = instance
|
|
|
|
const rowStyles = {
|
|
style: {
|
|
position: 'relative',
|
|
width: `${totalColumnsWidth}px`,
|
|
},
|
|
}
|
|
|
|
getTableBodyProps.push(() => rowStyles)
|
|
getRowProps.push(() => rowStyles)
|
|
getHeaderGroupProps.push(() => rowStyles)
|
|
|
|
// Calculating column/cells widths
|
|
const cellStyles = {
|
|
position: 'absolute',
|
|
top: 0,
|
|
}
|
|
|
|
getHeaderProps.push(header => {
|
|
return {
|
|
style: {
|
|
...cellStyles,
|
|
left: `${header.totalLeft}px`,
|
|
width: `${header.totalWidth}px`,
|
|
},
|
|
}
|
|
})
|
|
|
|
getCellProps.push(cell => {
|
|
return {
|
|
style: {
|
|
...cellStyles,
|
|
left: `${cell.column.totalLeft}px`,
|
|
width: `${cell.column.totalWidth}px`,
|
|
},
|
|
}
|
|
})
|
|
|
|
return instance
|
|
}
|