Tabs


Tabs - 图1

  1. import React from 'react';
  2. import { TabContent, TabPane, Nav, NavItem, NavLink, Card, Button, CardTitle, CardText, Row, Col } from 'reactstrap';
  3. import classnames from 'classnames';
  4. export default class Example extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.toggle = this.toggle.bind(this);
  8. this.state = {
  9. activeTab: '1'
  10. };
  11. }
  12. toggle(tab) {
  13. if (this.state.activeTab !== tab) {
  14. this.setState({
  15. activeTab: tab
  16. });
  17. }
  18. }
  19. render() {
  20. return (
  21. <div>
  22. <Nav tabs>
  23. <NavItem>
  24. <NavLink
  25. className={classnames({ active: this.state.activeTab === '1' })}
  26. onClick={() => { this.toggle('1'); }}
  27. >
  28. Tab1
  29. </NavLink>
  30. </NavItem>
  31. <NavItem>
  32. <NavLink
  33. className={classnames({ active: this.state.activeTab === '2' })}
  34. onClick={() => { this.toggle('2'); }}
  35. >
  36. Moar Tabs
  37. </NavLink>
  38. </NavItem>
  39. </Nav>
  40. <TabContent activeTab={this.state.activeTab}>
  41. <TabPane tabId="1">
  42. <Row>
  43. <Col sm="12">
  44. <h4>Tab 1 Contents</h4>
  45. </Col>
  46. </Row>
  47. </TabPane>
  48. <TabPane tabId="2">
  49. <Row>
  50. <Col sm="6">
  51. <Card body>
  52. <CardTitle>Special Title Treatment</CardTitle>
  53. <CardText>With supporting text below as a natural lead-in to additional content.</CardText>
  54. <Button>Go somewhere</Button>
  55. </Card>
  56. </Col>
  57. <Col sm="6">
  58. <Card body>
  59. <CardTitle>Special Title Treatment</CardTitle>
  60. <CardText>With supporting text below as a natural lead-in to additional content.</CardText>
  61. <Button>Go somewhere</Button>
  62. </Card>
  63. </Col>
  64. </Row>
  65. </TabPane>
  66. </TabContent>
  67. </div>
  68. );
  69. }
  70. }