-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce renderThChildren table plugin [#159899107]
Signed-off-by: Ming Xiao <mxiao@pivotal.io>
- Loading branch information
1 parent
62310d6
commit 0ab59be
Showing
3 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
spec/pivotal-ui-react/table/plugins/render-th-children_spec.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import '../../spec_helper'; | ||
import {Table, withRenderThChildren} from '../../../../src/react/table'; | ||
|
||
describe('withRenderThChildren', () => { | ||
let data; | ||
|
||
beforeEach(() => { | ||
const columns = [ | ||
{attribute: 'attr1', renderThChildren: () => (<div className="custom">some header</div>)}, | ||
{attribute: 'attr2', displayName: 'Attr2'} | ||
]; | ||
|
||
data = [{ | ||
attr1: 'row1-value1', | ||
attr2: 'row1-value2' | ||
}]; | ||
|
||
const ComposedTable = withRenderThChildren(Table); | ||
ReactDOM.render(<ComposedTable {...{columns, data}}/>, root); | ||
}); | ||
|
||
it('renders the correct header', () => { | ||
expect('table thead th:eq(0) .custom').toHaveText('some header'); | ||
expect('table thead th:eq(1)').toHaveText('Attr2'); | ||
}); | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
import {TablePlugin} from '../table-plugin'; | ||
|
||
export function withRenderThChildren(Table) { | ||
return class TableWithRenderTdChildren extends TablePlugin { | ||
render() { | ||
return this.renderTable(Table, { | ||
th: (props, {column: {renderThChildren}}) => { | ||
if (!renderThChildren) return; | ||
return {children: renderThChildren()}; | ||
} | ||
}); | ||
} | ||
}; | ||
} |