diff --git a/README.md b/README.md index ab4e756..bcad4be 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ npm run preview ## 能力 -- 整页长滚动浏览全部入口(图标 + 标题 + 简介) -- 左侧抽屉可快速跳到某一分类 +- **移动端**:整页长滚动 + 左侧抽屉跳转分类 +- **PC(≥960px)**:左侧常驻分类栏、加宽内容区、4~5 列入口网格 - 顶栏随滚动显示当前分类 - 浅色 / 深色主题记忆 - 回到顶部 diff --git a/src/App.tsx b/src/App.tsx index 81449b3..abc034a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { CategoryPanel } from './components/CategoryPanel' import { SideDrawer } from './components/SideDrawer' import config from './data/links.json' -import type { NavConfig, NavLink } from './types' +import type { NavCategory, NavConfig, NavLink } from './types' const nav = config as NavConfig @@ -16,6 +16,10 @@ function readTheme(): Theme { : 'light' } +function countLinks(cat: NavCategory) { + return cat.groups.reduce((s, g) => s + g.links.length, 0) +} + function IconMenu({ open }: { open: boolean }) { return ( window.clearTimeout(id) }, [toast]) + useEffect(() => { + const mq = window.matchMedia('(min-width: 960px)') + const onChange = () => { + if (mq.matches) setDrawerOpen(false) + } + onChange() + mq.addEventListener('change', onChange) + return () => mq.removeEventListener('change', onChange) + }, []) + useEffect(() => { const sections = nav.categories .map((c) => document.getElementById(`cat-${c.id}`)) @@ -173,45 +187,85 @@ export default function App() { -
-
- - -
- -
-

{nav.brand}

-

- {activeCategory.title} -

-
+
+ + + +
+
+
+ + +
+ +
+

{nav.brand}

+

+ {activeCategory.title} +

+
+
+ + +
+
+ +
+ {nav.categories.map((cat) => ( + + ))} +
{nav.footer}
+
+
-
- {nav.categories.map((cat) => ( - - ))} - -
-