Install useSimpleLayout and adjust useTable and useRows as required.

This commit is contained in:
Gary Menzel
2019-04-28 19:10:22 +09:00
parent 8c81a31aa6
commit 834ab4b4a7
5 changed files with 42 additions and 3 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -26,6 +26,7 @@ export const useRows = props => {
const row = {
original,
index: i,
path: [i],
subRows,
depth,
cells: [{}] // This is a dummy cell

View File

@@ -0,0 +1,38 @@
export const useSimpleLayout = props => {
const {
hooks: {
columns: columnsHooks,
getHeaderProps,
getCellProps
}
} = props
columnsHooks.push((columns, api) => {
columns.filter(column => {
column.visible =
typeof column.show === 'function' ? column.show(api) : !!column.show
return column.visible
})
getHeaderProps.push(column => ({
style: {
boxSizing: 'border-box',
width: column.width !== undefined ? `${column.width}px` : 'auto'
}
}))
getCellProps.push(cell => {
return {
style: {
boxSizing: 'border-box',
width: cell.column.width !== undefined ? `${cell.column.width}px` : 'auto'
}
}
})
return columns
})
return props
}

View File

@@ -143,7 +143,7 @@ export const useTable = (props, ...plugins) => {
const { path } = row
row.getRowProps = props =>
mergeProps(
{ key: ['row', path].join('_') },
{ key: ['row', path.join('_')].join('_') },
applyHooks(api.hooks.getRowProps, row, api),
props
)