feat(homepage+tools): tools page card refinement and homepage fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface BorderBeamProps {
|
||||
@@ -14,18 +14,54 @@ interface BorderBeamProps {
|
||||
delay?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic UI - Border Beam
|
||||
* Animated traveling light border beam.
|
||||
* Optimized with IntersectionObserver to sleep when out of view,
|
||||
* and falls back to a clean static gradient on mobile/touch to eliminate GPU heating.
|
||||
* Reference: https://magicui.design/docs/components/border-beam
|
||||
*/
|
||||
export function BorderBeam({
|
||||
className,
|
||||
size = 250,
|
||||
duration = 12,
|
||||
borderWidth = 1.5,
|
||||
anchor = 90,
|
||||
colorFrom = '#3b82f6',
|
||||
colorTo = '#8b5cf6',
|
||||
colorFrom = 'var(--color-accent)',
|
||||
colorTo = 'var(--color-accent-hi)',
|
||||
delay = 0,
|
||||
}: BorderBeamProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [isTouchDevice, setIsTouchDevice] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Detect mobile touch devices to eliminate GPU-churning conic masks
|
||||
if (typeof window !== 'undefined') {
|
||||
const isTouch =
|
||||
window.innerWidth < 1024 ||
|
||||
navigator.maxTouchPoints > 0 ||
|
||||
'ontouchstart' in window;
|
||||
setIsTouchDevice(isTouch);
|
||||
}
|
||||
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
setIsVisible(entry.isIntersecting);
|
||||
},
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
observer.observe(container);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
style={
|
||||
{
|
||||
'--size': `${size}px`,
|
||||
@@ -38,7 +74,7 @@ export function BorderBeam({
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
'pointer-events-none absolute inset-0 rounded-[inherit] overflow-hidden',
|
||||
'pointer-events-none absolute inset-0 rounded-[inherit] overflow-hidden motion-reduce:hidden',
|
||||
className
|
||||
)}
|
||||
>
|
||||
@@ -46,21 +82,28 @@ export function BorderBeam({
|
||||
className="absolute inset-0 rounded-[inherit]"
|
||||
style={{
|
||||
padding: `${borderWidth}px`,
|
||||
mask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
|
||||
WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)',
|
||||
mask: 'linear-gradient(currentColor 0 0) content-box, linear-gradient(currentColor 0 0)',
|
||||
WebkitMask: 'linear-gradient(currentColor 0 0) content-box, linear-gradient(currentColor 0 0)',
|
||||
maskComposite: 'exclude',
|
||||
WebkitMaskComposite: 'xor',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-[-100%] animate-spin pointer-events-none"
|
||||
className={cn(
|
||||
'absolute inset-[-100%] pointer-events-none',
|
||||
isVisible && !isTouchDevice && 'animate-spin'
|
||||
)}
|
||||
style={{
|
||||
animationDuration: `${duration}s`,
|
||||
animationDelay: `${delay}s`,
|
||||
background: `conic-gradient(from 0deg at 50% 50%, transparent 0deg, transparent 270deg, ${colorFrom} 315deg, ${colorTo} 360deg)`,
|
||||
willChange: isVisible && !isTouchDevice ? 'transform' : 'auto',
|
||||
transform: 'translateZ(0)',
|
||||
background: `conic-gradient(from 0deg at 50% 50%, transparent 0deg, transparent 270deg, var(--color-from) 315deg, var(--color-to) 360deg)`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default BorderBeam;
|
||||
|
||||
Reference in New Issue
Block a user