Skip to content

Commit 1741300

Browse files
committed
Shift content for pinned navigation
1 parent 4dd42cc commit 1741300

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎app/globals.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ img { display: block; max-width: 100%; }
3232
button, a, summary { -webkit-tap-highlight-color: transparent; }
3333
::selection { color: var(--white); background: var(--blue); }
3434

35+
main > section { transition: margin-left 360ms cubic-bezier(0.22, 1, 0.36, 1); }
36+
3537
.section-shell { width: min(var(--shell), calc(100% - 56px)); margin-inline: auto; }
3638
#focus, #research, #experience, #projects, #opensource, #contact { scroll-margin-top: 84px; }
3739

@@ -319,6 +321,10 @@ button, a, summary { -webkit-tap-highlight-color: transparent; }
319321
.opensource-row > p:first-of-type { display: none; }
320322
}
321323

324+
@media (min-width: 1161px) {
325+
html.nav-layout-pinned main > section { margin-left: 300px; }
326+
}
327+
322328
@media (max-width: 820px) {
323329
.section-shell { width: min(100% - 32px, var(--shell)); }
324330
.site-nav { min-height: 68px; padding-inline: 16px; }

‎app/navigation-shell.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export default function NavigationShell() {
4949
}
5050
}, [pinned]);
5151

52+
useEffect(() => {
53+
document.documentElement.classList.toggle('nav-layout-pinned', pinned);
54+
return () => document.documentElement.classList.remove('nav-layout-pinned');
55+
}, [pinned]);
56+
5257
useEffect(() => {
5358
const handleEscape = (event: KeyboardEvent) => {
5459
if (event.key === 'Escape') {
@@ -83,7 +88,7 @@ export default function NavigationShell() {
8388
<aside id="side-navigation" className="side-nav-panel" aria-label="页面导航" aria-hidden={!visible} onMouseEnter={() => setHovering(true)} onMouseLeave={closeIfFloating}>
8489
<div className="side-nav-head"><div><span>NAVIGATION</span><strong>页面导航</strong></div><div><button type="button" aria-label={pinned ? '取消固定导航' : '固定导航'} aria-pressed={pinned} onClick={() => { setPinned((value) => !value); setOpen(true); }}>{pinned ? <PiPushPinSlashBold aria-hidden="true" /> : <PiPushPinBold aria-hidden="true" />}</button><button type="button" aria-label="收起导航" onClick={() => { setPinned(false); setOpen(false); setHovering(false); }}><PiXBold aria-hidden="true" /></button></div></div>
8590
<nav>{navigationItems.map((item, index) => { const Icon = item.icon; return <a href={item.href} key={item.href} tabIndex={visible ? 0 : -1} onClick={closeIfFloating}><span>{String(index + 1).padStart(2, '0')}</span><Icon aria-hidden="true" /><span><strong>{item.label}</strong><small>{item.english}</small></span></a>; })}</nav>
86-
<p><span />移到左侧边缘可临时展开;固定后导航会保持打开。</p>
91+
<p><span />移到左侧边缘可临时展开;固定后页面会自动为导航让位。</p>
8792
</aside>
8893
</div>
8994
<button className={`side-nav-backdrop${visible ? ' is-visible' : ''}`} type="button" aria-label="关闭导航" tabIndex={visible ? 0 : -1} onClick={() => { setPinned(false); setOpen(false); setHovering(false); }} />

0 commit comments

Comments
 (0)