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.
This commit is contained in:
4 files changed
+200
-93
No files matched your search
@@ -191,7 +191,7 @@ export function FloatingLabelInput({
|
||||
<div className={`w-full ${className}`}>
|
||||
<div className="relative pt-[20px]">
|
||||
<div
|
||||
className={`relative h-10 rounded-[10px] border-2 transition-[background-color,border-color,box-shadow] duration-150 ${
|
||||
className={`relative h-11 rounded-[10px] border-2 transition-[background-color,border-color,box-shadow] duration-150 sm:h-10 ${
|
||||
invalid
|
||||
? "border-destructive bg-background"
|
||||
: focused
|
||||
@@ -228,7 +228,7 @@ export function FloatingLabelInput({
|
||||
fieldProps.onChange(event);
|
||||
onChange?.(event.currentTarget.value, event);
|
||||
}}
|
||||
className={`absolute inset-0 h-full w-full rounded-[9px] bg-transparent px-3 py-0 text-[13px] leading-[20px] text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed ${
|
||||
className={`absolute inset-0 h-full w-full rounded-[9px] bg-transparent px-3 py-0 text-base leading-5 text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed sm:text-[13px] ${
|
||||
endAdornment ? "pr-16" : ""
|
||||
}`}
|
||||
/>
|
||||
@@ -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
|
||||
|
||||
@@ -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<WizardNavigationControls | null>(null);
|
||||
|
||||
export function useWizardNavigation(): WizardNavigationControls {
|
||||
const controls = useContext(WizardNavigationContext);
|
||||
if (!controls) throw new Error("useWizardNavigation must be used inside <WizardSteps>");
|
||||
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 (
|
||||
<div className={`w-full ${className}`}>
|
||||
<div className={`${fill ? "flex min-h-0 flex-1 flex-col" : ""} w-full ${className}`}>
|
||||
<p aria-live="polite" className="sr-only">{position}</p>
|
||||
<span
|
||||
aria-hidden
|
||||
className="mb-2 grid select-none text-[13px] font-medium text-foreground"
|
||||
className={`${spacious ? "mb-1 text-sm" : "mb-2 text-[13px]"} grid select-none font-medium text-foreground`}
|
||||
>
|
||||
{steps.map((candidate, stepIndex) => (
|
||||
<motion.span
|
||||
@@ -229,7 +272,7 @@ export function WizardSteps({
|
||||
<ol
|
||||
ref={listRef}
|
||||
aria-label={label}
|
||||
className="mb-4 flex list-none items-center gap-1 p-0"
|
||||
className={`${spacious ? "mb-3 gap-2" : "mb-4 gap-1"} flex list-none items-center p-0`}
|
||||
>
|
||||
{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}
|
||||
</button>
|
||||
@@ -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"
|
||||
}`}
|
||||
>
|
||||
<AnimatePresence initial={false} custom={direction}>
|
||||
<motion.div
|
||||
@@ -327,7 +374,9 @@ export function WizardSteps({
|
||||
exit="exit"
|
||||
transition={panelTransition}
|
||||
style={{ scrollbarGutter: "stable" }}
|
||||
className="absolute inset-0 overflow-y-auto overscroll-contain p-4 text-[13.5px] leading-relaxed text-foreground"
|
||||
className={`absolute inset-0 overscroll-contain text-foreground ${
|
||||
step.scrollMode === "content" ? "overflow-hidden" : "overflow-y-auto"
|
||||
} ${spacious ? "p-4 text-sm leading-relaxed sm:p-5 lg:p-6" : "p-4 text-[13.5px] leading-relaxed"}`}
|
||||
>
|
||||
{complete ? (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-1.5">
|
||||
@@ -335,14 +384,16 @@ export function WizardSteps({
|
||||
<p className="text-[12.5px] text-muted-foreground">{completeHint}</p>
|
||||
</div>
|
||||
) : (
|
||||
step.content
|
||||
<WizardNavigationContext.Provider value={navigation}>
|
||||
{step.content}
|
||||
</WizardNavigationContext.Provider>
|
||||
)}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
<div className="mt-3 flex h-9 items-center gap-3">
|
||||
{showNavigation ? <div className={`${spacious ? "mt-4 h-11" : "mt-3 h-9"} flex items-center gap-3`}>
|
||||
<AnimatePresence initial={false}>
|
||||
{isFirst ? null : (
|
||||
{showBack ? (
|
||||
<motion.button
|
||||
key="back"
|
||||
type="button"
|
||||
@@ -354,16 +405,15 @@ export function WizardSteps({
|
||||
}}
|
||||
transition={reduced ? { duration: 0 } : { duration: 0.16, ease: EASE }}
|
||||
onClick={() => {
|
||||
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}
|
||||
</motion.button>
|
||||
)}
|
||||
) : null}
|
||||
</AnimatePresence>
|
||||
{step.canSkip ? (
|
||||
{showSkip ? (
|
||||
<motion.button
|
||||
key={`skip-${step.id}`}
|
||||
type="button"
|
||||
@@ -379,20 +429,19 @@ export function WizardSteps({
|
||||
if (!isLast) intent.current = "panel";
|
||||
next();
|
||||
}}
|
||||
className="h-9 rounded-[9px] px-3 text-[13px] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground 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] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/40`}
|
||||
>
|
||||
{skipLabel}
|
||||
</motion.button>
|
||||
) : null}
|
||||
<AnimatePresence initial={false}>
|
||||
{complete || step.hideAdvance ? null : (
|
||||
{showAdvance ? (
|
||||
<motion.button
|
||||
key="advance"
|
||||
type="button"
|
||||
aria-label={isLast ? finishLabel : nextLabel}
|
||||
onClick={() => {
|
||||
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)]`}
|
||||
>
|
||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||
{finishLabel.length > nextLabel.length ? finishLabel : nextLabel}
|
||||
@@ -428,9 +477,9 @@ export function WizardSteps({
|
||||
{finishLabel}
|
||||
</motion.span>
|
||||
</motion.button>
|
||||
)}
|
||||
) : null}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-3">
|
||||
<form onSubmit={handleSubmit} className={cn('flex flex-col gap-3', className)}>
|
||||
{!carriesOld && (
|
||||
<InlineValidation
|
||||
id={`${idPrefix}-old`}
|
||||
@@ -206,7 +223,7 @@ export function ChangePasswordForm({
|
||||
validationKey={effectiveOld}
|
||||
validate={(value) => {
|
||||
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({
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
{onCancel && (
|
||||
<Button type="button" variant="ghost" onClick={onCancel} className="h-10">
|
||||
取消
|
||||
</Button>
|
||||
)}
|
||||
<Button type="submit" disabled={!canSubmit} className="ml-auto h-10">
|
||||
{submitting ? (
|
||||
<>
|
||||
<Loader2 className="size-4 animate-spin" /> 提交中…
|
||||
</>
|
||||
) : (
|
||||
submitLabel
|
||||
{renderActions ? renderActions({ canSubmit, submitting, submitLabel }) : (
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
{onCancel && (
|
||||
<Button type="button" variant="ghost" onClick={onCancel} className="h-10">
|
||||
取消
|
||||
</Button>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<Button type="submit" disabled={!canSubmit} className="ml-auto h-10">
|
||||
{submitting ? (
|
||||
<>
|
||||
<Loader2 className="size-4 animate-spin" /> 提交中…
|
||||
</>
|
||||
) : (
|
||||
submitLabel
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -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"
|
||||
>
|
||||
<PasswordVisibilityIcon visible={visible} reduceMotion={reduceMotion} />
|
||||
</button>
|
||||
|
||||
@@ -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: (
|
||||
<AgreementStep
|
||||
documents={documents}
|
||||
@@ -104,9 +112,11 @@ export function OnboardingWizardPage({
|
||||
label: '设置访问密码',
|
||||
canSkip: false,
|
||||
hideAdvance: true,
|
||||
hideBack: true,
|
||||
content: (
|
||||
<PasswordStep
|
||||
knownOldPassword={knownOldPassword}
|
||||
mode={passwordMode}
|
||||
checkStrength={checkStrength}
|
||||
submit={submitPassword}
|
||||
onComplete={() => {
|
||||
@@ -133,7 +143,7 @@ export function OnboardingWizardPage({
|
||||
if (total === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="relative flex min-h-screen items-center justify-center overflow-x-hidden bg-background px-4 py-6">
|
||||
<div className="relative min-h-dvh overflow-x-clip bg-background antialiased">
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
style={{
|
||||
@@ -141,28 +151,29 @@ export function OnboardingWizardPage({
|
||||
'radial-gradient(80% 60% at 50% 0%, color-mix(in oklab, var(--primary) 18%, transparent) 0%, transparent 70%)',
|
||||
}}
|
||||
/>
|
||||
<div className="absolute right-4 top-4">
|
||||
<div className="absolute right-4 top-4 z-20 sm:right-6 sm:top-6">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
<main className="relative z-10 w-full max-w-3xl">
|
||||
<div className="mb-5">
|
||||
<p className="text-xs font-medium text-primary">SnowLuma WebUI</p>
|
||||
<h1 className="mt-1 text-xl font-semibold tracking-tight">完成首次使用设置</h1>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
<main className="relative z-10 mx-auto flex h-dvh min-h-0 w-full max-w-5xl flex-col overflow-hidden px-4 pb-4 pt-14 sm:px-6 sm:pb-5 sm:pt-4">
|
||||
<header className="mx-auto mb-2 w-full max-w-2xl shrink-0 text-center">
|
||||
<p className="text-xs font-semibold tracking-wide text-primary">SnowLuma WebUI</p>
|
||||
<h1 className="mt-1 text-balance text-2xl font-semibold tracking-tight sm:text-3xl">完成首次使用设置</h1>
|
||||
<p className="mx-auto mt-1 max-w-xl text-pretty text-sm leading-relaxed text-muted-foreground">
|
||||
按顺序完成必要步骤后即可进入控制台。
|
||||
</p>
|
||||
</div>
|
||||
</header>
|
||||
<WizardSteps
|
||||
steps={steps}
|
||||
index={index}
|
||||
onIndexChange={setIndex}
|
||||
onComplete={onComplete}
|
||||
height={520}
|
||||
label="首次使用设置步骤"
|
||||
backLabel="上一步"
|
||||
nextLabel="下一步"
|
||||
finishLabel="完成"
|
||||
skipLabel="跳过"
|
||||
spacious
|
||||
fill
|
||||
/>
|
||||
</main>
|
||||
</div>
|
||||
@@ -208,21 +219,21 @@ function AgreementStep({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-full flex-col">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
<div className="flex items-start gap-3 sm:gap-4">
|
||||
<div className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20 sm:size-12 sm:rounded-2xl">
|
||||
<ScrollText className="size-5 text-primary" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-base font-semibold">请阅读并同意以下协议</h2>
|
||||
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
||||
<h2 className="text-balance text-lg font-semibold tracking-tight sm:text-xl">请阅读并同意以下协议</h2>
|
||||
<p className="mt-0.5 max-w-2xl text-pretty text-xs leading-relaxed text-muted-foreground sm:mt-1 sm:text-sm">
|
||||
同意一次后无需重复确认;仅当协议内容更新时才会再次请求确认。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{documents.length > 1 ? (
|
||||
<div className="mt-4 max-w-full overflow-x-auto">
|
||||
<div className="mt-3 max-w-full overflow-x-auto pb-1 sm:mt-4">
|
||||
<SegmentedControl
|
||||
label="协议文档"
|
||||
value={activeId}
|
||||
@@ -238,19 +249,25 @@ function AgreementStep({
|
||||
) : null}
|
||||
|
||||
{active && (active.declaredVersion || active.effectiveDate) ? (
|
||||
<p className="mt-2 text-meta text-muted-foreground">
|
||||
<p className="mt-1.5 px-0.5 text-meta leading-relaxed text-muted-foreground">
|
||||
{active.declaredVersion ? `版本 / Version ${active.declaredVersion}` : ''}
|
||||
{active.declaredVersion && active.effectiveDate ? ' · ' : ''}
|
||||
{active.effectiveDate ? `生效 / Effective ${active.effectiveDate}` : ''}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="mt-3 min-h-48 flex-1 overflow-y-auto rounded-lg border border-border bg-background/60 p-4">
|
||||
{active ? (
|
||||
<Markdown content={active.text} />
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">未能加载协议文本,请刷新页面重试。</p>
|
||||
)}
|
||||
<div
|
||||
tabIndex={0}
|
||||
aria-label={active?.title ? `${active.title}正文` : '协议正文'}
|
||||
className="mt-3 min-h-0 flex-1 overflow-y-auto overscroll-contain rounded-2xl border border-border/80 bg-background/55 p-3 outline-none shadow-[inset_0_1px_2px_rgb(0_0_0/0.06)] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/30 sm:p-5"
|
||||
>
|
||||
<div className="mx-auto max-w-3xl">
|
||||
{active ? (
|
||||
<Markdown content={active.text} />
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">未能加载协议文本,请刷新页面重试。</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@@ -258,7 +275,7 @@ function AgreementStep({
|
||||
onClick={() => setAgreed((current) => !current)}
|
||||
aria-pressed={agreed}
|
||||
className={cn(
|
||||
'mt-3 flex w-full items-center gap-3 rounded-lg border px-3.5 py-2.5 text-left transition-colors',
|
||||
'mt-3 flex min-h-11 w-full items-center gap-3 rounded-xl border px-3.5 py-2.5 text-start outline-none transition-[background-color,border-color,box-shadow] duration-150 focus-visible:ring-[3px] focus-visible:ring-ring/40 sm:min-h-12 sm:px-4 sm:py-3',
|
||||
agreed
|
||||
? 'border-primary/60 bg-primary/5'
|
||||
: 'border-border hover:border-primary/40 hover:bg-accent/40',
|
||||
@@ -274,20 +291,20 @@ function AgreementStep({
|
||||
>
|
||||
{agreed ? <Check className="size-3.5" strokeWidth={3} /> : null}
|
||||
</span>
|
||||
<span className="text-sm font-medium">我已阅读并同意《用户协议》与《隐私政策》</span>
|
||||
<span className="text-sm font-medium leading-relaxed">我已阅读并同意《用户协议》与《隐私政策》</span>
|
||||
</button>
|
||||
|
||||
{error ? <p role="alert" className="mt-2 text-xs text-destructive">{error}</p> : null}
|
||||
|
||||
<div className="mt-3 flex items-center justify-between gap-2">
|
||||
<span className="text-micro text-muted-foreground/70">
|
||||
<div className="mt-3 flex items-center gap-3 sm:justify-between">
|
||||
<span className="hidden text-micro text-muted-foreground/70 sm:inline">
|
||||
agreements {version.slice(0, 8)}
|
||||
</span>
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant="ghost" onClick={onDecline} disabled={submitting}>
|
||||
<div className="grid w-full grid-cols-2 gap-3 sm:ml-auto sm:flex sm:w-auto sm:items-center">
|
||||
<Button type="button" variant="outline" onClick={onDecline} disabled={submitting} className="h-11 w-full sm:w-auto">
|
||||
不同意并退出
|
||||
</Button>
|
||||
<Button type="button" onClick={() => { void accept(); }} disabled={!agreed || submitting}>
|
||||
<Button type="button" onClick={() => { void accept(); }} disabled={!agreed || submitting} className="h-11 w-full sm:min-w-36 sm:w-auto">
|
||||
<ShieldCheck className="size-4" />
|
||||
{submitting ? '提交中…' : '同意并继续'}
|
||||
</Button>
|
||||
@@ -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 (
|
||||
<div className="mx-auto flex w-full max-w-lg flex-col">
|
||||
<div className="mb-5 flex items-start gap-3">
|
||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-xl flex-col justify-center py-2 sm:py-5">
|
||||
<div className="mb-8 flex items-start gap-4">
|
||||
<div className="flex size-12 shrink-0 items-center justify-center rounded-2xl bg-primary/10 ring-1 ring-primary/20">
|
||||
<ShieldAlert className="size-5 text-primary" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-base font-semibold">设置新的访问密码</h2>
|
||||
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
||||
将首次启动生成的临时密码替换为符合要求的强密码。
|
||||
<h2 className="text-balance text-lg font-semibold tracking-tight sm:text-xl">设置新的访问密码</h2>
|
||||
<p className="mt-1 text-pretty text-sm leading-relaxed text-muted-foreground">
|
||||
{mode === 'rehearsal'
|
||||
? '验证密码设置步骤的界面与规则;本次演练不会保存输入内容。'
|
||||
: '将首次启动生成的临时密码替换为符合要求的强密码。'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<ChangePasswordForm
|
||||
knownOldPassword={knownOldPassword}
|
||||
mode={mode}
|
||||
checkStrength={checkStrength}
|
||||
submit={submit}
|
||||
onSuccess={onComplete}
|
||||
idPrefix="onboarding-cpw"
|
||||
submitLabel="保存并完成"
|
||||
submitLabel={mode === 'rehearsal' ? '完成演练' : '保存并完成'}
|
||||
className="gap-5"
|
||||
renderActions={({ canSubmit, submitting, submitLabel }) => (
|
||||
<div className="grid gap-3 pt-2 sm:flex sm:items-center">
|
||||
<Button type="button" variant="outline" onClick={back} disabled={submitting} className="h-11 w-full sm:w-auto">
|
||||
上一步
|
||||
</Button>
|
||||
<Button type="submit" disabled={!canSubmit} className="h-11 w-full sm:ml-auto sm:min-w-36 sm:w-auto">
|
||||
{submitting ? (
|
||||
<>
|
||||
<Loader2 className="size-4 animate-spin" /> 提交中…
|
||||
</>
|
||||
) : submitLabel}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user