react-table
Version:
Hooks for building lightweight, fast and extendable datagrids for React
53 lines (46 loc) • 974 B
JavaScript
const cellStyles = {
display: 'inline-block',
boxSizing: 'border-box',
}
const getRowStyles = (props, { instance }) => [
props,
{
style: {
display: 'flex',
width: `${instance.totalColumnsWidth}px`,
},
},
]
export const useBlockLayout = hooks => {
hooks.getRowProps.push(getRowStyles)
hooks.getHeaderGroupProps.push(getRowStyles)
hooks.getFooterGroupProps.push(getRowStyles)
hooks.getHeaderProps.push((props, { column }) => [
props,
{
style: {
...cellStyles,
width: `${column.totalWidth}px`,
},
},
])
hooks.getCellProps.push((props, { cell }) => [
props,
{
style: {
...cellStyles,
width: `${cell.column.totalWidth}px`,
},
},
])
hooks.getFooterProps.push((props, { column }) => [
props,
{
style: {
...cellStyles,
width: `${column.totalWidth}px`,
},
},
])
}
useBlockLayout.pluginName = 'useBlockLayout'