Skip to content

Commit 3e5ad89

Browse files
authored
Merge pull request #169 from react-component/next
Refactor
2 parents 20a83c6 + 36b89a1 commit 3e5ad89

32 files changed

+2097
-3034
lines changed

examples/dropdown.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,34 @@ for (let i = 0; i < 10; i++) {
1818
});
1919
}
2020

21-
const Test = React.createClass({
22-
getInitialState() {
23-
this.filters = [];
24-
return {
25-
visible: false,
26-
};
27-
},
21+
class Demo extends React.Component {
22+
state = {
23+
visible: false,
24+
}
25+
26+
filters = []
2827

29-
handleVisibleChange(visible) {
28+
handleVisibleChange = (visible) => {
3029
this.setState({ visible });
31-
},
30+
}
3231

33-
handleSelect(selected) {
32+
handleSelect = (selected) => {
3433
this.filters.push(selected);
35-
},
34+
}
3635

37-
handleDeselect(key) {
36+
handleDeselect = (key) => {
3837
const index = this.filters.indexOf(key);
3938
if (index !== -1) {
4039
this.filters.splice(index, 1);
4140
}
42-
},
41+
}
4342

44-
confirmFilter() {
43+
confirmFilter = () => {
4544
console.log(this.filters.join(','));
4645
this.setState({
4746
visible: false,
4847
});
49-
},
48+
}
5049

5150
render() {
5251
const menu = (
@@ -100,13 +99,13 @@ const Test = React.createClass({
10099
rowKey={record => record.key}
101100
/>
102101
);
103-
},
104-
});
102+
}
103+
}
105104

106105
ReactDOM.render(
107106
<div>
108107
<h2>use dropdown</h2>
109-
<Test />
108+
<Demo />
110109
</div>,
111110
document.getElementById('__react-content')
112111
);

examples/expandedRowRender.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,42 @@ const tableData = [
1010
{ key: 2, a: '1333', c: 'eee', d: 2 },
1111
];
1212

13-
const App = React.createClass({
14-
getInitialState() {
15-
this.columns = [
16-
{ title: 'title 1', dataIndex: 'a', key: 'a', width: 100 },
17-
{ title: 'title 2', dataIndex: 'b', key: 'b', width: 100 },
18-
{ title: 'title 3', dataIndex: 'c', key: 'c', width: 200 },
19-
{ title: 'Operation', dataIndex: '', key: 'x', render: this.renderAction },
20-
];
21-
return {
22-
data: tableData,
23-
expandedRowKeys: [],
24-
expandIconAsCell: true,
25-
expandRowByClick: false,
26-
};
27-
},
13+
class Demo extends React.Component {
14+
state = {
15+
data: tableData,
16+
expandedRowKeys: [],
17+
expandIconAsCell: true,
18+
expandRowByClick: false,
19+
}
2820

29-
onExpand(expanded, record) {
21+
onExpand = (expanded, record) => {
3022
console.log('onExpand', expanded, record);
31-
},
23+
}
3224

33-
onExpandedRowsChange(rows) {
25+
onExpandedRowsChange = (rows) => {
3426
this.setState({
3527
expandedRowKeys: rows,
3628
});
37-
},
29+
}
3830

39-
onExpandIconAsCellChange(e) {
31+
onExpandIconAsCellChange = (e) => {
4032
this.setState({
4133
expandIconAsCell: e.target.checked,
4234
});
43-
},
35+
}
4436

45-
onExpandRowByClickChange(e) {
37+
onExpandRowByClickChange = (e) => {
4638
this.setState({
4739
expandRowByClick: e.target.checked,
4840
});
49-
},
41+
}
42+
43+
columns = [
44+
{ title: 'title 1', dataIndex: 'a', key: 'a', width: 100 },
45+
{ title: 'title 2', dataIndex: 'b', key: 'b', width: 100 },
46+
{ title: 'title 3', dataIndex: 'c', key: 'c', width: 200 },
47+
{ title: 'Operation', dataIndex: '', key: 'x', render: this.renderAction },
48+
]
5049

5150
toggleButton() {
5251
if (this.state.expandedRowKeys.length) {
@@ -55,22 +54,22 @@ const App = React.createClass({
5554
}
5655
const openAll = () => this.setState({ expandedRowKeys: [0, 1, 2] });
5756
return <button onClick={openAll}>Expand All</button>;
58-
},
57+
}
5958

6059
remove(index) {
6160
const data = this.state.data;
6261
data.splice(index, 1);
6362
this.setState({ data });
64-
},
63+
}
6564

6665
expandedRowRender(record) {
67-
console.log(record);
66+
// console.log(record);
6867
return <p>extra: {record.a}</p>;
69-
},
68+
}
7069

7170
renderAction(o, row, index) {
7271
return <a href="#" onClick={() => this.remove(index)}>Delete</a>;
73-
},
72+
}
7473

7574
render() {
7675
const { expandIconAsCell, expandRowByClick, expandedRowKeys, data } = this.state;
@@ -103,13 +102,13 @@ const App = React.createClass({
103102
/>
104103
</div>
105104
);
106-
},
107-
});
105+
}
106+
}
108107

109108
ReactDOM.render(
110109
<div>
111110
<h2>expandedRowRender</h2>
112-
<App />
111+
<Demo />
113112
</div>,
114113
document.getElementById('__react-content')
115114
);

examples/fixedColumns-auto-height.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const columns = [
2121
];
2222

