feat(webui): add spring-based range sliders
Replace native range inputs with an accessible Radix-backed control that preserves keyboard and assistive-technology semantics. Reproduce the elastic handle, track stretch, tick visibility, and reduced-motion behavior while keeping SnowLuma theme tokens. Adopt the component for interface scale and background image controls.
This commit is contained in:
5 files changed
+774
-103
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { createContext, useContext, useId, useRef, useState, type ReactNode } from 'react';
|
||||
import { createContext, useContext, useId, useRef, useState, type ComponentProps, type ReactNode } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import {
|
||||
Accessibility, AlertTriangle, Bell, Bug, Check, Clock, Code2, Download, ExternalLink, Github, Image as ImageIcon,
|
||||
@@ -252,6 +252,27 @@ function SettingRow({
|
||||
);
|
||||
}
|
||||
|
||||
function SliderSettingRow({
|
||||
label,
|
||||
hint,
|
||||
...sliderProps
|
||||
}: {
|
||||
label: string;
|
||||
hint?: ReactNode;
|
||||
} & Omit<ComponentProps<typeof Slider>, 'label'>) {
|
||||
const hintId = useId();
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 px-5 py-4">
|
||||
<Slider
|
||||
{...sliderProps}
|
||||
label={label}
|
||||
aria-describedby={hint ? hintId : undefined}
|
||||
/>
|
||||
{hint && <p id={hintId} className="text-[12px] leading-snug text-muted-foreground">{hint}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// A settings group: a card whose header sits above a hairline-divided list of rows.
|
||||
function Group({
|
||||
title, description, icon: Icon, children,
|
||||
@@ -497,21 +518,17 @@ function AppearancePanel() {
|
||||
<SettingRow label="圆角">
|
||||
<Segmented value={a.radius} options={RADIUS_OPTIONS.map((r) => ({ value: r.value, label: r.label }))} onChange={(radius) => setAppearance({ radius })} />
|
||||
</SettingRow>
|
||||
<SettingRow label={`界面缩放(${Math.round(a.uiScale * 100)}%)`} hint="整体放大或缩小界面,适合高分屏或视力需要。" layout="stack">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-meta text-muted-foreground tabular-nums">{Math.round(UI_SCALE.min * 100)}%</span>
|
||||
<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="flex-1"
|
||||
aria-label="界面缩放"
|
||||
/>
|
||||
<span className="text-meta text-muted-foreground tabular-nums">{Math.round(UI_SCALE.max * 100)}%</span>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SliderSettingRow
|
||||
label="界面缩放"
|
||||
hint="整体放大或缩小界面,适合高分屏或视力需要。"
|
||||
min={UI_SCALE.min}
|
||||
max={UI_SCALE.max}
|
||||
step={UI_SCALE.step}
|
||||
value={a.uiScale}
|
||||
valueLabelFormat={(nextValue) => `${Math.round(nextValue * 100)}%`}
|
||||
onValueChange={(uiScale) => setAppearance({ uiScale })}
|
||||
aria-valuetext={`${Math.round(a.uiScale * 100)}%`}
|
||||
/>
|
||||
<SettingRow label="显示密度">
|
||||
<Segmented value={a.density} options={DENSITY_OPTIONS} onChange={(density) => setAppearance({ density })} />
|
||||
</SettingRow>
|
||||
@@ -660,26 +677,27 @@ function BackgroundCard({
|
||||
|
||||
{a.background.hasImage && (
|
||||
<>
|
||||
<SettingRow label={`遮罩强度(${Math.round(a.background.imageOpacity * 100)}%)`} hint="越高越能盖住壁纸、提升前景可读性。" layout="stack">
|
||||
<Slider
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={a.background.imageOpacity}
|
||||
onChange={(e) => setAppearance({ background: { imageOpacity: Number(e.target.value) } })}
|
||||
aria-label="遮罩强度"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label={`模糊(${a.background.imageBlur}px)`} layout="stack">
|
||||
<Slider
|
||||
min={0}
|
||||
max={40}
|
||||
step={1}
|
||||
value={a.background.imageBlur}
|
||||
onChange={(e) => setAppearance({ background: { imageBlur: Number(e.target.value) } })}
|
||||
aria-label="背景模糊"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SliderSettingRow
|
||||
label="遮罩强度"
|
||||
hint="越高越能盖住壁纸、提升前景可读性。"
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={a.background.imageOpacity}
|
||||
valueLabelFormat={(nextValue) => `${Math.round(nextValue * 100)}%`}
|
||||
onValueChange={(imageOpacity) => setAppearance({ background: { imageOpacity } })}
|
||||
aria-valuetext={`${Math.round(a.background.imageOpacity * 100)}%`}
|
||||
/>
|
||||
<SliderSettingRow
|
||||
label="背景模糊"
|
||||
min={0}
|
||||
max={40}
|
||||
step={1}
|
||||
value={a.background.imageBlur}
|
||||
valueLabelFormat={(nextValue) => `${nextValue}px`}
|
||||
onValueChange={(imageBlur) => setAppearance({ background: { imageBlur } })}
|
||||
aria-valuetext={`${a.background.imageBlur} 像素`}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user