mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
3245310aa8
* feat(review): add optional CallDiff call-flow analysis * fix(review): harden CallDiff integration
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import React, { useMemo, type JSX } from 'react';
|
|
import { motion, useReducedMotion } from 'motion/react';
|
|
|
|
export interface TextShimmerProps {
|
|
children: string;
|
|
as?: React.ElementType;
|
|
className?: string;
|
|
duration?: number;
|
|
spread?: number;
|
|
}
|
|
|
|
function TextShimmerComponent({
|
|
children,
|
|
as: Component = 'span',
|
|
className,
|
|
duration = 2,
|
|
spread = 2,
|
|
}: TextShimmerProps) {
|
|
const shouldReduceMotion = useReducedMotion();
|
|
const MotionComponent = motion.create(
|
|
Component as keyof JSX.IntrinsicElements
|
|
);
|
|
|
|
const dynamicSpread = useMemo(() => {
|
|
return children.length * spread;
|
|
}, [children, spread]);
|
|
|
|
return (
|
|
<MotionComponent
|
|
className={[
|
|
'relative inline-block bg-[length:250%_100%,auto] bg-clip-text',
|
|
'text-transparent [--base-color:#a1a1aa] [--base-gradient-color:#000]',
|
|
'[background-repeat:no-repeat,padding-box] [--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--base-gradient-color),#0000_calc(50%+var(--spread)))]',
|
|
'dark:[--base-color:#71717a] dark:[--base-gradient-color:#ffffff] dark:[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--base-gradient-color),#0000_calc(50%+var(--spread)))]',
|
|
className,
|
|
]
|
|
.filter(Boolean)
|
|
.join(' ')}
|
|
initial={shouldReduceMotion ? false : { backgroundPosition: '100% center' }}
|
|
animate={shouldReduceMotion ? undefined : { backgroundPosition: '0% center' }}
|
|
transition={shouldReduceMotion ? undefined : {
|
|
repeat: Infinity,
|
|
duration,
|
|
ease: 'linear',
|
|
}}
|
|
style={
|
|
{
|
|
'--spread': `${dynamicSpread}px`,
|
|
backgroundImage: shouldReduceMotion
|
|
? 'linear-gradient(var(--base-color), var(--base-color))'
|
|
: 'var(--bg), linear-gradient(var(--base-color), var(--base-color))',
|
|
} as React.CSSProperties
|
|
}
|
|
>
|
|
{children}
|
|
</MotionComponent>
|
|
);
|
|
}
|
|
|
|
export const TextShimmer = React.memo(TextShimmerComponent);
|