2323
const data = [
24-
{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' },
25-
{ a: 'cdd', b: 'edd12221', d: 3, key: '2' },
26-
{ a: '133', c: 'edd12221', d: 2, key: '3' },
27-
{ a: '133', c: 'edd12221', d: 2, key: '4' },
28-
{ a: '133', c: 'edd12221', d: 2, key: '5' },
29-
{ a: '133', c: 'edd12221', d: 2, key: '6' },
30-
{ a: '133', c: 'edd12221', d: 2, key: '7' },
31-
{ a: '133', c: 'edd12221', d: 2, key: '8' },
32-
{ a: '133', c: 'edd12221', d: 2, key: '9' },
24+
{ a: '123', b: 'xxxxxxxx', d: 3, key: '1', title: 'hello' },
25+
{ a: 'cdd', b: 'edd12221', d: 3, key: '2', title: 'hello' },
26+
{ a: '133', c: 'edd12221', d: 2, key: '3', title: 'hello' },
27+
{ a: '133', c: 'edd12221', d: 2, key: '4', title: 'hello' },
28+
{ a: '133', c: 'edd12221', d: 2, key: '5', title: 'hello' },
29+
{ a: '133', c: 'edd12221', d: 2, key: '6', title: 'hello' },
30+
{ a: '133', c: 'edd12221', d: 2, key: '7', title: 'hello' },
31+
{ a: '133', c: 'edd12221', d: 2, key: '8', title: 'hello' },
32+
{ a: '133', c: 'edd12221', d: 2, key: '9', title: 'hello' },
3333
];
3434

3535
ReactDOM.render(

examples/fixedColumnsAndHeader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ const data = [
3434
ReactDOM.render(
3535
<div>
3636
<h2>Fixed columns and header</h2>
37-
<Table columns={columns} scroll={{ x: true, y: 300 }} data={data} style={{ width: 800 }} />
37+
<Table columns={columns} scroll={{ x: 1650, y: 300 }} data={data} style={{ width: 800 }} />
3838
</div>
3939
, document.getElementById('__react-content'));

examples/key.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
/* eslint-disable no-console,func-names,react/no-multi-comp */
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4+
import PropTypes from 'prop-types';
45
import Table from 'rc-table';
56
import 'rc-table/assets/index.less';
67

7-
const CheckBox = React.createClass({
8-
render() {
9-
const props = this.props;
10-
return (
11-
<label>
12-
<input type="checkbox" />
13-
{props.id}
14-
</label>
15-
);
16-
},
17-
});
8+
const CheckBox = ({ id }) => (
9+
<label>
10+
<input type="checkbox" />
11+
{id}
12+
</label>
13+
);
1814

19-
const MyTable = React.createClass({
20-
getInitialState() {
21-
const props = this.props;
22-
return {
15+
class Demo extends React.Component {
16+
static propTypes = {
17+
data: PropTypes.array.isRequired,
18+
}
19+
20+
constructor(props) {
21+
super(props);
22+
23+
this.state = {
2324
data: props.data,
2425
};
25-
},
26+
}
2627

2728
remove(index) {
2829
const rows = this.state.data;
2930
rows.splice(index, 1);
3031
this.setState({
3132
data: rows,
3233
});
33-
},
34+
}
3435

35-
handleClick(index) {
36-
const self = this;
37-
return () => {
38-
self.remove(index);
39-
};
40-
},
36+
handleClick = (index) => () => {
37+
this.remove(index);
38+
}
4139

4240
checkbox(a) {
4341
return <CheckBox id={a} />;
44-
},
42+
}
4543

46-
renderAction(o, row, index) {
44+
renderAction = (o, row, index) => {
4745
return <a href="#" onClick={this.handleClick(index)}>Delete</a>;
48-
},
46+
}
4947

5048
render() {
5149
const state = this.state;
@@ -58,15 +56,15 @@ const MyTable = React.createClass({
5856
return (
5957
<Table columns={columns} data={state.data} className="table" rowKey={record => record.a} />
6058
);
61-
},
62-
});
59+
}
60+
}
6361

6462
const data = [{ a: '123' }, { a: 'cdd', b: 'edd' }, { a: '1333', c: 'eee', d: 2 }];
6563

6664
ReactDOM.render(
6765
<div>
6866
<h2>specify key</h2>
69-
<MyTable data={data} />
67+
<Demo data={data} />
7068
</div>,
7169
document.getElementById('__react-content')
7270
);

examples/scrollY.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ for (let i = 0; i < 10; i++) {
1414
});
1515
}
1616

17-
const Test = React.createClass({
18-
getInitialState() {
19-
return {
20-
showBody: true,
21-
};
22-
},
17+
class Demo extends React.Component {
18+
state = {
19+
showBody: true,
20+
}
2321

24-
toggleBody() {
22+
toggleBody = () => {
2523
this.setState({
2624
showBody: !this.state.showBody,
2725
});
28-
},
26+
}
2927

3028
render() {
3129
const columns = [
@@ -52,13 +50,13 @@ const Test = React.createClass({
5250
}}
5351
/>
5452
);
55-
},
56-
});
53+
}
54+
}
5755

5856
ReactDOM.render(
5957
<div>
6058
<h2>scroll body table</h2>
61-
<Test/>
59+
<Demo />
6260
</div>,
6361
document.getElementById('__react-content')
6462
);

examples/subTable.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ const data = [
2929
},
3030
];
3131

32-
const MyTable = React.createClass({
33-
handleClick(record, e) {
32+
class Demo extends React.Component {
33+
handleClick = (record, e) => {
3434
e.preventDefault();
3535
console.log(record.a);
36-
},
36+
}
37+
3738
render() {
3839
const columns = [
3940
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
@@ -56,7 +57,7 @@ const MyTable = React.createClass({
5657
/>
5758
</div>
5859
);
59-
},
60-
});
60+
}
61+
}
6162

62-
ReactDOM.render(<MyTable />, document.getElementById('__react-content'));
63+
ReactDOM.render(<Demo />, document.getElementById('__react-content'));

0 commit comments

Comments
 (0)