Skip to content

Commit 0ab59be

Browse files
sweinstein22Ming Xiao
authored andcommitted
Introduce renderThChildren table plugin [#159899107]
Signed-off-by: Ming Xiao <mxiao@pivotal.io>
1 parent 62310d6 commit 0ab59be

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import '../../spec_helper';
2+
import {Table, withRenderThChildren} from '../../../../src/react/table';
3+
4+
describe('withRenderThChildren', () => {
5+
let data;
6+
7+
beforeEach(() => {
8+
const columns = [
9+
{attribute: 'attr1', renderThChildren: () => (<div className="custom">some header</div>)},
10+
{attribute: 'attr2', displayName: 'Attr2'}
11+
];
12+
13+
data = [{
14+
attr1: 'row1-value1',
15+
attr2: 'row1-value2'
16+
}];
17+
18+
const ComposedTable = withRenderThChildren(Table);
19+
ReactDOM.render(<ComposedTable {...{columns, data}}/>, root);
20+
});
21+
22+
it('renders the correct header', () => {
23+
expect('table thead th:eq(0) .custom').toHaveText('some header');
24+
expect('table thead th:eq(1)').toHaveText('Attr2');
25+
});
26+
});

src/react/table/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import {withCellEllipsis} from './plugins/cell-ellipsis';
66
import {withCellLink} from './plugins/cell-link';
77
import {withCellOnClick} from './plugins/cell-on-click';
88
import {withCellRenderer} from './plugins/cell-renderer';
9-
import {withRenderTdChildren} from './plugins/render-td-children';
109
import {withCellTooltip} from './plugins/cell-tooltip';
1110
import {withCellWidth} from './plugins/cell-width';
1211
import {withFlex} from './plugins/flex';
1312
import {withFooterRow} from './plugins/footer-row';
13+
import {withRenderTdChildren} from './plugins/render-td-children';
14+
import {withRenderThChildren} from './plugins/render-th-children';
1415
import {withRowClassName} from './plugins/row-class-name';
1516
import {withRowDrawer} from './plugins/row-drawer';
1617
import {withRowLink} from './plugins/row-link';
17-
import {withSorting} from './plugins/sorting';
1818
import {withScrollableTbody} from './plugins/scrollable-tbody';
19+
import {withSorting} from './plugins/sorting';
1920

2021
export {Table} from './table';
2122
export {TablePlugin} from './table-plugin';
@@ -25,16 +26,17 @@ export {withCellEllipsis} from './plugins/cell-ellipsis';
2526
export {withCellLink} from './plugins/cell-link';
2627
export {withCellOnClick} from './plugins/cell-on-click';
2728
export {withCellRenderer} from './plugins/cell-renderer';
28-
export {withRenderTdChildren} from './plugins/render-td-children';
2929
export {withCellTooltip} from './plugins/cell-tooltip';
3030
export {withCellWidth} from './plugins/cell-width';
3131
export {withFlex} from './plugins/flex';
3232
export {withFooterRow} from './plugins/footer-row';
33+
export {withRenderTdChildren} from './plugins/render-td-children';
34+
export {withRenderThChildren} from './plugins/render-th-children';
3335
export {withRowClassName} from './plugins/row-class-name';
3436
export {withRowDrawer} from './plugins/row-drawer';
3537
export {withRowLink} from './plugins/row-link';
36-
export {withSorting} from './plugins/sorting';
3738
export {withScrollableTbody} from './plugins/scrollable-tbody';
39+
export {withSorting} from './plugins/sorting';
3840

3941
export const SortableTable = withSorting(Table);
4042
export const FlexTable = withFlex(Table);
@@ -47,6 +49,7 @@ export const AdvancedTable = flow(
4749
withCellOnClick,
4850
withCellRenderer,
4951
withRenderTdChildren,
52+
withRenderThChildren,
5053
withCellTooltip,
5154
withCellWidth,
5255
withFooterRow,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
import {TablePlugin} from '../table-plugin';
4+
5+
export function withRenderThChildren(Table) {
6+
return class TableWithRenderTdChildren extends TablePlugin {
7+
render() {
8+
return this.renderTable(Table, {
9+
th: (props, {column: {renderThChildren}}) => {
10+
if (!renderThChildren) return;
11+
return {children: renderThChildren()};
12+
}
13+
});
14+
}
15+
};
16+
}

0 commit comments

Comments
 (0)