mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add use reponsive width
This commit is contained in:
@ -21,7 +21,7 @@ const HomeSidebarDrawer = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="md:hidden">
|
<>
|
||||||
<IconButton onClick={toggleDrawer(true)}>
|
<IconButton onClick={toggleDrawer(true)}>
|
||||||
<Icon.Search className="w-5 h-auto dark:text-gray-200" />
|
<Icon.Search className="w-5 h-auto dark:text-gray-200" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@ -30,7 +30,7 @@ const HomeSidebarDrawer = () => {
|
|||||||
<HomeSidebar />
|
<HomeSidebar />
|
||||||
</div>
|
</div>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
||||||
import NavigationDrawer from "./NavigationDrawer";
|
import NavigationDrawer from "./NavigationDrawer";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -7,12 +8,13 @@ interface Props {
|
|||||||
|
|
||||||
const MobileHeader = (props: Props) => {
|
const MobileHeader = (props: Props) => {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
|
const { sm } = useResponsiveWidth();
|
||||||
const [titleText] = useState("MEMOS");
|
const [titleText] = useState("MEMOS");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sticky top-0 pt-4 sm:pt-1 pb-1 mb-1 backdrop-blur bg-zinc-100 dark:bg-zinc-800 bg-opacity-70 flex md:hidden flex-row justify-between items-center w-full h-auto flex-nowrap shrink-0 z-2">
|
<div className="sticky top-0 pt-4 sm:pt-1 pb-1 mb-1 backdrop-blur bg-zinc-100 dark:bg-zinc-800 bg-opacity-70 flex md:hidden flex-row justify-between items-center w-full h-auto flex-nowrap shrink-0 z-2">
|
||||||
<div className="flex flex-row justify-start items-center mr-2 shrink-0 overflow-hidden">
|
<div className="flex flex-row justify-start items-center mr-2 shrink-0 overflow-hidden">
|
||||||
<NavigationDrawer />
|
{!sm && <NavigationDrawer />}
|
||||||
<span
|
<span
|
||||||
className="font-bold text-lg leading-10 mr-1 text-ellipsis shrink-0 cursor-pointer overflow-hidden text-gray-700 dark:text-gray-200"
|
className="font-bold text-lg leading-10 mr-1 text-ellipsis shrink-0 cursor-pointer overflow-hidden text-gray-700 dark:text-gray-200"
|
||||||
onClick={() => location.reload()}
|
onClick={() => location.reload()}
|
||||||
|
@ -21,7 +21,7 @@ const NavigationDrawer = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sm:hidden">
|
<>
|
||||||
<IconButton onClick={toggleDrawer(true)}>
|
<IconButton onClick={toggleDrawer(true)}>
|
||||||
<Icon.Menu className="w-5 h-auto dark:text-gray-200" />
|
<Icon.Menu className="w-5 h-auto dark:text-gray-200" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@ -30,7 +30,7 @@ const NavigationDrawer = () => {
|
|||||||
<Navigation />
|
<Navigation />
|
||||||
</div>
|
</div>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
18
web/src/hooks/useResponsiveWidth.ts
Normal file
18
web/src/hooks/useResponsiveWidth.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import useWindowSize from "react-use/lib/useWindowSize";
|
||||||
|
|
||||||
|
enum TailwindResponsiveWidth {
|
||||||
|
sm = 640,
|
||||||
|
md = 768,
|
||||||
|
lg = 1024,
|
||||||
|
}
|
||||||
|
|
||||||
|
const useResponsiveWidth = () => {
|
||||||
|
const { width } = useWindowSize();
|
||||||
|
return {
|
||||||
|
sm: width >= TailwindResponsiveWidth.sm,
|
||||||
|
md: width >= TailwindResponsiveWidth.md,
|
||||||
|
lg: width >= TailwindResponsiveWidth.lg,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useResponsiveWidth;
|
@ -3,20 +3,22 @@ import HomeSidebarDrawer from "@/components/HomeSidebarDrawer";
|
|||||||
import MemoEditor from "@/components/MemoEditor";
|
import MemoEditor from "@/components/MemoEditor";
|
||||||
import MemoList from "@/components/MemoList";
|
import MemoList from "@/components/MemoList";
|
||||||
import MobileHeader from "@/components/MobileHeader";
|
import MobileHeader from "@/components/MobileHeader";
|
||||||
|
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
|
const { md } = useResponsiveWidth();
|
||||||
return (
|
return (
|
||||||
<div className="w-full flex flex-row justify-start items-start">
|
<div className="w-full flex flex-row justify-start items-start">
|
||||||
<div className="w-full px-4 md:max-w-[calc(100%-14rem)] sm:px-2 sm:pt-4">
|
<div className="w-full px-4 md:max-w-[calc(100%-14rem)] sm:px-2 sm:pt-4">
|
||||||
<MobileHeader>
|
<MobileHeader>{!md && <HomeSidebarDrawer />}</MobileHeader>
|
||||||
<HomeSidebarDrawer />
|
|
||||||
</MobileHeader>
|
|
||||||
<MemoEditor className="mb-2" cacheKey="home-memo-editor" />
|
<MemoEditor className="mb-2" cacheKey="home-memo-editor" />
|
||||||
<MemoList />
|
<MemoList />
|
||||||
</div>
|
</div>
|
||||||
|
{md && (
|
||||||
<div className="hidden md:block sticky top-0 left-0 w-56">
|
<div className="hidden md:block sticky top-0 left-0 w-56">
|
||||||
<HomeSidebar />
|
<HomeSidebar />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user