feat(webui): custom scrollbars + sliders, stat-tile fit, reduce-motion
- Scrollbars: theme native scrollbars (thin, token-colored thumb) for plain overflow containers; Radix ScrollArea keeps its own custom bar (it hides the native one, so no double bar). - Sliders: new <Slider> component + `.slider` CSS replaces the native range inputs (UI scale / mask opacity / blur). Filled track + ring-bordered thumb, themed; input height matches the track so the thumb centers in every engine; Firefox fills via ::-moz-range-progress. - Stat tiles: tighten the h=1 tile (py-2 + mt-0.5) so the three text lines + padding fit the 80px cell without hugging the border. - Reduce motion: gate the always-present sidebar-width + page-transition animations to instant when enabled (Framer's reducedMotion only suppresses transforms, so these needed an explicit opt-out); kill the slider thumb transition too.
This commit is contained in:
5 files changed
+129
-16
No files matched your search
@@ -28,6 +28,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||
return appearance.sidebarDefaultCollapsed;
|
||||
});
|
||||
const customBg = appearance.background.type !== 'none';
|
||||
// Framer's reducedMotion only suppresses transforms, so the always-present
|
||||
// width + page-transition animations need an explicit opt-out to make the
|
||||
// “减少动效” setting actually felt.
|
||||
const reduce = appearance.reduceMotion;
|
||||
const { editing } = useLayout();
|
||||
// Force the sidebar open while editing layout so its drag-to-reorder list
|
||||
// has room (it returns to the user's collapsed pref on 完成).
|
||||
@@ -46,7 +50,7 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||
<motion.aside
|
||||
initial={false}
|
||||
animate={{ width: effectiveCollapsed ? 64 : 248 }}
|
||||
transition={{ type: 'spring', stiffness: 280, damping: 32 }}
|
||||
transition={reduce ? { duration: 0 } : { type: 'spring', stiffness: 280, damping: 32 }}
|
||||
className="relative h-full shrink-0 border-r overflow-hidden"
|
||||
>
|
||||
<Sidebar collapsed={effectiveCollapsed} />
|
||||
@@ -85,10 +89,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={pathname}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
initial={reduce ? false : { opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -8 }}
|
||||
transition={{ duration: 0.22, ease: [0.16, 1, 0.3, 1] }}
|
||||
exit={reduce ? { opacity: 0 } : { opacity: 0, y: -8 }}
|
||||
transition={reduce ? { duration: 0 } : { duration: 0.22, ease: [0.16, 1, 0.3, 1] }}
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
|
||||
@@ -173,7 +173,7 @@ function StatTile({
|
||||
to?: AppPath;
|
||||
}) {
|
||||
const body = (
|
||||
<CardContent className="flex h-full items-center gap-2.5 overflow-hidden px-4 py-3">
|
||||
<CardContent className="flex h-full items-center gap-2.5 overflow-hidden px-4 py-2">
|
||||
<div
|
||||
className={cn(
|
||||
'flex size-9 shrink-0 items-center justify-center rounded-xl',
|
||||
@@ -184,8 +184,8 @@ function StatTile({
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-[11px] font-medium uppercase leading-tight tracking-wider text-muted-foreground">{label}</p>
|
||||
<div className="mt-1 truncate text-[15px] font-semibold leading-tight tabular-nums">{value}</div>
|
||||
{subtext && <p className="mt-1 truncate text-[11px] leading-tight text-muted-foreground">{subtext}</p>}
|
||||
<div className="mt-0.5 truncate text-[15px] font-semibold leading-tight tabular-nums">{value}</div>
|
||||
{subtext && <p className="mt-0.5 truncate text-[11px] leading-tight text-muted-foreground">{subtext}</p>}
|
||||
</div>
|
||||
{to && <ArrowRight className="size-4 shrink-0 text-muted-foreground/60" />}
|
||||
</CardContent>
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import {
|
||||
ACCENTS,
|
||||
DEFAULT_APPEARANCE,
|
||||
@@ -361,14 +362,13 @@ function AppearancePanel() {
|
||||
<SettingRow label={`界面缩放(${Math.round(a.uiScale * 100)}%)`} hint="整体放大或缩小界面,适合高分屏或视力需要。" layout="stack">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-[11px] text-muted-foreground tabular-nums">{Math.round(UI_SCALE.min * 100)}%</span>
|
||||
<input
|
||||
type="range"
|
||||
<Slider
|
||||
min={UI_SCALE.min}
|
||||
max={UI_SCALE.max}
|
||||
step={UI_SCALE.step}
|
||||
value={a.uiScale}
|
||||
onChange={(e) => setAppearance({ uiScale: Number(e.target.value) })}
|
||||
className="h-2 flex-1 cursor-pointer accent-primary"
|
||||
className="flex-1"
|
||||
aria-label="界面缩放"
|
||||
/>
|
||||
<span className="text-[11px] text-muted-foreground tabular-nums">{Math.round(UI_SCALE.max * 100)}%</span>
|
||||
@@ -506,26 +506,22 @@ function BackgroundCard({
|
||||
{a.background.hasImage && (
|
||||
<>
|
||||
<SettingRow label={`遮罩强度(${Math.round(a.background.imageOpacity * 100)}%)`} hint="越高越能盖住壁纸、提升前景可读性。" layout="stack">
|
||||
<input
|
||||
type="range"
|
||||
<Slider
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={a.background.imageOpacity}
|
||||
onChange={(e) => setAppearance({ background: { imageOpacity: Number(e.target.value) } })}
|
||||
className="h-2 w-full cursor-pointer accent-primary"
|
||||
aria-label="遮罩强度"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label={`模糊(${a.background.imageBlur}px)`} layout="stack">
|
||||
<input
|
||||
type="range"
|
||||
<Slider
|
||||
min={0}
|
||||
max={40}
|
||||
step={1}
|
||||
value={a.background.imageBlur}
|
||||
onChange={(e) => setAppearance({ background: { imageBlur: Number(e.target.value) } })}
|
||||
className="h-2 w-full cursor-pointer accent-primary"
|
||||
aria-label="背景模糊"
|
||||
/>
|
||||
</SettingRow>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'value'> {
|
||||
value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Themed range input. Styling lives in index.css (`.slider`); here we just
|
||||
* compute the filled-track percentage and expose it as `--slider-pct` for the
|
||||
* WebKit track gradient (Firefox fills natively via ::-moz-range-progress).
|
||||
*/
|
||||
export function Slider({ value, min, max, className, style, ...props }: SliderProps) {
|
||||
const pct = max > min ? Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100)) : 0;
|
||||
return (
|
||||
<input
|
||||
type="range"
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
className={cn('slider', className)}
|
||||
style={{ '--slider-pct': `${pct}%`, ...style } as React.CSSProperties}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user