Skip to content

Commit 6b7d1f9

Browse files
authored
Allen/feature 9 (#10)
Fix #9
1 parent 5b7a891 commit 6b7d1f9

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"webpack-dev-server": "^2.7.1"
4646
},
4747
"dependencies": {
48+
"classnames": "^2.2.5",
4849
"prop-types": "^15.5.10",
4950
"react": "^15.6.1",
5051
"react-dom": "^15.6.1"

packages/react-bootstrap-table2/src/bootstrap-table.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3+
import cs from 'classnames';
34

45
import Header from './header';
56
import Body from './body';
@@ -12,10 +13,25 @@ class BootstrapTable extends storeBase(Component) {
1213
}
1314

1415
render() {
15-
const { columns, keyField } = this.props;
16+
const {
17+
columns,
18+
keyField,
19+
striped,
20+
hover,
21+
bordered,
22+
condensed
23+
} = this.props;
24+
25+
const tableClass = cs('table', {
26+
'table-striped': striped,
27+
'table-hover': hover,
28+
'table-bordered': bordered,
29+
'table-condensed': condensed
30+
});
31+
1632
return (
1733
<div className="react-bootstrap-table-container">
18-
<table className="table">
34+
<table className={ tableClass }>
1935
<Header columns={ columns } />
2036
<Body
2137
data={ this.data }
@@ -31,7 +47,15 @@ class BootstrapTable extends storeBase(Component) {
3147
BootstrapTable.propTypes = {
3248
keyField: PropTypes.string.isRequired,
3349
data: PropTypes.array.isRequired,
34-
columns: PropTypes.array.isRequired
50+
columns: PropTypes.array.isRequired,
51+
striped: PropTypes.bool
52+
};
53+
54+
BootstrapTable.defaultProps = {
55+
striped: false,
56+
bordered: true,
57+
hover: false,
58+
condensed: false
3559
};
3660

3761
export default BootstrapTable;

packages/react-bootstrap-table2/test/bootstrap-table.test.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,54 @@ describe('BootstrapTable', () => {
3030

3131
it('should render successfully', () => {
3232
expect(wrapper.length).toBe(1);
33-
expect(wrapper.find('table').length).toBe(1);
33+
expect(wrapper.find('table.table').length).toBe(1);
3434
expect(wrapper.find(Header).length).toBe(1);
3535
expect(wrapper.find(Body).length).toBe(1);
3636
expect(wrapper.find('.react-bootstrap-table-container').length).toBe(1);
3737
});
38+
39+
it('should have table-bordered class as default', () => {
40+
expect(wrapper.find('table.table-bordered').length).toBe(1);
41+
});
42+
});
43+
44+
describe('when hover is true', () => {
45+
beforeEach(() => {
46+
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } hover />);
47+
});
48+
49+
it('should have table-hover class on table', () => {
50+
expect(wrapper.find('table.table-hover').length).toBe(1);
51+
});
52+
});
53+
54+
describe('when striped is true', () => {
55+
beforeEach(() => {
56+
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } striped />);
57+
});
58+
59+
it('should have table-striped class on table', () => {
60+
expect(wrapper.find('table.table-striped').length).toBe(1);
61+
});
62+
});
63+
64+
describe('when condensed is true', () => {
65+
beforeEach(() => {
66+
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } condensed />);
67+
});
68+
69+
it('should have table-condensed class on table', () => {
70+
expect(wrapper.find('table.table-condensed').length).toBe(1);
71+
});
72+
});
73+
74+
describe('when bordered is false', () => {
75+
beforeEach(() => {
76+
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } bordered={ false } />);
77+
});
78+
79+
it('should not have table-condensed class on table', () => {
80+
expect(wrapper.find('table.table-condensed').length).toBe(0);
81+
});
3882
});
3983
});

0 commit comments

Comments
 (0)