From e224a0c6eac0edacb0d4d9930df7bdc6befe9983 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Thu, 16 Jul 2026 16:06:04 +0800 Subject: [PATCH] feat(webui): animate contextual state icons Add a shared, stable-size password visibility icon that switches with interruptible opacity, scale, and blur motion across login and password-change flows. Apply the same motion language to password rule checks, remove the redundant outer pulse, skip initial-state animation, and switch immediately when reduced motion is enabled. --- .../components/pages/change-password-form.tsx | 31 ++++++++++-------- .../webui/src/components/pages/login-page.tsx | 5 +-- .../ui/password-visibility-icon.tsx | 32 +++++++++++++++++++ 3 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 packages/webui/src/components/ui/password-visibility-icon.tsx diff --git a/packages/webui/src/components/pages/change-password-form.tsx b/packages/webui/src/components/pages/change-password-form.tsx index f3bc2f4d..6497a6f3 100644 --- a/packages/webui/src/components/pages/change-password-form.tsx +++ b/packages/webui/src/components/pages/change-password-form.tsx @@ -1,9 +1,11 @@ import { useEffect, useMemo, useState } from 'react'; import { motion, AnimatePresence } from 'motion/react'; -import { Check, Eye, EyeOff, Loader2 } from 'lucide-react'; +import { Check, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; +import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon'; +import { useTheme } from '@/contexts/ThemeContext'; import { cn } from '@/lib/utils'; export interface PasswordRule { @@ -48,6 +50,8 @@ export function ChangePasswordForm({ submitLabel = '保存新密码', }: ChangePasswordFormProps) { const carriesOld = knownOldPassword !== undefined; + const { appearance } = useTheme(); + const reduceMotion = appearance.reduceMotion || appearance.disableMotion; const [oldPassword, setOldPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); @@ -124,7 +128,7 @@ export function ChangePasswordForm({ tabIndex={-1} className="absolute right-2 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground" > - {showOld ? : } + @@ -149,7 +153,7 @@ export function ChangePasswordForm({ tabIndex={-1} className="absolute right-2 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground" > - {showNew ? : } + @@ -170,7 +174,7 @@ export function ChangePasswordForm({ )} - + {error && ( @@ -205,7 +209,7 @@ export function ChangePasswordForm({ ); } -function RuleList({ rules }: { rules: PasswordRule[] }) { +function RuleList({ rules, reduceMotion }: { rules: PasswordRule[]; reduceMotion: boolean }) { // Initial empty state: show a placeholder set so the user knows the rules // exist even before any input. const display = useMemo(() => { @@ -228,19 +232,20 @@ function RuleList({ rules }: { rules: PasswordRule[] }) { animate={{ backgroundColor: rule.ok ? 'color-mix(in oklab, var(--primary) 20%, transparent)' : 'transparent', borderColor: rule.ok ? 'var(--primary)' : 'var(--border)', - scale: rule.ok ? [1, 1.18, 1] : 1, }} - transition={{ duration: 0.25 }} + transition={{ duration: reduceMotion ? 0 : 0.2 }} className={cn('flex size-4 items-center justify-center rounded-full border')} > - + {rule.ok && ( @@ -250,7 +255,7 @@ function RuleList({ rules }: { rules: PasswordRule[] }) { {rule.label} diff --git a/packages/webui/src/components/pages/login-page.tsx b/packages/webui/src/components/pages/login-page.tsx index 4f393e66..ca7382e3 100644 --- a/packages/webui/src/components/pages/login-page.tsx +++ b/packages/webui/src/components/pages/login-page.tsx @@ -1,11 +1,12 @@ import { useEffect, useState } from 'react'; import { motion } from 'motion/react'; -import { ArrowRight, Eye, EyeOff, KeyRound, Sparkles } from 'lucide-react'; +import { ArrowRight, KeyRound, Sparkles } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { ToggleSwitch } from '@/components/ui/toggle-switch'; +import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon'; import { ThemeToggle } from '@/components/theme-toggle'; import { LoginWaves } from '@/components/login-waves'; import { useTheme } from '@/contexts/ThemeContext'; @@ -131,7 +132,7 @@ export function LoginPage({ onLogin }: LoginPageProps) { tabIndex={-1} aria-label={showPwd ? '隐藏密码' : '显示密码'} > - {showPwd ? : } + diff --git a/packages/webui/src/components/ui/password-visibility-icon.tsx b/packages/webui/src/components/ui/password-visibility-icon.tsx new file mode 100644 index 00000000..1002f7f2 --- /dev/null +++ b/packages/webui/src/components/ui/password-visibility-icon.tsx @@ -0,0 +1,32 @@ +import { AnimatePresence, motion } from 'motion/react'; +import { Eye, EyeOff } from 'lucide-react'; + +interface PasswordVisibilityIconProps { + visible: boolean; + reduceMotion?: boolean; +} + +const hidden = { opacity: 0, scale: 0.25, filter: 'blur(4px)' }; +const shown = { opacity: 1, scale: 1, filter: 'blur(0px)' }; + +/** A stable-size password icon whose state change remains interruptible. */ +export function PasswordVisibilityIcon({ visible, reduceMotion = false }: PasswordVisibilityIconProps) { + const Icon = visible ? EyeOff : Eye; + + return ( + + + + + + + + ); +}