refactor: add typescript definition

This commit is contained in:
HD
2022-06-22 17:36:05 +08:00
parent 0b612d8c8e
commit b66919114d
+55 -45
View File
@@ -1,8 +1,18 @@
import { FC, ReactElement } from "react";
import Tippy from "@tippyjs/react";
import useContactOperation from "../../hook/useContactOperation";
import ContextMenu from "../ContextMenu";
export default function ContactContextMenu({ enable = false, uid, cid, visible, hide, children }) {
interface Props {
enable?: boolean;
uid: number;
cid: number;
visible: boolean;
hide: () => void;
children: ReactElement;
}
const ContactContextMenu: FC<Props> = ({ enable = false, uid, cid, visible, hide, children }) => {
const {
canCall,
call,
@@ -18,48 +28,48 @@ export default function ContactContextMenu({ enable = false, uid, cid, visible,
cid
});
return (
<>
<Tippy
disabled={!enable}
visible={visible}
followCursor={"initial"}
interactive
placement="right-start"
popperOptions={{ strategy: "fixed" }}
onClickOutside={hide}
key={uid}
content={
<ContextMenu
hideMenu={hide}
items={[
{
title: "Message",
handler: startChat
},
canCall && {
title: "Call",
handler: call
},
canCopyEmail && {
title: "Copy Email",
handler: copyEmail
},
canRemoveFromChannel && {
danger: true,
title: "Remove From Channel",
handler: removeFromChannel
},
canRemove && {
danger: true,
title: "Remove From Server",
handler: removeUser
}
]}
/>
}
>
{children}
</Tippy>
</>
<Tippy
disabled={!enable}
visible={visible}
followCursor={"initial"}
interactive
placement="right-start"
popperOptions={{ strategy: "fixed" }}
onClickOutside={hide}
key={uid}
content={
<ContextMenu
hideMenu={hide}
items={[
{
title: "Message",
handler: startChat
},
canCall && {
title: "Call",
handler: call
},
canCopyEmail && {
title: "Copy Email",
handler: copyEmail
},
canRemoveFromChannel && {
danger: true,
title: "Remove From Channel",
handler: removeFromChannel
},
canRemove && {
danger: true,
title: "Remove From Server",
handler: removeUser
}
]}
/>
}
>
{children}
</Tippy>
);
}
};
export default ContactContextMenu;