mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update sidebar styles in mobile view (#285)
* 添加移动端点击自动关闭侧边栏 * 添加移动端点击自动关闭侧边栏 * 添加移动端点击自动关闭侧边栏 * move closeSidebar function to utils * move closeSidebar function to utils * 侧边栏优化 * 移动端侧边栏优化 * 移动端侧边栏优化 * 移动端侧边栏优化
This commit is contained in:
@ -5,6 +5,7 @@ import { useAppSelector } from "../store";
|
|||||||
import * as utils from "../helpers/utils";
|
import * as utils from "../helpers/utils";
|
||||||
import useToggle from "../hooks/useToggle";
|
import useToggle from "../hooks/useToggle";
|
||||||
import useLoading from "../hooks/useLoading";
|
import useLoading from "../hooks/useLoading";
|
||||||
|
import { closeSidebar } from "../helpers/utils";
|
||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
import toastHelper from "./Toast";
|
import toastHelper from "./Toast";
|
||||||
import showCreateShortcutDialog from "./CreateShortcutDialog";
|
import showCreateShortcutDialog from "./CreateShortcutDialog";
|
||||||
@ -63,6 +64,7 @@ const ShortcutContainer: React.FC<ShortcutContainerProps> = (props: ShortcutCont
|
|||||||
const [showConfirmDeleteBtn, toggleConfirmDeleteBtn] = useToggle(false);
|
const [showConfirmDeleteBtn, toggleConfirmDeleteBtn] = useToggle(false);
|
||||||
|
|
||||||
const handleShortcutClick = () => {
|
const handleShortcutClick = () => {
|
||||||
|
closeSidebar();
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
locationService.setMemoShortcut(undefined);
|
locationService.setMemoShortcut(undefined);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { userService } from "../services";
|
import { userService } from "../services";
|
||||||
import Icon from "./Icon";
|
|
||||||
import showDailyReviewDialog from "./DailyReviewDialog";
|
import showDailyReviewDialog from "./DailyReviewDialog";
|
||||||
import showSettingDialog from "./SettingDialog";
|
import showSettingDialog from "./SettingDialog";
|
||||||
import UserBanner from "./UserBanner";
|
import UserBanner from "./UserBanner";
|
||||||
import UsageHeatMap from "./UsageHeatMap";
|
import UsageHeatMap from "./UsageHeatMap";
|
||||||
import ShortcutList from "./ShortcutList";
|
import ShortcutList from "./ShortcutList";
|
||||||
import TagList from "./TagList";
|
import TagList from "./TagList";
|
||||||
|
import { closeSidebar } from "../helpers/utils";
|
||||||
import "../less/siderbar.less";
|
import "../less/siderbar.less";
|
||||||
|
|
||||||
const Sidebar = () => {
|
const Sidebar = () => {
|
||||||
@ -18,42 +18,42 @@ const Sidebar = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="sidebar-wrapper">
|
<div>
|
||||||
<div className="close-container">
|
<aside className="sidebar-wrapper close-sidebar">
|
||||||
<span className="action-btn" onClick={toggleSiderbar}>
|
<UserBanner />
|
||||||
<Icon.X className="icon-img" />
|
<UsageHeatMap />
|
||||||
</span>
|
<div className="action-btns-container">
|
||||||
</div>
|
<button className="btn action-btn" onClick={() => showDailyReviewDialog()}>
|
||||||
<UserBanner />
|
<span className="icon">📅</span> {t("sidebar.daily-review")}
|
||||||
<UsageHeatMap />
|
</button>
|
||||||
<div className="action-btns-container">
|
{!userService.isVisitorMode() && (
|
||||||
<button className="btn action-btn" onClick={() => showDailyReviewDialog()}>
|
<>
|
||||||
<span className="icon">📅</span> {t("sidebar.daily-review")}
|
<Link to="/explore" className="btn action-btn">
|
||||||
</button>
|
<span className="icon">🏂</span> {t("common.explore")}
|
||||||
{!userService.isVisitorMode() && (
|
</Link>
|
||||||
<>
|
<button className="btn action-btn" onClick={handleSettingBtnClick}>
|
||||||
<Link to="/explore" className="btn action-btn">
|
<span className="icon">⚙️</span> {t("sidebar.setting")}
|
||||||
<span className="icon">🏂</span> {t("common.explore")}
|
</button>
|
||||||
</Link>
|
</>
|
||||||
<button className="btn action-btn" onClick={handleSettingBtnClick}>
|
)}
|
||||||
<span className="icon">⚙️</span> {t("sidebar.setting")}
|
</div>
|
||||||
</button>
|
{!userService.isVisitorMode() && <ShortcutList />}
|
||||||
</>
|
<TagList />
|
||||||
)}
|
</aside>
|
||||||
</div>
|
|
||||||
{!userService.isVisitorMode() && <ShortcutList />}
|
<div className="mask" onClick={closeSidebar}></div>
|
||||||
<TagList />
|
</div>
|
||||||
</aside>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toggleSiderbar = () => {
|
export const toggleSiderbar = () => {
|
||||||
const sidebarEl = document.body.querySelector(".sidebar-wrapper") as HTMLDivElement;
|
const sidebarEl = document.body.querySelector(".sidebar-wrapper") as HTMLDivElement;
|
||||||
const display = window.getComputedStyle(sidebarEl).display;
|
const maskEl = document.body.querySelector(".mask") as HTMLDivElement;
|
||||||
if (display === "none") {
|
if (!sidebarEl.classList.contains("close-sidebar")) {
|
||||||
sidebarEl.style.display = "flex";
|
sidebarEl.classList.replace("open-sidebar", "close-sidebar");
|
||||||
} else {
|
} else {
|
||||||
sidebarEl.style.display = "none";
|
sidebarEl.classList.replace("close-sidebar", "open-sidebar");
|
||||||
|
maskEl.classList.contains("hide-mask") ? maskEl.classList.replace("hide-mask", "show-mask") : maskEl.classList.add("show-mask");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { useAppSelector } from "../store";
|
import { useAppSelector } from "../store";
|
||||||
import { locationService, memoService, userService } from "../services";
|
import { locationService, memoService, userService } from "../services";
|
||||||
import useToggle from "../hooks/useToggle";
|
import useToggle from "../hooks/useToggle";
|
||||||
|
import { closeSidebar } from "../helpers/utils";
|
||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
import "../less/tag-list.less";
|
import "../less/tag-list.less";
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ const TagList = () => {
|
|||||||
}, [tagsText]);
|
}, [tagsText]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="tags-wrapper">
|
<div className="tags-wrapper" onClick={closeSidebar}>
|
||||||
<p className="title-text">{t("common.tags")}</p>
|
<p className="title-text">{t("common.tags")}</p>
|
||||||
<div className="tags-container">
|
<div className="tags-container">
|
||||||
{tags.map((t, idx) => (
|
{tags.map((t, idx) => (
|
||||||
|
@ -134,3 +134,10 @@ export const parseHTMLToRawText = (htmlStr: string): string => {
|
|||||||
const text = tempEl.innerText;
|
const text = tempEl.innerText;
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function closeSidebar() {
|
||||||
|
const sidebarEl = document.body.querySelector(".sidebar-wrapper") as HTMLDivElement;
|
||||||
|
const maskEl = document.body.querySelector(".mask") as HTMLDivElement;
|
||||||
|
sidebarEl.classList.replace("open-sidebar", "close-sidebar");
|
||||||
|
maskEl.classList.replace("show-mask", "hide-mask");
|
||||||
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
@import "./mixin.less";
|
@import "./mixin.less";
|
||||||
|
|
||||||
.sidebar-wrapper {
|
.sidebar-wrapper {
|
||||||
@apply fixed sm:sticky top-0 left-0 z-20 sm:z-0 hidden sm:!flex flex-col justify-start items-start w-64 h-screen py-4 pl-2 bg-white sm:bg-transparent shadow-2xl sm:shadow-none overflow-x-hidden overflow-y-auto transition-all;
|
@apply fixed sm:sticky top-0 z-30 sm:z-0 sm:!flex flex-col justify-start items-start w-64 h-screen py-4 pl-2 bg-white sm:bg-transparent shadow-2xl sm:shadow-none overflow-x-hidden overflow-y-auto transition-transform duration-377;
|
||||||
.hide-scroll-bar();
|
.hide-scroll-bar();
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
|
||||||
> .close-container {
|
> .close-container {
|
||||||
@apply w-full pr-6 my-2 flex sm:hidden flex-row justify-end items-center;
|
@apply w-full pr-6 my-2 flex sm:hidden flex-row justify-end items-center;
|
||||||
@ -24,3 +25,50 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.open-sidebar{
|
||||||
|
@apply sm:transform translate-x-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-sidebar{
|
||||||
|
@apply sm:transform -translate-x-64 md:translate-x-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask{
|
||||||
|
@apply fixed top-0 right-0 w-screen h-screen;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide-mask{
|
||||||
|
animation: hide 0.23s ease-in;
|
||||||
|
@keyframes hide {
|
||||||
|
0%{
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
65%{
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-mask{
|
||||||
|
@apply translate-x-0 z-20;
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
animation: show 0.37s ease-in;
|
||||||
|
@keyframes show {
|
||||||
|
0%{
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
80%{
|
||||||
|
background-color: rgba(0, 0, 0, 0.56);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -27,6 +27,9 @@ module.exports = {
|
|||||||
gridTemplateRows: {
|
gridTemplateRows: {
|
||||||
7: "repeat(7, minmax(0, 1fr))",
|
7: "repeat(7, minmax(0, 1fr))",
|
||||||
},
|
},
|
||||||
|
transitionDuration: {
|
||||||
|
'377': '377ms',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user