feat(web): PC 响应式侧栏与加宽网格
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
045d4306c8
commit
2cf42c3fd9
@ -18,8 +18,8 @@ npm run preview
|
|||||||
|
|
||||||
## 能力
|
## 能力
|
||||||
|
|
||||||
- 整页长滚动浏览全部入口(图标 + 标题 + 简介)
|
- **移动端**:整页长滚动 + 左侧抽屉跳转分类
|
||||||
- 左侧抽屉可快速跳到某一分类
|
- **PC(≥960px)**:左侧常驻分类栏、加宽内容区、4~5 列入口网格
|
||||||
- 顶栏随滚动显示当前分类
|
- 顶栏随滚动显示当前分类
|
||||||
- 浅色 / 深色主题记忆
|
- 浅色 / 深色主题记忆
|
||||||
- 回到顶部
|
- 回到顶部
|
||||||
|
|||||||
137
src/App.tsx
137
src/App.tsx
@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|||||||
import { CategoryPanel } from './components/CategoryPanel'
|
import { CategoryPanel } from './components/CategoryPanel'
|
||||||
import { SideDrawer } from './components/SideDrawer'
|
import { SideDrawer } from './components/SideDrawer'
|
||||||
import config from './data/links.json'
|
import config from './data/links.json'
|
||||||
import type { NavConfig, NavLink } from './types'
|
import type { NavCategory, NavConfig, NavLink } from './types'
|
||||||
|
|
||||||
const nav = config as NavConfig
|
const nav = config as NavConfig
|
||||||
|
|
||||||
@ -16,6 +16,10 @@ function readTheme(): Theme {
|
|||||||
: 'light'
|
: 'light'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function countLinks(cat: NavCategory) {
|
||||||
|
return cat.groups.reduce((s, g) => s + g.links.length, 0)
|
||||||
|
}
|
||||||
|
|
||||||
function IconMenu({ open }: { open: boolean }) {
|
function IconMenu({ open }: { open: boolean }) {
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
@ -99,6 +103,16 @@ export default function App() {
|
|||||||
return () => window.clearTimeout(id)
|
return () => window.clearTimeout(id)
|
||||||
}, [toast])
|
}, [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(() => {
|
useEffect(() => {
|
||||||
const sections = nav.categories
|
const sections = nav.categories
|
||||||
.map((c) => document.getElementById(`cat-${c.id}`))
|
.map((c) => document.getElementById(`cat-${c.id}`))
|
||||||
@ -173,45 +187,85 @@ export default function App() {
|
|||||||
<span className="orb orb-c" />
|
<span className="orb orb-c" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<header className="topbar sticky-stack">
|
<aside className="desktop-rail" aria-label="分类导航">
|
||||||
<div className="brand-row">
|
<div className="desktop-rail-brand">
|
||||||
<button
|
<img src="/icons/_brand.webp" alt="" width={32} height={32} />
|
||||||
type="button"
|
<div>
|
||||||
className={`icon-btn menu-trigger${drawerOpen ? ' open' : ''}`}
|
<span className="desktop-rail-title">{nav.brand}</span>
|
||||||
aria-label="打开分类"
|
<span className="desktop-rail-sub">{nav.tagline}</span>
|
||||||
aria-expanded={drawerOpen}
|
|
||||||
onClick={() => setDrawerOpen(true)}
|
|
||||||
>
|
|
||||||
<IconMenu open={drawerOpen} />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div className="brand-mark">
|
|
||||||
<img
|
|
||||||
className="brand-logo"
|
|
||||||
src="/icons/_brand.webp"
|
|
||||||
alt=""
|
|
||||||
width={28}
|
|
||||||
height={28}
|
|
||||||
/>
|
|
||||||
<div className="brand-text">
|
|
||||||
<h1 className="brand-name">{nav.brand}</h1>
|
|
||||||
<p key={pillKey} className="brand-current">
|
|
||||||
{activeCategory.title}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
|
||||||
ref={themeBtnRef}
|
|
||||||
type="button"
|
|
||||||
className="icon-btn theme-trigger"
|
|
||||||
aria-label={theme === 'dark' ? '切换浅色' : '切换深色'}
|
|
||||||
onClick={toggleTheme}
|
|
||||||
>
|
|
||||||
{theme === 'dark' ? <IconSun /> : <IconMoon />}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
<nav className="desktop-rail-nav">
|
||||||
|
{nav.categories.map((cat) => {
|
||||||
|
const count = countLinks(cat)
|
||||||
|
const active = cat.id === activeCategory.id
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={cat.id}
|
||||||
|
type="button"
|
||||||
|
className={`desktop-rail-item${active ? ' active' : ''}`}
|
||||||
|
aria-current={active ? 'page' : undefined}
|
||||||
|
onClick={() => onSelectCategory(cat.id)}
|
||||||
|
>
|
||||||
|
<span className="desktop-rail-emoji" aria-hidden>
|
||||||
|
{cat.emoji}
|
||||||
|
</span>
|
||||||
|
<span className="desktop-rail-item-title">{cat.title}</span>
|
||||||
|
<span className="desktop-rail-item-count">{count}</span>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<div className="desktop-main">
|
||||||
|
<header className="topbar sticky-stack">
|
||||||
|
<div className="brand-row">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`icon-btn menu-trigger${drawerOpen ? ' open' : ''}`}
|
||||||
|
aria-label="打开分类"
|
||||||
|
aria-expanded={drawerOpen}
|
||||||
|
onClick={() => setDrawerOpen(true)}
|
||||||
|
>
|
||||||
|
<IconMenu open={drawerOpen} />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="brand-mark">
|
||||||
|
<img
|
||||||
|
className="brand-logo"
|
||||||
|
src="/icons/_brand.webp"
|
||||||
|
alt=""
|
||||||
|
width={28}
|
||||||
|
height={28}
|
||||||
|
/>
|
||||||
|
<div className="brand-text">
|
||||||
|
<h1 className="brand-name">{nav.brand}</h1>
|
||||||
|
<p key={pillKey} className="brand-current">
|
||||||
|
{activeCategory.title}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
ref={themeBtnRef}
|
||||||
|
type="button"
|
||||||
|
className="icon-btn theme-trigger"
|
||||||
|
aria-label={theme === 'dark' ? '切换浅色' : '切换深色'}
|
||||||
|
onClick={toggleTheme}
|
||||||
|
>
|
||||||
|
{theme === 'dark' ? <IconSun /> : <IconMoon />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main className="page">
|
||||||
|
{nav.categories.map((cat) => (
|
||||||
|
<CategoryPanel key={cat.id} category={cat} onOpen={onOpen} />
|
||||||
|
))}
|
||||||
|
<footer className="footer">{nav.footer}</footer>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
<SideDrawer
|
<SideDrawer
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
@ -223,13 +277,6 @@ export default function App() {
|
|||||||
onSelect={onSelectCategory}
|
onSelect={onSelectCategory}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<main className="page">
|
|
||||||
{nav.categories.map((cat) => (
|
|
||||||
<CategoryPanel key={cat.id} category={cat} onOpen={onOpen} />
|
|
||||||
))}
|
|
||||||
<footer className="footer">{nav.footer}</footer>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`back-top${showTop ? ' show' : ''}`}
|
className={`back-top${showTop ? ' show' : ''}`}
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
--font-body: 'Manrope', 'PingFang SC', 'Noto Sans SC', system-ui, sans-serif;
|
--font-body: 'Manrope', 'PingFang SC', 'Noto Sans SC', system-ui, sans-serif;
|
||||||
--radius: 14px;
|
--radius: 14px;
|
||||||
--max-w: 560px;
|
--max-w: 560px;
|
||||||
|
--rail-w: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme='dark'] {
|
[data-theme='dark'] {
|
||||||
@ -95,6 +96,16 @@ button {
|
|||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.desktop-rail {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-main {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.bg-glow {
|
.bg-glow {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@ -925,6 +936,265 @@ html {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* —— PC / 宽屏:常驻侧栏 + 加宽内容 —— */
|
||||||
|
@media (min-width: 960px) {
|
||||||
|
:root,
|
||||||
|
[data-theme='light'],
|
||||||
|
[data-theme='dark'] {
|
||||||
|
--max-w: 1040px;
|
||||||
|
--rail-w: 248px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: var(--rail-w) minmax(0, 1fr);
|
||||||
|
width: min(100%, calc(var(--rail-w) + var(--max-w)));
|
||||||
|
margin: 0 auto;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
height: 100dvh;
|
||||||
|
z-index: 20;
|
||||||
|
padding: 22px 14px 20px;
|
||||||
|
border-right: 1px solid var(--line);
|
||||||
|
background:
|
||||||
|
linear-gradient(
|
||||||
|
180deg,
|
||||||
|
color-mix(in srgb, var(--accent) 7%, var(--bg-elevated)),
|
||||||
|
var(--bg-elevated) 36%
|
||||||
|
),
|
||||||
|
var(--bg-elevated);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-brand {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 4px 8px 18px;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-brand img {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 11px;
|
||||||
|
object-fit: cover;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-title {
|
||||||
|
display: block;
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.05rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.03em;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-sub {
|
||||||
|
display: block;
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: var(--ink-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-nav {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 10px 4px 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 12px;
|
||||||
|
text-align: left;
|
||||||
|
color: var(--ink-muted);
|
||||||
|
transition:
|
||||||
|
background 0.18s ease,
|
||||||
|
color 0.18s ease,
|
||||||
|
transform 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-item:hover {
|
||||||
|
background: var(--chip);
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-item.active {
|
||||||
|
background: var(--chip-active);
|
||||||
|
color: var(--chip-active-ink);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-emoji {
|
||||||
|
width: 1.2em;
|
||||||
|
text-align: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-item-title {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 650;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-rail-item-count {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 2px 7px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: color-mix(in srgb, currentColor 12%, transparent);
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-trigger {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-root {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sticky-stack {
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
padding: 14px 28px 14px 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark img,
|
||||||
|
.brand-logo {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-name {
|
||||||
|
font-size: 1.12rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-current {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
padding: 22px 28px 96px 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-panel + .cat-panel {
|
||||||
|
margin-top: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-heading h2 {
|
||||||
|
font-size: 1.28rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cat-count {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
padding: 3px 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-title {
|
||||||
|
font-size: 0.76rem;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-grid {
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card {
|
||||||
|
padding: 12px;
|
||||||
|
gap: 10px;
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card:active {
|
||||||
|
transform: translateY(0) scale(0.99);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-icon-wrap {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-title {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-desc {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
white-space: normal;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
margin-top: 40px;
|
||||||
|
font-size: 0.76rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-top {
|
||||||
|
right: max(24px, calc((100vw - (var(--rail-w) + var(--max-w))) / 2 + 24px));
|
||||||
|
bottom: 28px;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1280px) {
|
||||||
|
:root,
|
||||||
|
[data-theme='light'],
|
||||||
|
[data-theme='dark'] {
|
||||||
|
--max-w: 1180px;
|
||||||
|
--rail-w: 268px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-grid {
|
||||||
|
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
padding: 26px 36px 110px 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
padding: 16px 36px 16px 28px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
.bg-glow::after,
|
.bg-glow::after,
|
||||||
.orb,
|
.orb,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user