index.jsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Modal, Button } from '@douyinfe/semi-ui';
  2. import { Animation } from '@douyinfe/semi-animation-react';
  3. import React from 'react';
  4. export default class modalDemo extends React.Component {
  5. constructor() {
  6. super();
  7. this.state = { visible: false, reverse: false };
  8. this.showDialog = this.showDialog.bind(this);
  9. this.handleOk = this.handleOk.bind(this);
  10. this.handleCancel = this.handleCancel.bind(this);
  11. }
  12. showDialog() {
  13. this.setState({
  14. reverse: false,
  15. visible: true,
  16. });
  17. }
  18. handleOk(e) {
  19. this.setState({
  20. reverse: true,
  21. });
  22. }
  23. handleCancel(e) {
  24. this.setState({
  25. reverse: true,
  26. });
  27. }
  28. render() {
  29. let { reverse, visible } = this.state;
  30. return (
  31. <>
  32. <Button onClick={this.showDialog}>Open Modal</Button>
  33. <Animation
  34. from={{ x: 0 }}
  35. to={{ x: 1 }}
  36. reverse={reverse}
  37. reset={visible}
  38. config={{ duration: 200, easing: reverse ? 'easeOutCubic' : 'easeInCubic' }}
  39. onRest={() => {
  40. if (reverse) {
  41. this.setState({ visible: false });
  42. }
  43. }}
  44. >
  45. {({ x }) => (
  46. <Modal
  47. title="自定义样式"
  48. visible={this.state.visible}
  49. onOk={this.handleOk}
  50. onCancel={this.handleCancel}
  51. style={{ top: '30vh', transform: `scale(${x}, ${x})` }}
  52. maskStyle={{ backgroundColor: 'pink', opacity: '.3' }}
  53. bodyStyle={{ backgroundColor: 'lightgrey' }}
  54. >
  55. <p>This is a modal with customized styles.</p>
  56. <p>More content...</p>
  57. </Modal>
  58. )}
  59. </Animation>
  60. </>
  61. );
  62. }
  63. }