index.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { Component } from 'react';
  2. import { Modal, Collapsible, Button, Table } from '@douyinfe/semi-ui';
  3. class Demo extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. isOpen: false,
  8. visible: false,
  9. content: null,
  10. contentIndex: 0
  11. };
  12. this.showDialog = this.showDialog.bind(this);
  13. this.handleOk = this.handleOk.bind(this);
  14. this.handleCancel = this.handleCancel.bind(this);
  15. this.toggle = this.toggle.bind(this);
  16. this.changeContent = this.changeContent.bind(this);
  17. this.contents = [
  18. <ul key="ul">
  19. <li>
  20. <p>Semi Design 以内容优先进行设计。</p>
  21. </li>
  22. <li>
  23. <p>更容易地自定义主题。</p>
  24. </li>
  25. </ul>,
  26. <Table key="table" columns={[
  27. {
  28. title: 'Name',
  29. dataIndex: 'name',
  30. width: 150,
  31. render: (text, record) => text,
  32. },
  33. {
  34. title: 'Age',
  35. dataIndex: 'age',
  36. width: 150,
  37. render: (text, record) => text,
  38. },
  39. {
  40. title: 'Address',
  41. dataIndex: 'address',
  42. render: (text, record) => text,
  43. },
  44. {
  45. render: (text, record) => (
  46. <p>Show Info</p>
  47. ),
  48. width: 150,
  49. },
  50. ]} />
  51. ];
  52. }
  53. showDialog() {
  54. this.setState({
  55. visible: true,
  56. });
  57. }
  58. handleOk(e) {
  59. this.setState({
  60. visible: false,
  61. });
  62. }
  63. handleCancel(e) {
  64. this.setState({
  65. visible: false,
  66. });
  67. }
  68. toggle() {
  69. this.setState({ isOpen: !this.state.isOpen });
  70. }
  71. changeContent() {
  72. this.setState({
  73. contentIndex: (this.state.contentIndex + 1) % this.contents.length,
  74. });
  75. }
  76. componentDidMount() {
  77. this.changeContent();
  78. }
  79. render() {
  80. const { isOpen, content, contentIndex } = this.state;
  81. return (
  82. <div>
  83. <Button onClick={this.showDialog}>打开弹窗</Button>
  84. <Modal
  85. title="基本对话框"
  86. visible={this.state.visible}
  87. onOk={this.handleOk}
  88. onCancel={this.handleCancel}
  89. >
  90. <Button onClick={this.toggle}>Toggle</Button>
  91. <Button onClick={() => this.changeContent()}>Change Content</Button>
  92. <Collapsible isOpen={isOpen}>{this.contents[contentIndex]}</Collapsible>
  93. </Modal>
  94. </div>
  95. );
  96. }
  97. }
  98. export default () => <Demo />;