Created
November 12, 2019 16:01
-
-
Save twheys/c8c6cb8415eede3e5ec277b07d4aa485 to your computer and use it in GitHub Desktop.
react-table 7.0.0-beta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PropTypes from 'prop-types'; | |
const propTypes = {}; | |
export const useFlexLayout = hooks => { | |
hooks.useMain.push(useMain); | |
}; | |
useFlexLayout.pluginName = 'useFlexLayout'; | |
const useMain = instance => { | |
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useFlexLayout'); | |
const { | |
hooks: {getRowProps, getHeaderGroupProps, getHeaderProps, getCellProps}, | |
} = instance; | |
const rowStyles = { | |
style: { | |
display: 'flex', | |
}, | |
}; | |
getRowProps.push(() => rowStyles); | |
getHeaderGroupProps.push(() => rowStyles); | |
const cellStyles = { | |
display: 'inline-block', | |
boxSizing: 'border-box', | |
}; | |
getHeaderProps.push(header => ({ | |
style: { | |
...cellStyles, | |
flexBasis: `${header.width}px`, | |
flexGrow: header.flexGrow ? 1 : 0, | |
flexShrink: header.flexShrink ? 1 : 0, | |
} | |
})); | |
getCellProps.push(cell => ({ | |
style: { | |
...cellStyles, | |
flexBasis: `${cell.column.width}px`, | |
flexGrow: cell.column.flexGrow ? 1 : 0, | |
flexShrink: cell.column.flexShrink ? 1 : 0, | |
}, | |
}) | |
); | |
return instance; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment