Files
supabase/apps/www/components/Wrapped/Pages/Intro.tsx
Brian-AnandDanny White f1082e28c7 chore: migrate Framer Motion imports to Motion (#51520)
## Problem

Closes #31221.
The applications and shared UI packages still import the former
`framer-motion` package instead of Motion's React entry point.

## Solution

Replace runtime imports, type imports, and three test mocks with
`motion/react` across the consuming workspaces.
Replace the seven direct dependency declarations with `motion:
^11.18.2`.
Preserve the existing animation engine version and all other dependency
resolutions, including the asynchronous `domMax` feature loader.
Historical blog examples remain as published; `framer-motion` remains a
transitive implementation dependency of Motion.

## Review instructions

1. Run `pnpm install --frozen-lockfile` and check the seven dependency
replacements in the lockfile.
2. Open the WWW Auth page and Docs homepage at desktop and mobile
widths, with normal and reduced motion preferences.
3. Open the mobile navigation, expand Product on WWW, and close the menu
using Escape and the close button.
4. Check the existing animation components, shared form validation, and
Studio tests for unchanged behavior.

Validation:

- Studio: 731 test files, 8,334 passing tests and one expected failure,
with `--maxWorkers=4`.
- Shared UI, UI patterns, WWW, and UI library: 615 passing tests.
- `pnpm run typecheck --concurrency=1`: all 16 repository tasks pass.
- All six application source lint scripts and lint ratchets pass;
generated Docs example copies are excluded from local lint.
- Repository Prettier source check, lockfile formatting, and case hazard
check pass.
- WWW: 10 existing end-to-end checks across nine pages.
- Docs: 5 existing guide link and accessibility checks across Database
and Auth.
- WWW and Docs mobile navigation pass at desktop/mobile sizes with
normal/reduced motion; SQL-to-REST translation tabs exercise the
asynchronous feature loader without browser errors.
- Frozen-lockfile installation passes; all existing package and snapshot
resolutions are unchanged.
- Learn and UI library command palettes open, filter results, and close
with Escape without browser errors.
- Independent code review finds no actionable defects.
- `npm run build -- --filter=www --filter=docs --filter=studio
--filter=learn --filter=library --concurrency=1 --continue=always`: all
five affected applications build successfully (9 tasks including
prerequisites); asset uploads disabled for local validation.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
(no docs topics changed)

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-10-14 07:16:00 +00:00

232 lines
6.9 KiB
TypeScript

'use client'
import * as Scrollytelling from '@bsmnt/scrollytelling'
import { AnimatePresence, motion, useInView } from 'motion/react'
import { useEffect, useRef, useState } from 'react'
import { cn } from 'ui'
import { Dots, Stripes } from '../Visuals'
const titles = [
'Thank you to our community.',
'You created more Supabase databases in 2025 than in all previous years combined.',
"You've stored over 3.9B objects, and called almost 50B edge functions.",
"Together, we've launched new ideas, startups, community projects, weekend hackathons…",
'Thank you for building with us.',
]
const MIN_DISTANCE = 12 // Minimum distance between box centers (in percentage)
type FloatingBox = {
id: number
type: 'dots' | 'stripes'
top: number
left: number
size: string
drift: { x: number; y: number }
}
function getDistance(box1: { top: number; left: number }, box2: { top: number; left: number }) {
return Math.sqrt(Math.pow(box1.top - box2.top, 2) + Math.pow(box1.left - box2.left, 2))
}
function generateNonOverlappingPosition(
existingBoxes: FloatingBox[]
): { top: number; left: number } | null {
const maxAttempts = 20
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const top = Math.random() * 80 + 5
const left = Math.random() * 80 + 5
const hasOverlap = existingBoxes.some(
(box) => getDistance({ top, left }, { top: box.top, left: box.left }) < MIN_DISTANCE
)
if (!hasOverlap) {
return { top, left }
}
}
return null
}
function generateRandomBox(id: number, existingBoxes: FloatingBox[]): FloatingBox | null {
const position = generateNonOverlappingPosition(existingBoxes)
if (!position) {
return null
}
const movementType = Math.random()
let driftX = 0
let driftY = 0
if (movementType > 0.4) {
const driftAmount = (Math.random() > 0.5 ? 1 : -1) * 24
if (movementType > 0.7) {
driftX = driftAmount
} else {
driftY = driftAmount
}
}
return {
id,
type: Math.random() > 0.5 ? 'dots' : 'stripes',
top: position.top,
left: position.left,
size: `${Math.random() * 60 + 40}px`,
drift: { x: driftX, y: driftY },
}
}
function FloatingBoxes() {
const [floatingBoxes, setFloatingBoxes] = useState<FloatingBox[]>([])
const boxIdRef = useRef(0)
const lifetimeTimersRef = useRef<Set<NodeJS.Timeout>>(new Set())
const containerRef = useRef(null)
const isInView = useInView(containerRef, { once: false, amount: 0.3 })
useEffect(() => {
if (!isInView) {
// Clear all boxes when section goes out of view
setFloatingBoxes([])
lifetimeTimersRef.current.forEach(clearTimeout)
lifetimeTimersRef.current.clear()
return
}
const lifetimeTimers = lifetimeTimersRef.current
const spawnBox = () => {
setFloatingBoxes((prev) => {
const id = boxIdRef.current++
const newBox = generateRandomBox(id, prev)
if (!newBox) {
return prev
}
const lifetime = Math.random() * 2000 + 2000
const timerId = setTimeout(() => {
setFloatingBoxes((current) => current.filter((box) => box.id !== id))
lifetimeTimers.delete(timerId)
}, lifetime)
lifetimeTimers.add(timerId)
return [...prev, newBox]
})
}
const initialDelays = [0, 100, 200, 350, 500, 650, 800, 1000]
const initialTimers = initialDelays.map((delay) => setTimeout(spawnBox, delay))
let intervalId: NodeJS.Timeout
const scheduleNextSpawn = () => {
intervalId = setTimeout(
() => {
spawnBox()
scheduleNextSpawn()
},
300 + Math.random() * 300
)
}
scheduleNextSpawn()
return () => {
initialTimers.forEach(clearTimeout)
clearTimeout(intervalId)
lifetimeTimers.forEach(clearTimeout)
lifetimeTimers.clear()
}
}, [isInView])
return (
<div ref={containerRef} className="absolute inset-0">
<AnimatePresence>
{floatingBoxes.map((box) => (
<motion.div
key={box.id}
className={cn('absolute pointer-events-none border')}
style={{
top: `${box.top}%`,
left: `${box.left}%`,
width: box.size,
height: box.size,
}}
initial={{ opacity: 0, scale: 0.95, x: 0, y: 0 }}
animate={{ opacity: 0.6, scale: 1, x: box.drift.x, y: box.drift.y }}
exit={{ opacity: 0, scale: 0.95 }}
transition={{
opacity: { duration: 0.45 },
scale: { type: 'spring', duration: 0.45, bounce: 0.2 },
x: { type: 'spring', stiffness: 100, damping: 10 },
y: { type: 'spring', stiffness: 100, damping: 10 },
}}
>
{box.type === 'dots' ? <Dots /> : <Stripes />}
</motion.div>
))}
</AnimatePresence>
</div>
)
}
export const Intro = () => {
// Calculate the scroll percentage ranges for each title
const segmentSize = 100 / titles.length
return (
<Scrollytelling.Root>
<Scrollytelling.Pin childHeight={'100vh'} pinSpacerHeight={`${titles.length * 60}vh`} top={0}>
<section className="h-screen border-x border-b max-w-240 mx-auto w-[95%] md:w-full">
<div className="h-full grid place-items-center px-4 relative overflow-hidden">
{/* Floating boxes */}
<FloatingBoxes />
{/* Content - each title fades in/out based on scroll position */}
{titles.map((title, index) => {
const start = index * segmentSize
const fadeInEnd = start + segmentSize * 0.2
const fadeOutStart = start + segmentSize * 0.8
const end = (index + 1) * segmentSize
return (
<Scrollytelling.Animation
key={index}
tween={[
// Fade in: opacity 0 -> 1
{
start,
end: fadeInEnd,
to: { opacity: 1, filter: 'blur(0px)' },
},
// Fade out (except for last item)
...(index < titles.length - 1
? [
{
start: fadeOutStart,
end,
to: { opacity: 0, filter: 'blur(4px)' },
},
]
: []),
]}
>
<p
className="h1 text-center absolute inset-x-8 top-1/2 -translate-y-1/2"
style={{ opacity: 0, transform: 'translateY(calc(-50% + 30px))' }}
>
{title}
</p>
</Scrollytelling.Animation>
)
})}
</div>
</section>
</Scrollytelling.Pin>
</Scrollytelling.Root>
)
}