@@ -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 (
-
);
}
@@ -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)}
-
-