Files
react-table/src/plugin-hooks/useAbsoluteLayout.js
T
tannerlinsley 247687ee08 feat: ingested width logic, useAbsoluteLayout useBlockLayout
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.
2019-10-01 14:03:11 -06:00

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
}