安全/鉴权:登出清服务端 httpOnly 令牌、登录 IP 限流前置 bcrypt、停用账号 令牌在 6 个内联 role handler 失效、admin/items 存在性 oracle 认证前置、 同意偏好 sanitize fail-closed、api-crypto 按 HTTP 方法判体。 CMS:workflow 状态更新+审计收进交互式 $transaction(失败即回滚)、编辑器 richtext 走 textarea 防换行损毁、array/object 子字段按作用域读写防污染、 about/contact/erp-upgrade 补 ISR revalidate 与路由映射。 UI/a11y:AnimatedCounter 入视口前显起点、CLS 累计上报、MetricCard 动画入 effect 并卸载取消 rAF、后台状态四态映射/搜索防抖+序号守卫/媒体单 input/ 吞错改横幅/表单 label-aria 关联。 新增对应判别性单测与 pagination/rate-limit/client-ip/sanitize/validate-content-data 等模块及 tests-integration 真库集成层。
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { useReducedMotion } from '@/hooks/use-reduced-motion';
|
|
|
|
interface ScrollProgressProps {
|
|
/** Height of the progress bar in px */
|
|
height?: number;
|
|
/** Color of the progress bar (CSS variable or color) */
|
|
color?: string;
|
|
/** Position: top or bottom */
|
|
position?: 'top' | 'bottom';
|
|
className?: string;
|
|
}
|
|
|
|
export function ScrollProgress({
|
|
height = 2,
|
|
color = 'var(--color-brand)',
|
|
position = 'top',
|
|
className = '',
|
|
}: ScrollProgressProps) {
|
|
const [progress, setProgress] = useState(0);
|
|
const shouldReduceMotion = useReducedMotion();
|
|
|
|
useEffect(() => {
|
|
const updateProgress = () => {
|
|
const scrollTop = window.scrollY;
|
|
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
|
|
const value = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
|
|
setProgress(value);
|
|
};
|
|
|
|
updateProgress();
|
|
window.addEventListener('scroll', updateProgress, { passive: true });
|
|
window.addEventListener('resize', updateProgress);
|
|
|
|
return () => {
|
|
window.removeEventListener('scroll', updateProgress);
|
|
window.removeEventListener('resize', updateProgress);
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<div
|
|
className={`fixed left-0 right-0 z-[100] pointer-events-none ${className}`}
|
|
style={{
|
|
[position]: 0,
|
|
height: `${height}px`,
|
|
}}
|
|
aria-hidden="true"
|
|
data-testid="scroll-progress"
|
|
>
|
|
<div
|
|
style={{
|
|
width: '100%',
|
|
height: '100%',
|
|
background: color,
|
|
transformOrigin: 'left',
|
|
transform: `scaleX(${progress / 100})`,
|
|
transition: shouldReduceMotion ? 'none' : 'transform 0.1s linear',
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|