Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Allow styles to be passed to the container div #5

Merged
merged 3 commits into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ All passed props will be passed to the underlying FixedDataTable component. Plea
Width and height will be overriden to take all the available space of its parent container.

### Additional configuration
**containerStyle** *{Object}*: Additional styles to be set on the container div.
**refreshRate** *{Number}*: Time in milliseconds to debounce the resize handler.
14 changes: 11 additions & 3 deletions src/responsive-fixed-data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ var React = require('react/addons');
var PureRenderMixin = React.addons.PureRenderMixin;
var Table = require('fixed-data-table').Table;
var debounce = require('debounce');
var assign = require('react/lib/Object.assign');

var ResponsiveFixedDataTable = React.createClass({
mixins: [ PureRenderMixin ],

propTypes: {
containerStyle: React.PropTypes.object,
refreshRate: React.PropTypes.number
},

getDefaultProps: function() {
return {
containerStyle: {},
refreshRate: 250 // ms
};
},
Expand Down Expand Up @@ -60,14 +63,19 @@ var ResponsiveFixedDataTable = React.createClass({
}
},

_getStyle: function() {
return assign(this.props.containerStyle, {
width: '100%',
height: '100%'
});
},

/**
* @return {ReactDOMNode}
*/
render: function() {
var wrapperStyle = { width: '100%', height: '100%' };

return (
<div style={wrapperStyle}>
<div style={this._getStyle()}>
<Table {...this.props} ref='table' width={this.state.gridWidth} height={this.state.gridHeight} />
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions test/specs/responsive-fixed-data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('responsive-fixed-data-table', function() {
beforeEach(function() {
var props = {
foo: 'bar',
containerStyle: { width: '20%', position: 'absolute' },
rowGetter: function() {},
rowHeight: 1,
rowsCount: 1,
Expand All @@ -33,6 +34,11 @@ describe('responsive-fixed-data-table', function() {
expect(tableNode.style.height).toBe('100%');
});

it('should accept additional styles', function() {
var tableNode = table.getDOMNode();
expect(tableNode.style.position).toBe('absolute');
});

it('should transfer props and add width and height', function() {
var tableState = table.state;
var fixedDataTable = table.refs.table
Expand Down