mirror of https://github.com/usememos/memos
chore: update dropdown component
parent
7a6eb53e0f
commit
004713d4cd
@ -1,82 +0,0 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { userService } from "../services";
|
||||
import Only from "./common/OnlyWhen";
|
||||
import showAboutSiteDialog from "./AboutSiteDialog";
|
||||
import showArchivedMemoDialog from "./ArchivedMemoDialog";
|
||||
import showResourcesDialog from "./ResourcesDialog";
|
||||
import "../less/menu-btns-popup.less";
|
||||
|
||||
interface Props {
|
||||
shownStatus: boolean;
|
||||
setShownStatus: (status: boolean) => void;
|
||||
}
|
||||
|
||||
const MenuBtnsPopup: React.FC<Props> = (props: Props) => {
|
||||
const { shownStatus, setShownStatus } = props;
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const popupElRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (shownStatus) {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (!popupElRef.current?.contains(event.target as Node)) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
setShownStatus(false);
|
||||
};
|
||||
window.addEventListener("click", handleClickOutside, {
|
||||
capture: true,
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
}, [shownStatus]);
|
||||
|
||||
const handleResourcesBtnClick = () => {
|
||||
showResourcesDialog();
|
||||
};
|
||||
|
||||
const handleArchivedBtnClick = () => {
|
||||
showArchivedMemoDialog();
|
||||
};
|
||||
|
||||
const handleAboutBtnClick = () => {
|
||||
showAboutSiteDialog();
|
||||
};
|
||||
|
||||
const handleSignOutBtnClick = async () => {
|
||||
userService
|
||||
.doSignOut()
|
||||
.then(() => {
|
||||
navigate("/auth");
|
||||
})
|
||||
.catch(() => {
|
||||
// do nth
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`menu-btns-popup ${shownStatus ? "" : "hidden"}`} ref={popupElRef}>
|
||||
<Only when={!userService.isVisitorMode()}>
|
||||
<button className="btn action-btn" onClick={handleResourcesBtnClick}>
|
||||
<span className="icon">🌄</span> {t("sidebar.resources")}
|
||||
</button>
|
||||
<button className="btn action-btn" onClick={handleArchivedBtnClick}>
|
||||
<span className="icon">🗂</span> {t("sidebar.archived")}
|
||||
</button>
|
||||
</Only>
|
||||
<button className="btn action-btn" onClick={handleAboutBtnClick}>
|
||||
<span className="icon">🤠</span> {t("common.about")}
|
||||
</button>
|
||||
<Only when={!userService.isVisitorMode()}>
|
||||
<button className="btn action-btn" onClick={handleSignOutBtnClick}>
|
||||
<span className="icon">👋</span> {t("common.sign-out")}
|
||||
</button>
|
||||
</Only>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MenuBtnsPopup;
|
@ -1,21 +0,0 @@
|
||||
@import "../mixin.less";
|
||||
|
||||
.dropdown-wrapper {
|
||||
@apply relative flex flex-col justify-start items-start select-none;
|
||||
|
||||
> .trigger-button {
|
||||
@apply flex flex-row justify-center items-center border p-1 rounded shadow text-gray-600 cursor-pointer hover:opacity-80;
|
||||
|
||||
> .icon-img {
|
||||
@apply w-4 h-auto;
|
||||
}
|
||||
}
|
||||
|
||||
> .action-buttons-container {
|
||||
@apply w-28 mt-1 absolute top-full right-0 flex flex-col justify-start items-start bg-white z-1 border p-1 rounded shadow;
|
||||
|
||||
> button {
|
||||
@apply w-full text-left px-2 text-sm leading-7 rounded hover:bg-gray-100;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
@import "./mixin.less";
|
||||
|
||||
.menu-btns-popup {
|
||||
@apply absolute right-2 top-6 flex flex-col justify-start items-start mt-4 p-1 w-36 rounded-lg z-10 shadow bg-white;
|
||||
|
||||
> .btn {
|
||||
@apply flex flex-row justify-start items-center w-full py-2 px-3 text-base rounded text-left hover:bg-gray-100;
|
||||
|
||||
> .icon {
|
||||
@apply block w-6 text-center mr-2 text-base;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue