mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
docs: Rewrite Tabs demos to ES6 component
This commit is contained in:
parent
a4acf1f66e
commit
6bcd88f5c0
@ -17,31 +17,33 @@ Hide default plus icon, and bind event for customized trigger.
|
||||
import { Tabs, Button } from 'antd';
|
||||
const TabPane = Tabs.TabPane;
|
||||
|
||||
const Demo = React.createClass({
|
||||
getInitialState() {
|
||||
class Demo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.newTabIndex = 0;
|
||||
const panes = [
|
||||
{ title: 'Tab 1', content: 'Content of Tab Pane 1', key: '1' },
|
||||
{ title: 'Tab 2', content: 'Content of Tab Pane 2', key: '2' },
|
||||
];
|
||||
return {
|
||||
this.state = {
|
||||
activeKey: panes[0].key,
|
||||
panes,
|
||||
};
|
||||
},
|
||||
onChange(activeKey) {
|
||||
}
|
||||
|
||||
onChange = (activeKey) => {
|
||||
this.setState({ activeKey });
|
||||
},
|
||||
onEdit(targetKey, action) {
|
||||
}
|
||||
onEdit = (targetKey, action) => {
|
||||
this[action](targetKey);
|
||||
},
|
||||
add() {
|
||||
}
|
||||
add = () => {
|
||||
const panes = this.state.panes;
|
||||
const activeKey = `newTab${this.newTabIndex++}`;
|
||||
panes.push({ title: 'New Tab', content: 'New Tab Pane', key: activeKey });
|
||||
this.setState({ panes, activeKey });
|
||||
},
|
||||
remove(targetKey) {
|
||||
}
|
||||
remove = (targetKey) => {
|
||||
let activeKey = this.state.activeKey;
|
||||
let lastIndex;
|
||||
this.state.panes.forEach((pane, i) => {
|
||||
@ -54,7 +56,7 @@ const Demo = React.createClass({
|
||||
activeKey = panes[lastIndex].key;
|
||||
}
|
||||
this.setState({ panes, activeKey });
|
||||
},
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
@ -72,8 +74,8 @@ const Demo = React.createClass({
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<Demo />, mountNode);
|
||||
````
|
||||
|
@ -17,31 +17,34 @@ Only card type Tabs support adding & closeable.
|
||||
import { Tabs } from 'antd';
|
||||
const TabPane = Tabs.TabPane;
|
||||
|
||||
const Demo = React.createClass({
|
||||
getInitialState() {
|
||||
|
||||
class Demo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.newTabIndex = 0;
|
||||
const panes = [
|
||||
{ title: 'Tab 1', content: 'Content of Tab 1', key: '1' },
|
||||
{ title: 'Tab 2', content: 'Content of Tab 2', key: '2' },
|
||||
{ title: 'Tab 1', content: 'Content of Tab Pane 1', key: '1' },
|
||||
{ title: 'Tab 2', content: 'Content of Tab Pane 2', key: '2' },
|
||||
];
|
||||
return {
|
||||
this.state = {
|
||||
activeKey: panes[0].key,
|
||||
panes,
|
||||
};
|
||||
},
|
||||
onChange(activeKey) {
|
||||
}
|
||||
|
||||
onChange = (activeKey) => {
|
||||
this.setState({ activeKey });
|
||||
},
|
||||
onEdit(targetKey, action) {
|
||||
}
|
||||
onEdit = (targetKey, action) => {
|
||||
this[action](targetKey);
|
||||
},
|
||||
add() {
|
||||
}
|
||||
add = () => {
|
||||
const panes = this.state.panes;
|
||||
const activeKey = `newTab${this.newTabIndex++}`;
|
||||
panes.push({ title: 'New Tab', content: 'Content of new Tab', key: activeKey });
|
||||
this.setState({ panes, activeKey });
|
||||
},
|
||||
remove(targetKey) {
|
||||
}
|
||||
remove = (targetKey) => {
|
||||
let activeKey = this.state.activeKey;
|
||||
let lastIndex;
|
||||
this.state.panes.forEach((pane, i) => {
|
||||
@ -54,7 +57,7 @@ const Demo = React.createClass({
|
||||
activeKey = panes[lastIndex].key;
|
||||
}
|
||||
this.setState({ panes, activeKey });
|
||||
},
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<Tabs
|
||||
@ -66,8 +69,8 @@ const Demo = React.createClass({
|
||||
{this.state.panes.map(pane => <TabPane tab={pane.title} key={pane.key}>{pane.content}</TabPane>)}
|
||||
</Tabs>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<Demo />, mountNode);
|
||||
````
|
||||
|
@ -18,15 +18,14 @@ import { Tabs, Select } from 'antd';
|
||||
const TabPane = Tabs.TabPane;
|
||||
const Option = Select.Option;
|
||||
|
||||
const Demo = React.createClass({
|
||||
getInitialState() {
|
||||
return {
|
||||
tabPosition: 'top',
|
||||
};
|
||||
},
|
||||
changeTabPosition(tabPosition) {
|
||||
|
||||
class Demo extends React.Component {
|
||||
state = {
|
||||
tabPosition: 'top',
|
||||
}
|
||||
changeTabPosition = (tabPosition) => {
|
||||
this.setState({ tabPosition });
|
||||
},
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
@ -48,8 +47,8 @@ const Demo = React.createClass({
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<Demo />, mountNode);
|
||||
````
|
||||
|
Loading…
Reference in New Issue
Block a user