From 80801043118d901014abbf865d2bb1b2915f1453 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 1 Aug 2026 00:40:09 +0800 Subject: [PATCH] refactor(webui): refine onboarding layout Give agreement reading and password setup a calmer responsive layout.\n\nKeep existing motion behavior while aligning actions and improving mobile form ergonomics. --- .../components/interior/floating-label.tsx | 6 +- .../src/components/interior/wizard-steps.tsx | 99 +++++++++++---- .../components/pages/change-password-form.tsx | 73 +++++++---- .../pages/onboarding-wizard-page.tsx | 115 ++++++++++++------ 4 files changed, 200 insertions(+), 93 deletions(-) diff --git a/packages/webui/src/components/interior/floating-label.tsx b/packages/webui/src/components/interior/floating-label.tsx index e952edda..991fc372 100644 --- a/packages/webui/src/components/interior/floating-label.tsx +++ b/packages/webui/src/components/interior/floating-label.tsx @@ -191,7 +191,7 @@ export function FloatingLabelInput({
@@ -249,7 +249,7 @@ export function FloatingLabelInput({ }} transition={move} style={{ originX: 0, originY: 0, willChange: "transform" }} - className={`absolute left-3 top-[32px] block cursor-text select-none text-[13px] leading-[16px] ${ + className={`absolute left-3 top-[32px] block cursor-text select-none text-base leading-5 sm:text-[13px] sm:leading-[16px] ${ invalid ? "text-destructive" : raised diff --git a/packages/webui/src/components/interior/wizard-steps.tsx b/packages/webui/src/components/interior/wizard-steps.tsx index 03d59e07..14f88b17 100644 --- a/packages/webui/src/components/interior/wizard-steps.tsx +++ b/packages/webui/src/components/interior/wizard-steps.tsx @@ -1,7 +1,7 @@ "use client"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import type { KeyboardEvent, ReactNode } from "react"; +import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react"; +import type { CSSProperties, KeyboardEvent, ReactNode } from "react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; const EASE = [0.23, 1, 0.32, 1] as const; @@ -94,8 +94,28 @@ export type WizardStep = { canSkip?: boolean; onSkip?: () => void; hideAdvance?: boolean; + hideBack?: boolean; + scrollMode?: "panel" | "content"; }; +export type WizardNavigationControls = { + back: () => void; + next: () => void; + goTo: (index: number) => void; + index: number; + total: number; + isFirst: boolean; + isLast: boolean; +}; + +const WizardNavigationContext = createContext(null); + +export function useWizardNavigation(): WizardNavigationControls { + const controls = useContext(WizardNavigationContext); + if (!controls) throw new Error("useWizardNavigation must be used inside "); + return controls; +} + export type WizardStepsProps = { steps: WizardStep[]; index?: number; @@ -103,7 +123,7 @@ export type WizardStepsProps = { onIndexChange?: (index: number, direction: WizardDirection) => void; onComplete?: () => void; complete?: boolean; - height?: number; + height?: CSSProperties["height"]; backLabel?: string; nextLabel?: string; finishLabel?: string; @@ -112,6 +132,8 @@ export type WizardStepsProps = { completeHint?: string; label?: string; className?: string; + spacious?: boolean; + fill?: boolean; }; export function WizardSteps({ @@ -130,6 +152,8 @@ export function WizardSteps({ completeHint = "Step back to change anything", label = "Steps", className = "", + spacious = false, + fill = false, }: WizardStepsProps) { const wizard = useWizard({ total: steps.length, @@ -206,13 +230,32 @@ export function WizardSteps({ if (!step) return null; const position = `Step ${at + 1} of ${total}: ${step.label}`; + const navigation = { + back: () => { + intent.current = "panel"; + back(); + }, + next: () => { + if (!isLast) intent.current = "panel"; + next(); + }, + goTo, + index: at, + total, + isFirst, + isLast, + } satisfies WizardNavigationControls; + const showBack = !isFirst && !step.hideBack; + const showSkip = Boolean(step.canSkip); + const showAdvance = !complete && !step.hideAdvance; + const showNavigation = showBack || showSkip || showAdvance; return ( -
+

{position}

{steps.map((candidate, stepIndex) => ( {steps.map((candidate, stepIndex) => { const done = complete || stepIndex < at; @@ -279,7 +322,7 @@ export function WizardSteps({ intent.current = "list"; goTo(stepIndex); }} - className="rounded-[8px] outline-none focus-visible:shadow-[0_0_0_1.5px_var(--ring)]" + className="relative rounded-[8px] outline-none after:absolute after:-inset-2 after:content-[''] focus-visible:shadow-[0_0_0_1.5px_var(--ring)]" > {tile} @@ -314,8 +357,12 @@ export function WizardSteps({ tabIndex={-1} role="group" aria-label={position} - style={{ height }} - className="relative overflow-hidden rounded-[11px] border border-border bg-card shadow-sm outline-none transition-[border-color,box-shadow] duration-150 focus-visible:border-ring" + style={{ height: fill ? undefined : height }} + className={`${fill ? "min-h-0 flex-1" : ""} relative overflow-hidden border border-border bg-card outline-none transition-[border-color,box-shadow] duration-150 focus-visible:border-ring ${ + spacious + ? "rounded-[24px] shadow-[0_0_0_1px_rgb(255_255_255/0.02),0_18px_50px_rgb(0_0_0/0.12)]" + : "rounded-[11px] shadow-sm" + }`} > {complete ? (
@@ -335,14 +384,16 @@ export function WizardSteps({

{completeHint}

) : ( - step.content + + {step.content} + )}
-
+ {showNavigation ?
- {isFirst ? null : ( + {showBack ? ( { - intent.current = "panel"; - back(); + navigation.back(); }} - className="h-9 rounded-[9px] border border-border bg-background px-3 text-[13px] font-medium text-foreground outline-none transition-[border-color,box-shadow] duration-150 hover:border-foreground/20 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40" + className={`${spacious ? "h-11 px-4 text-sm" : "h-9 px-3 text-[13px]"} rounded-[9px] border border-border bg-background font-medium text-foreground outline-none transition-[border-color,box-shadow] duration-150 hover:border-foreground/20 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40`} > {backLabel} - )} + ) : null} - {step.canSkip ? ( + {showSkip ? ( {skipLabel} ) : null} - {complete || step.hideAdvance ? null : ( + {showAdvance ? ( { - if (!isLast) intent.current = "panel"; - next(); + navigation.next(); }} initial={{ opacity: 0, scale: 0.96 }} animate={{ opacity: 1, scale: 1 }} @@ -404,7 +453,7 @@ export function WizardSteps({ : { duration: 0.14, ease: EXIT_EASE }, }} transition={reduced ? { duration: 0 } : CROSSFADE} - className="ml-auto grid h-9 place-items-center rounded-[9px] bg-foreground px-3.5 text-[13px] font-medium text-background outline-none focus-visible:shadow-[inset_0_0_0_1.5px_var(--ring)]" + className={`${spacious ? "h-11 px-4 text-sm" : "h-9 px-3.5 text-[13px]"} ml-auto grid place-items-center rounded-[9px] bg-foreground font-medium text-background outline-none focus-visible:shadow-[inset_0_0_0_1.5px_var(--ring)]`} > {finishLabel.length > nextLabel.length ? finishLabel : nextLabel} @@ -428,9 +477,9 @@ export function WizardSteps({ {finishLabel} - )} + ) : null} -
+
: null}
); } diff --git a/packages/webui/src/components/pages/change-password-form.tsx b/packages/webui/src/components/pages/change-password-form.tsx index 0052e57d..89f47306 100644 --- a/packages/webui/src/components/pages/change-password-form.tsx +++ b/packages/webui/src/components/pages/change-password-form.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from 'react'; +import { useEffect, useMemo, useState, type ReactNode } from 'react'; import { AnimatePresence, motion } from 'motion/react'; import { Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; @@ -10,6 +10,7 @@ import { import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon'; import { actionErrorMessage, useActionFeedback } from '@/contexts/ActionFeedbackContext'; import { useTheme } from '@/contexts/ThemeContext'; +import { cn } from '@/lib/utils'; export interface PasswordRule { id: string; @@ -28,6 +29,8 @@ const EMPTY_RULES: readonly PasswordRule[] = [ const STRENGTH_LABELS = ['未输入', '很弱', '较弱', '一般', '良好', '强'] as const; export interface ChangePasswordFormProps { + /** Selects whether the form changes credentials or only rehearses validation. */ + mode?: 'change' | 'rehearsal'; /** * When provided, the "current password" field is omitted entirely and this * value is used as the old password. @@ -51,9 +54,16 @@ export interface ChangePasswordFormProps { /** Disambiguates input ids if two instances ever mount at once. */ idPrefix?: string; submitLabel?: string; + className?: string; + renderActions?: (state: { + canSubmit: boolean; + submitting: boolean; + submitLabel: string; + }) => ReactNode; } export function ChangePasswordForm({ + mode = 'change', knownOldPassword, checkStrength, submit, @@ -61,8 +71,11 @@ export function ChangePasswordForm({ onCancel, idPrefix = 'cpw', submitLabel = '保存新密码', + className, + renderActions, }: ChangePasswordFormProps) { - const carriesOld = knownOldPassword !== undefined; + const rehearsing = mode === 'rehearsal'; + const carriesOld = rehearsing || knownOldPassword !== undefined; const { runAction } = useActionFeedback(); const { appearance } = useTheme(); const reduceMotion = appearance.reduceMotion || appearance.disableMotion; @@ -85,7 +98,7 @@ export function ChangePasswordForm({ const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(''); - const effectiveOld = carriesOld ? (knownOldPassword as string) : oldPassword; + const effectiveOld = rehearsing ? '' : carriesOld ? (knownOldPassword as string) : oldPassword; const checkedCurrentPassword = strengthResult.password === newPassword; const valid = checkedCurrentPassword && strengthResult.valid; const strengthError = strengthFailure?.password === newPassword @@ -106,7 +119,11 @@ export function ChangePasswordForm({ ); const confirmMatches = newPassword.length > 0 && newPassword === confirmPassword; const canSubmit = - !submitting && effectiveOld.length > 0 && valid && confirmMatches && effectiveOld !== newPassword; + !submitting + && (rehearsing || effectiveOld.length > 0) + && valid + && confirmMatches + && (rehearsing || effectiveOld !== newPassword); // Debounce the strength check so we don't slam the API on every keystroke. useEffect(() => { @@ -145,11 +162,11 @@ export function ChangePasswordForm({ try { const res = await runAction( { - title: '正在更新访问密码', - detail: '正在保存新密码并使其他会话失效', - successTitle: '访问密码已更新', - successDetail: '其他会话已失效', - errorTitle: '访问密码更新失败', + title: rehearsing ? '正在验证密码设置步骤' : '正在更新访问密码', + detail: rehearsing ? '演练内容不会保存' : '正在保存新密码并使其他会话失效', + successTitle: rehearsing ? '密码设置演练已完成' : '访问密码已更新', + successDetail: rehearsing ? '未修改真实访问密码' : '其他会话已失效', + errorTitle: rehearsing ? '密码设置演练失败' : '访问密码更新失败', resultError: (result) => result.success ? null : result.message || '修改失败', }, () => submit(effectiveOld, newPassword), @@ -167,7 +184,7 @@ export function ChangePasswordForm({ }; return ( -
+ {!carriesOld && ( { if (value.length === 0) return '请输入新密码'; - if (value === effectiveOld) return '新密码不能与当前密码相同'; + if (!rehearsing && value === effectiveOld) return '新密码不能与当前密码相同'; return null; }} showValidIcon={false} @@ -277,22 +294,24 @@ export function ChangePasswordForm({ )} -
- {onCancel && ( - - )} - )} - -
+ +
+ )} ); } @@ -311,7 +330,7 @@ function PasswordVisibilityButton({ type="button" onClick={onToggle} aria-label={visible ? '隐藏密码' : '显示密码'} - className="flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary" + className="flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary sm:size-7" > diff --git a/packages/webui/src/components/pages/onboarding-wizard-page.tsx b/packages/webui/src/components/pages/onboarding-wizard-page.tsx index 7be9a753..d922d8f6 100644 --- a/packages/webui/src/components/pages/onboarding-wizard-page.tsx +++ b/packages/webui/src/components/pages/onboarding-wizard-page.tsx @@ -1,9 +1,13 @@ import { useState, type ReactNode } from 'react'; -import { Check, ScrollText, ShieldAlert, ShieldCheck } from 'lucide-react'; +import { Check, Loader2, ScrollText, ShieldAlert, ShieldCheck } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { ThemeToggle } from '@/components/theme-toggle'; import { SegmentedControl } from '@/components/interior/segmented-control'; -import { WizardSteps, type WizardStep } from '@/components/interior/wizard-steps'; +import { + useWizardNavigation, + WizardSteps, + type WizardStep, +} from '@/components/interior/wizard-steps'; import { ChangePasswordForm, type PasswordRule } from '@/components/pages/change-password-form'; import { advanceOnboardingStep, @@ -28,6 +32,7 @@ interface OnboardingWizardPageProps { needsConsent: boolean; mustChangePassword: boolean; knownOldPassword?: string; + passwordMode?: 'change' | 'rehearsal'; onAccept: () => Promise<{ success: boolean; message?: string }>; onConsentComplete: () => void; onDecline: () => void; @@ -52,6 +57,7 @@ export function OnboardingWizardPage({ needsConsent, mustChangePassword, knownOldPassword, + passwordMode = 'change', onAccept, onConsentComplete, onDecline, @@ -85,6 +91,8 @@ export function OnboardingWizardPage({ label: '阅读并同意协议', canSkip: false, hideAdvance: true, + hideBack: true, + scrollMode: 'content', content: ( { @@ -133,7 +143,7 @@ export function OnboardingWizardPage({ if (total === 0) return null; return ( -
+
-
+
-
-
-

SnowLuma WebUI

-

完成首次使用设置

-

+

+
+

SnowLuma WebUI

+

完成首次使用设置

+

按顺序完成必要步骤后即可进入控制台。

-
+
@@ -208,21 +219,21 @@ function AgreementStep({ }; return ( -
-
-
+
+
+
-

请阅读并同意以下协议

-

+

请阅读并同意以下协议

+

同意一次后无需重复确认;仅当协议内容更新时才会再次请求确认。

{documents.length > 1 ? ( -
+
+

{active.declaredVersion ? `版本 / Version ${active.declaredVersion}` : ''} {active.declaredVersion && active.effectiveDate ? ' · ' : ''} {active.effectiveDate ? `生效 / Effective ${active.effectiveDate}` : ''}

) : null} -
- {active ? ( - - ) : ( -

未能加载协议文本,请刷新页面重试。

- )} +
+
+ {active ? ( + + ) : ( +

未能加载协议文本,请刷新页面重试。

+ )} +
{error ?

{error}

: null} -
- +
+ agreements {version.slice(0, 8)} -
- - @@ -299,11 +316,13 @@ function AgreementStep({ function PasswordStep({ knownOldPassword, + mode, checkStrength, submit, onComplete, }: { knownOldPassword?: string; + mode: 'change' | 'rehearsal'; checkStrength: (password: string) => Promise<{ rules: PasswordRule[]; valid: boolean }>; submit: ( oldPassword: string, @@ -311,26 +330,46 @@ function PasswordStep({ ) => Promise<{ success: boolean; message?: string }>; onComplete: () => void; }) { + const { back } = useWizardNavigation(); + return ( -
-
-
+
+
+
-

设置新的访问密码

-

- 将首次启动生成的临时密码替换为符合要求的强密码。 +

设置新的访问密码

+

+ {mode === 'rehearsal' + ? '验证密码设置步骤的界面与规则;本次演练不会保存输入内容。' + : '将首次启动生成的临时密码替换为符合要求的强密码。'}

( +
+ + +
+ )} />
);