All files / src/modal/_example ModalShowExample.jsx

14.29% Statements 1/7
100% Branches 0/0
16.67% Functions 1/6
14.29% Lines 1/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41          1x                                                                      
import React, { useState } from "react";
import { Button } from "@tencent/tea-component/lib/button";
import { Modal } from "@tencent/tea-component/lib/modal";
 
export default function ModalShowExample() {
  return (
    <Button
      type="primary"
      onClick={() => {
        const modal = Modal.show({
          caption: "Modal.show() 打开对话框",
          children: <TimingModal onClose={() => modal.destroy()} />,
          onClose: () => modal.destroy(),
        });
      }}
    >
      打开
    </Button>
  );
}
 
// eslint-disable-next-line react/prop-types
function TimingModal({ onClose }) {
  const [time, setTime] = useState(new Date().toTimeString());
 
  return (
    <>
      <Modal.Body>当前时间 {time}</Modal.Body>
      <Modal.Footer>
        <Button
          type="primary"
          onClick={() => setTime(new Date().toTimeString())}
        >
          更新时间
        </Button>
        <Button onClick={onClose}>关闭</Button>
      </Modal.Footer>
    </>
  );
}