mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 12:29:31 +08:00
fix(settings): reuse the app scrim and keep the rail exit legible
The card's scrim was an 18% foreground tint, which turns into a cream veil in the dark theme; the shell now reuses var(--overlay) like Modal, so the dimming is the same colour the rest of the app uses in both themes. The 224px rail had no room for a title and a labelled back button once a locale spells both long, so the rail keeps an icon-only exit (aria-label kept) and the phone header keeps the label. The rail's section list is taller than the card, so it now shows a bottom fade while there is more to scroll and drops it at the end, instead of leaving the last row sliced in half with no cue.
This commit is contained in:
committed by
qiuqianyi66
parent
d4a6fd344b
commit
a660c30f1e
@@ -72,11 +72,26 @@ export default function SettingsMain({ children }: { children: React.ReactNode }
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || applying}
|
||||
onClick={() => (hasUnsavedChanges ? setLeaving(true) : returnToApp())}
|
||||
className="flex items-center gap-2 rounded-md px-2.5 py-1.5 text-[13px] font-medium text-foreground outline-none transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:opacity-40"
|
||||
onClick={requestClose}
|
||||
className="flex min-w-0 items-center gap-2 justify-self-start rounded-md px-2.5 py-1.5 text-[13px] font-medium text-foreground outline-none transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:opacity-40"
|
||||
>
|
||||
<ArrowLeft size={16} strokeWidth={1.7} className="shrink-0" />
|
||||
<span className="truncate">{t('Back to app')}</span>
|
||||
</button>
|
||||
)
|
||||
// The 224px rail has no room for "Settings" and a labelled back button side
|
||||
// by side once a locale spells both long ("Einstellungen" / "Zurück zur
|
||||
// App"), so the rail keeps the title and gives the exit an icon with a
|
||||
// tooltip. The phone header has the width and keeps the label.
|
||||
const railReturnButton = (
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || applying}
|
||||
aria-label={t('Back to app')}
|
||||
onClick={requestClose}
|
||||
className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--muted-foreground)] outline-none transition-colors hover:bg-accent hover:text-[var(--foreground)] focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:opacity-40"
|
||||
>
|
||||
<ArrowLeft size={16} strokeWidth={1.7} />
|
||||
{t('Back to app')}
|
||||
</button>
|
||||
)
|
||||
|
||||
@@ -86,7 +101,7 @@ export default function SettingsMain({ children }: { children: React.ReactNode }
|
||||
// its own rounded edge, so opening settings no longer replaces the whole
|
||||
// window. Phones have no room for a floating card and get the full sheet.
|
||||
<div
|
||||
className="fixed inset-0 flex items-center justify-center overflow-hidden bg-[color-mix(in_srgb,var(--foreground)_18%,transparent)] p-0 md:p-6"
|
||||
className="fixed inset-0 flex items-center justify-center overflow-hidden bg-[var(--overlay)] p-0 md:p-6"
|
||||
data-settings-shell
|
||||
onMouseDown={event => {
|
||||
// Clicking the scrim behaves like Escape: leave settings, but never
|
||||
@@ -99,11 +114,11 @@ export default function SettingsMain({ children }: { children: React.ReactNode }
|
||||
className="flex h-dvh w-full min-w-0 flex-col overflow-hidden bg-[var(--background)] md:h-[min(820px,88dvh)] md:w-[min(1080px,94vw)] md:rounded-2xl md:border md:border-[color-mix(in_srgb,var(--border)_70%,transparent)] md:shadow-[0_28px_70px_-32px_rgba(0,0,0,0.45)] lg:flex-row"
|
||||
>
|
||||
<aside className="hidden w-[224px] shrink-0 flex-col border-r border-[color-mix(in_srgb,var(--border)_55%,transparent)] bg-[color-mix(in_srgb,var(--muted)_18%,var(--background))] lg:flex">
|
||||
<div className="flex items-center justify-between gap-1 px-4 pb-2 pt-4">
|
||||
<p className="truncate text-[14px] font-semibold text-[var(--foreground)]">
|
||||
<div className="flex items-center justify-between gap-2 px-4 pb-2 pt-4">
|
||||
<p className="min-w-0 truncate text-[14px] font-semibold text-[var(--foreground)]">
|
||||
{t('Settings')}
|
||||
</p>
|
||||
{returnButton}
|
||||
{railReturnButton}
|
||||
</div>
|
||||
<SettingsNav />
|
||||
</aside>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { Search, X } from 'lucide-react'
|
||||
@@ -26,9 +26,32 @@ export default function SettingsNav({ onNavigate }: { onNavigate?: () => void })
|
||||
const access = useSettingsAccess()
|
||||
const pages = visibleSettingsPages(access)
|
||||
const [query, setQuery] = useState('')
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const [moreBelow, setMoreBelow] = useState(false)
|
||||
const needle = query.trim().toLocaleLowerCase()
|
||||
const currentKey = pathname.split('/')[2] || 'general'
|
||||
const currentFamily = settingsPageFamily(currentKey)
|
||||
|
||||
// The rail carries more sections than a 820px card can show (Search plus
|
||||
// five groups runs past the viewport), so the list scrolls. Without a cue the
|
||||
// last visible row is simply cut in half and reads as broken layout; the fade
|
||||
// only appears while there is actually more to scroll to, and disappears at
|
||||
// the end so the final row stays fully legible.
|
||||
useEffect(() => {
|
||||
const el = listRef.current
|
||||
if (!el) return
|
||||
const update = () =>
|
||||
setMoreBelow(el.scrollHeight - el.clientHeight - el.scrollTop > 8)
|
||||
update()
|
||||
el.addEventListener('scroll', update, { passive: true })
|
||||
const observer =
|
||||
typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(update)
|
||||
observer?.observe(el)
|
||||
return () => {
|
||||
el.removeEventListener('scroll', update)
|
||||
observer?.disconnect()
|
||||
}
|
||||
}, [needle])
|
||||
const matches = pages.filter(page => {
|
||||
const navLabel = settingsPageLabel(page.key, page.label)
|
||||
return [
|
||||
@@ -90,43 +113,51 @@ export default function SettingsNav({ onNavigate }: { onNavigate?: () => void })
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-2.5 pb-6">
|
||||
{groups
|
||||
.filter(group => group.pages.length)
|
||||
.map(group => (
|
||||
<div key={group.label} className="mb-0.5">
|
||||
<p className="px-2.5 pb-1.5 pt-5 text-[12px] font-medium text-muted-foreground">
|
||||
{t(group.label)}
|
||||
</p>
|
||||
<div className="space-y-0.5">
|
||||
{group.pages.map(page => {
|
||||
const Icon = needle ? page.icon : settingsPageIcon(page.key, page.icon)
|
||||
const active = needle ? page.key === currentKey : currentFamily.includes(page.key)
|
||||
return (
|
||||
<Tooltip key={page.key} label={t(page.blurb)} as="div" side="right">
|
||||
<Link
|
||||
href={settingsAnchorHref(page.key)}
|
||||
scroll={false}
|
||||
onClick={onNavigate}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
data-tour={`tour-nav-${page.key}`}
|
||||
className={`flex min-h-9 items-center gap-2 rounded-lg px-2.5 py-2 text-[13px] outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[var(--ring)] ${active ? 'bg-[var(--accent)] font-medium text-[var(--foreground)]' : 'text-[var(--foreground)] hover:bg-accent/60'}`}
|
||||
>
|
||||
<Icon size={15} strokeWidth={1.8} className="shrink-0" />
|
||||
<span>
|
||||
{t(needle ? page.label : settingsPageLabel(page.key, page.label))}
|
||||
</span>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
)
|
||||
})}
|
||||
<div className="relative min-h-0 flex-1">
|
||||
<div ref={listRef} className="h-full overflow-y-auto px-2.5 pb-6">
|
||||
{groups
|
||||
.filter(group => group.pages.length)
|
||||
.map(group => (
|
||||
<div key={group.label} className="mb-0.5">
|
||||
<p className="px-2.5 pb-1.5 pt-5 text-[12px] font-medium text-muted-foreground">
|
||||
{t(group.label)}
|
||||
</p>
|
||||
<div className="space-y-0.5">
|
||||
{group.pages.map(page => {
|
||||
const Icon = needle ? page.icon : settingsPageIcon(page.key, page.icon)
|
||||
const active = needle ? page.key === currentKey : currentFamily.includes(page.key)
|
||||
return (
|
||||
<Tooltip key={page.key} label={t(page.blurb)} as="div" side="right">
|
||||
<Link
|
||||
href={settingsAnchorHref(page.key)}
|
||||
scroll={false}
|
||||
onClick={onNavigate}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
data-tour={`tour-nav-${page.key}`}
|
||||
className={`flex min-h-9 items-center gap-2 rounded-lg px-2.5 py-2 text-[13px] outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[var(--ring)] ${active ? 'bg-[var(--accent)] font-medium text-[var(--foreground)]' : 'text-[var(--foreground)] hover:bg-accent/60'}`}
|
||||
>
|
||||
<Icon size={15} strokeWidth={1.8} className="shrink-0" />
|
||||
<span>
|
||||
{t(needle ? page.label : settingsPageLabel(page.key, page.label))}
|
||||
</span>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{needle && !matches.length && (
|
||||
<p className="px-2.5 py-5 text-[13px] text-[var(--muted-foreground)]">
|
||||
{t('No settings match “{{query}}”.', { query: query.trim() })}
|
||||
</p>
|
||||
))}
|
||||
{needle && !matches.length && (
|
||||
<p className="px-2.5 py-5 text-[13px] text-[var(--muted-foreground)]">
|
||||
{t('No settings match “{{query}}”.', { query: query.trim() })}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{moreBelow && (
|
||||
<div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-[color-mix(in_srgb,var(--muted)_18%,var(--background))] to-transparent"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
Reference in New Issue
Block a user