feat(ui): 重构核心 UI 组件库,新增 shadcn/ui 组件
- 重构 Button、Card、Badge、Input、Textarea 等基础组件 - 新增 Accordion、Alert、Dialog、Dropdown、Form 等 shadcn/ui 组件 - 新增 AnimatedCounter、StatsShowcase、MetricCard 等数据展示组件 - 新增 ScrollReveal 滚动动画组件 - 重构 Toast 通知系统与 Tooltip 提示组件 - 更新设计令牌系统,对齐新品牌视觉
This commit is contained in:
1 parent
9053f69123
commit
e78df62cd1
62 files changed
+4024
-822
No files matched your search
@@ -1,69 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { motion, useScroll, useSpring, useTransform } from 'framer-motion';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useReducedMotion } from '@/hooks/use-reduced-motion';
|
||||
|
||||
export function ScrollProgress() {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
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();
|
||||
const { scrollYProgress } = useScroll();
|
||||
|
||||
const scaleX = useSpring(scrollYProgress, {
|
||||
stiffness: 100,
|
||||
damping: 30,
|
||||
restDelta: 0.001,
|
||||
});
|
||||
|
||||
const glowX = useSpring(scrollYProgress, {
|
||||
stiffness: 120,
|
||||
damping: 25,
|
||||
restDelta: 0.001,
|
||||
});
|
||||
|
||||
const glowLeft = useTransform(glowX, (v) => `calc(${v * 100}% - 30px)`);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsVisible(window.scrollY > 80);
|
||||
const updateProgress = () => {
|
||||
const scrollTop = window.scrollY;
|
||||
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
|
||||
const value = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
|
||||
setProgress(value);
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
updateProgress();
|
||||
window.addEventListener('scroll', updateProgress, { passive: true });
|
||||
window.addEventListener('resize', updateProgress);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', updateProgress);
|
||||
window.removeEventListener('resize', updateProgress);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!isVisible) {return null;}
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
initial={shouldReduceMotion ? {} : { opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={shouldReduceMotion ? {} : { opacity: 0 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
className="fixed top-0 left-0 right-0 h-[2px] z-[100]"
|
||||
role="progressbar"
|
||||
aria-label="页面滚动进度"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
<div
|
||||
className={`fixed left-0 right-0 z-[100] pointer-events-none ${className}`}
|
||||
style={{
|
||||
[position]: 0,
|
||||
height: `${height}px`,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<motion.div
|
||||
className="h-full origin-left"
|
||||
<div
|
||||
style={{
|
||||
scaleX,
|
||||
background: 'var(--color-brand-primary)',
|
||||
width: `${shouldReduceMotion ? 0 : progress}%`,
|
||||
height: '100%',
|
||||
background: color,
|
||||
transition: shouldReduceMotion ? 'none' : 'width 0.1s linear',
|
||||
}}
|
||||
/>
|
||||
{!shouldReduceMotion && (
|
||||
<motion.div
|
||||
className="absolute top-1/2 -translate-y-1/2 w-[60px] h-[3px] -mt-[0.5px]"
|
||||
style={{
|
||||
left: glowLeft,
|
||||
background: 'linear-gradient(90deg, transparent, var(--color-brand-primary), transparent)',
|
||||
filter: 'blur(3px)',
|
||||
opacity: 0.6,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user