mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
import { ensurePluginOrder } from '../utils'
|
|
|
|
const cellStyles = {
|
|
position: 'absolute',
|
|
top: 0,
|
|
}
|
|
|
|
export const useAbsoluteLayout = hooks => {
|
|
hooks.getTableBodyProps.push(getRowStyles)
|
|
hooks.getRowProps.push(getRowStyles)
|
|
hooks.getHeaderGroupProps.push(getRowStyles)
|
|
hooks.useInstance.push(useInstance)
|
|
|
|
hooks.getHeaderProps.push((props, instance, header) => [
|
|
props,
|
|
{
|
|
style: {
|
|
...cellStyles,
|
|
left: `${header.totalLeft}px`,
|
|
width: `${header.totalWidth}px`,
|
|
},
|
|
},
|
|
])
|
|
|
|
hooks.getCellProps.push((props, instance, cell) => [
|
|
props,
|
|
{
|
|
style: {
|
|
...cellStyles,
|
|
left: `${cell.column.totalLeft}px`,
|
|
width: `${cell.column.totalWidth}px`,
|
|
},
|
|
},
|
|
])
|
|
}
|
|
|
|
useAbsoluteLayout.pluginName = 'useAbsoluteLayout'
|
|
|
|
const getRowStyles = (props, instance) => [
|
|
props,
|
|
{
|
|
style: {
|
|
position: 'relative',
|
|
width: `${instance.totalColumnsWidth}px`,
|
|
},
|
|
},
|
|
]
|
|
|
|
function useInstance({ plugins }) {
|
|
ensurePluginOrder(plugins, [], useAbsoluteLayout.pluginName, [
|
|
'useResizeColumns',
|
|
])
|
|
}
|