Template
Add oversized globe background to stats section
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
bea4c4a1b9
commit
a40edbffa9
@@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import { type COBEOptions } from 'cobe';
|
||||
|
||||
import { Globe } from '@/components/ui/globe';
|
||||
|
||||
// Rotation per frame. Default globe is 0.005; lower is slower, 0 stops it.
|
||||
const GLOBE_SPEED = 0.003;
|
||||
|
||||
const globeConfig: COBEOptions = {
|
||||
width: 800,
|
||||
height: 800,
|
||||
onRender: () => {},
|
||||
devicePixelRatio: 2,
|
||||
phi: 0,
|
||||
theta: 0.22,
|
||||
dark: 1,
|
||||
diffuse: 1.2,
|
||||
mapSamples: 20000,
|
||||
mapBrightness: 5,
|
||||
baseColor: [0.22, 0.22, 0.22],
|
||||
markerColor: [1, 1, 1],
|
||||
glowColor: [0.1, 0.1, 0.1],
|
||||
markers: [
|
||||
{ location: [37.7749, -122.4194], size: 0.08 },
|
||||
{ location: [40.7128, -74.006], size: 0.06 },
|
||||
{ location: [51.5072, -0.1276], size: 0.07 },
|
||||
{ location: [48.8566, 2.3522], size: 0.05 },
|
||||
{ location: [1.3521, 103.8198], size: 0.08 },
|
||||
{ location: [35.6762, 139.6503], size: 0.06 },
|
||||
{ location: [-33.8688, 151.2093], size: 0.05 },
|
||||
{ location: [-23.5505, -46.6333], size: 0.06 },
|
||||
],
|
||||
};
|
||||
|
||||
export function StatsGlobe() {
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute inset-0 overflow-hidden [mask-image:radial-gradient(ellipse_80%_110%_at_50%_90%,black_45%,transparent_100%)]"
|
||||
>
|
||||
<div className="absolute left-1/2 top-[6%] aspect-square w-[760px] -translate-x-1/2 opacity-90 sm:w-[1040px] lg:w-[1280px]">
|
||||
<Globe className="max-w-none" config={globeConfig} speed={GLOBE_SPEED} />
|
||||
</div>
|
||||
<div className="absolute inset-x-0 bottom-0 h-1/3 bg-linear-to-t from-black/80 to-transparent" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { StatsGlobe } from '@/components/site/stats-globe';
|
||||
|
||||
const stats = [
|
||||
{ value: '45ms', label: 'Median edge response, worldwide' },
|
||||
{ value: '99.99%', label: 'Platform uptime over the last year' },
|
||||
@@ -7,10 +9,14 @@ const stats = [
|
||||
|
||||
export function Stats() {
|
||||
return (
|
||||
<section className="border-y border-white/10 bg-black">
|
||||
<div className="mx-auto grid max-w-6xl grid-cols-2 gap-px overflow-hidden bg-white/10 lg:grid-cols-4">
|
||||
<section className="relative overflow-hidden border-y border-white/10 bg-black py-16 sm:py-24">
|
||||
<StatsGlobe />
|
||||
<div className="relative z-10 mx-auto grid max-w-6xl grid-cols-2 gap-px lg:grid-cols-4">
|
||||
{stats.map((stat) => (
|
||||
<div key={stat.label} className="bg-black px-6 py-12 text-center">
|
||||
<div
|
||||
key={stat.label}
|
||||
className="px-6 py-12 text-center ring-1 ring-white/10"
|
||||
>
|
||||
<div className="text-4xl font-semibold tracking-tight sm:text-5xl">
|
||||
{stat.value}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef } from "react"
|
||||
import createGlobe, { type COBEOptions } from "cobe"
|
||||
import { useMotionValue, useSpring } from "motion/react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const MOVEMENT_DAMPING = 1400
|
||||
|
||||
const GLOBE_CONFIG: COBEOptions = {
|
||||
width: 800,
|
||||
height: 800,
|
||||
onRender: () => {},
|
||||
devicePixelRatio: 2,
|
||||
phi: 0,
|
||||
theta: 0.3,
|
||||
dark: 0,
|
||||
diffuse: 0.4,
|
||||
mapSamples: 16000,
|
||||
mapBrightness: 1.2,
|
||||
baseColor: [1, 1, 1],
|
||||
markerColor: [251 / 255, 100 / 255, 21 / 255],
|
||||
glowColor: [1, 1, 1],
|
||||
markers: [
|
||||
{ location: [14.5995, 120.9842], size: 0.03 },
|
||||
{ location: [19.076, 72.8777], size: 0.1 },
|
||||
{ location: [23.8103, 90.4125], size: 0.05 },
|
||||
{ location: [30.0444, 31.2357], size: 0.07 },
|
||||
{ location: [39.9042, 116.4074], size: 0.08 },
|
||||
{ location: [-23.5505, -46.6333], size: 0.1 },
|
||||
{ location: [19.4326, -99.1332], size: 0.1 },
|
||||
{ location: [40.7128, -74.006], size: 0.1 },
|
||||
{ location: [34.6937, 135.5022], size: 0.05 },
|
||||
{ location: [41.0082, 28.9784], size: 0.06 },
|
||||
],
|
||||
}
|
||||
|
||||
export function Globe({
|
||||
className,
|
||||
config = GLOBE_CONFIG,
|
||||
speed = 0.005,
|
||||
}: {
|
||||
className?: string
|
||||
config?: COBEOptions
|
||||
/**
|
||||
* Radians added to the rotation on every frame. Higher spins faster,
|
||||
* 0 stops the auto-rotation (dragging still works).
|
||||
* @default 0.005
|
||||
*/
|
||||
speed?: number
|
||||
}) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null)
|
||||
const phiRef = useRef(0)
|
||||
const widthRef = useRef(0)
|
||||
const pointerInteracting = useRef<number | null>(null)
|
||||
const pointerInteractionMovement = useRef(0)
|
||||
|
||||
const r = useMotionValue(0)
|
||||
const rs = useSpring(r, {
|
||||
mass: 1,
|
||||
damping: 30,
|
||||
stiffness: 100,
|
||||
})
|
||||
|
||||
const updatePointerInteraction = (value: number | null) => {
|
||||
pointerInteracting.current = value
|
||||
if (canvasRef.current) {
|
||||
canvasRef.current.style.cursor = value !== null ? "grabbing" : "grab"
|
||||
}
|
||||
}
|
||||
|
||||
const updateMovement = (clientX: number) => {
|
||||
if (pointerInteracting.current !== null) {
|
||||
const delta = clientX - pointerInteracting.current
|
||||
pointerInteractionMovement.current = delta
|
||||
r.set(r.get() + delta / MOVEMENT_DAMPING)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const onResize = () => {
|
||||
if (canvasRef.current) {
|
||||
widthRef.current = canvasRef.current.offsetWidth
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("resize", onResize)
|
||||
onResize()
|
||||
|
||||
const globe = createGlobe(canvasRef.current!, {
|
||||
...config,
|
||||
width: widthRef.current * 2,
|
||||
height: widthRef.current * 2,
|
||||
onRender: (state) => {
|
||||
if (!pointerInteracting.current) phiRef.current += speed
|
||||
state.phi = phiRef.current + rs.get()
|
||||
state.width = widthRef.current * 2
|
||||
state.height = widthRef.current * 2
|
||||
},
|
||||
})
|
||||
|
||||
setTimeout(() => (canvasRef.current!.style.opacity = "1"), 0)
|
||||
return () => {
|
||||
globe.destroy()
|
||||
window.removeEventListener("resize", onResize)
|
||||
}
|
||||
}, [rs, config, speed])
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"absolute inset-0 mx-auto aspect-square w-full max-w-150",
|
||||
className
|
||||
)}
|
||||
>
|
||||
<canvas
|
||||
className={cn(
|
||||
"size-full opacity-0 transition-opacity duration-500 contain-[layout_paint_size]"
|
||||
)}
|
||||
ref={canvasRef}
|
||||
onPointerDown={(e) => {
|
||||
pointerInteracting.current = e.clientX
|
||||
updatePointerInteraction(e.clientX)
|
||||
}}
|
||||
onPointerUp={() => updatePointerInteraction(null)}
|
||||
onPointerOut={() => updatePointerInteraction(null)}
|
||||
onMouseMove={(e) => updateMovement(e.clientX)}
|
||||
onTouchMove={(e) =>
|
||||
e.touches[0] && updateMovement(e.touches[0].clientX)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user