Skip to content

Instantly share code, notes, and snippets.

@twheys
Created November 12, 2019 16:01
Show Gist options
  • Save twheys/c8c6cb8415eede3e5ec277b07d4aa485 to your computer and use it in GitHub Desktop.
Save twheys/c8c6cb8415eede3e5ec277b07d4aa485 to your computer and use it in GitHub Desktop.
react-table 7.0.0-beta
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