Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TableBody] Add new property: stripedRowsStyles #5325

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 9 additions & 2 deletions src/Table/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class TableBody extends Component {
* with the first row will be striped. The default value is false.
*/
stripedRows: PropTypes.bool,
/**
* Additional styles for stripped rows.
*/
stripedRowsStyle: PropTypes.object,
/**
* Override the inline-styles of the root element.
*/
Expand All @@ -113,6 +117,7 @@ class TableBody extends Component {
multiSelectable: false,
preScanRows: true,
selectable: true,
stripedRowsStyle: {},
style: {},
};

Expand Down Expand Up @@ -171,6 +176,8 @@ class TableBody extends Component {
hoverable: this.props.showRowHover,
selected: this.isRowSelected(rowNumber),
striped: this.props.stripedRows && (rowNumber % 2 === 0),
strippedStyle: this.props.stripedRows && this.props.stripedRowsStyle && (rowNumber % 2 === 0) ?
this.props.stripedRowsStyle : {},
rowNumber: rowNumber++,
};

Expand Down Expand Up @@ -408,14 +415,14 @@ class TableBody extends Component {
const {
className,
style,
} = this.props;
} = this.props;

const {prepareStyles} = this.context.muiTheme;

return (
<ClickAwayListener onClickAway={this.handleClickAway}>
<tbody className={className} style={prepareStyles(Object.assign({}, style))}>
{this.createRows()}
{this.createRows()}
</tbody>
</ClickAwayListener>
);
Expand Down
10 changes: 6 additions & 4 deletions src/Table/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ function getStyles(props, context, state) {
cellBgColor = tableRow.stripeColor;
}

const cellStyle = {
backgroundColor: cellBgColor,
};

return {
root: {
borderBottom: props.displayBorder && `1px solid ${tableRow.borderColor}`,
color: tableRow.textColor,
height: tableRow.height,
},
cell: {
backgroundColor: cellBgColor,
},
cell: props.striped && props.strippedStyle ? Object.assign(cellStyle, props.strippedStyle) : cellStyle,
};
}

Expand Down Expand Up @@ -185,7 +187,7 @@ class TableRow extends Component {
striped, // eslint-disable-line no-unused-vars
style,
...other,
} = this.props;
} = this.props;

const {prepareStyles} = this.context.muiTheme;
const styles = getStyles(this.props, this.context, this.state);
Expand Down