-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from Kutius/dev
小屏幕适配 (仅首页除drawer)
- Loading branch information
Showing
8 changed files
with
192 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Button } from '@blueprintjs/core' | ||
|
||
import { useAtomValue, useSetAtom } from 'jotai' | ||
|
||
import { navAtom, toggleExpandNavAtom } from 'store/nav' | ||
|
||
export const NavExpandButton = () => { | ||
const expanded = useAtomValue(navAtom) | ||
const toggleExpaned = useSetAtom(toggleExpandNavAtom) | ||
|
||
return ( | ||
<div className="sm:hidden"> | ||
<Button | ||
onClick={toggleExpaned} | ||
icon={expanded.expanded ? 'cross' : 'menu'} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Button, Portal } from '@blueprintjs/core' | ||
|
||
import { useAtomValue, useSetAtom } from 'jotai' | ||
import { LINKS } from 'layouts/AppLayout' | ||
import { NavLink } from 'react-router-dom' | ||
|
||
import { navAtom, toggleExpandNavAtom } from 'store/nav' | ||
|
||
export const NavAside = () => { | ||
const nav = useAtomValue(navAtom) | ||
const toggleNav = useSetAtom(toggleExpandNavAtom) | ||
const navLinks = [...LINKS] | ||
|
||
if (!nav.expanded) return null | ||
|
||
return ( | ||
<Portal> | ||
{/* todo: 这里可以重写移动端header 需要去掉top */} | ||
<div className="fixed inset-0 top-14 z-50 overflow-y-auto backdrop-blur-lg sm:hidden"> | ||
<div className="px-4 sm:px-6 pt-3 pb-6"> | ||
<nav className="flex flex-col gap-3"> | ||
{navLinks.map((link) => ( | ||
<div className="flex-col w-full" key={link.to}> | ||
<NavLink | ||
to={link.to} | ||
className="text-sm text-zinc-600 !no-underline" | ||
onClick={() => toggleNav()} | ||
> | ||
{({ isActive }) => ( | ||
<Button | ||
minimal | ||
icon={link.icon} | ||
active={isActive} | ||
className="w-full flex items-center" | ||
style={{ justifyContent: 'flex-start' }} | ||
> | ||
{link.label} | ||
</Button> | ||
)} | ||
</NavLink> | ||
</div> | ||
))} | ||
</nav> | ||
</div> | ||
</div> | ||
</Portal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { atom } from 'jotai' | ||
|
||
interface NavState { | ||
expanded?: boolean | ||
} | ||
|
||
export const navAtom = atom<NavState>({ | ||
expanded: false, | ||
}) | ||
|
||
export const toggleExpandNavAtom = atom(null, (get, set, value) => { | ||
set(navAtom, { | ||
...get(navAtom), | ||
expanded: !get(navAtom).expanded, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useMemo } from 'react' | ||
import { useWindowSize } from 'react-use' | ||
|
||
// https://tailwindcss.com/docs/container | ||
export const useCurrentSize = () => { | ||
const { width } = useWindowSize() | ||
|
||
const isSM = useMemo(() => width < 640, [width]) | ||
const isMD = useMemo(() => width >= 640 && width < 768, [width]) | ||
const isLG = useMemo(() => width >= 768 && width < 1024, [width]) | ||
const isXL = useMemo(() => width >= 1024 && width < 1280, [width]) | ||
const is2XL = useMemo(() => width >= 1280 && width < 1536, [width]) | ||
|
||
return { isSM, isMD, isLG, isXL, is2XL } | ||
} |