Files
supabase/apps/www/components/TabsWithHighlights.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

116 lines
3.8 KiB
TypeScript

import { Check } from 'lucide-react'
import { AnimatePresence, motion, useInView } from 'motion/react'
import { useTheme } from 'next-themes'
import Link from 'next/link'
import React, { useRef, useState } from 'react'
import { cn } from 'ui'
import BrowserFrame from './BrowserFrame'
export type Tab = {
label: string
panel: React.FC<{ isDark: boolean }>
highlights: { label: string; link?: string }[]
}
interface Props {
tabs: Tab[]
}
const TabsWithHighlights = (props: Props) => {
const { resolvedTheme } = useTheme()
const [activeTabIdx, setActiveTabIdx] = useState<number>(0)
const sectionRef = useRef(null)
const isInView = useInView(sectionRef, { once: true })
const Panel: any = props.tabs[activeTabIdx]?.panel ?? null
const highlights = props.tabs[activeTabIdx]?.highlights ?? [null]
const handleTabClick = (tabIndex: number) => {
setActiveTabIdx(tabIndex)
}
return (
<div className="relative flex flex-col gap-8 lg:gap-12 items-center">
{/* Threshold element used to load video 500px before reaching the video component */}
<div ref={sectionRef} className="absolute top-[-500px] not-sr-only" />
<div className="relative w-full col-span-full flex justify-center gap-2" role="tablist">
{props.tabs.map((tab, index) => (
<Tab
key={index}
isActive={index === activeTabIdx}
label={tab.label}
onClick={() => handleTabClick(index)}
/>
))}
</div>
<AnimatePresence mode="wait">
<motion.ul
key={props.tabs[activeTabIdx]?.label}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 0.1, delay: 0.2 } }}
exit={{ opacity: 0, transition: { duration: 0.05 } }}
className="position order-last lg:order-2 w-ful flex flex-wrap items-center gap-x-8 gap-y-4 lg:gap-8 justify-center text-center mx-auto z-30"
>
{highlights?.map((highlight) => (
<li key={highlight.label}>
<Link
href={highlight.link ?? '#'}
className="group cursor-pointer flex items-center gap-2 text-sm whitespace-nowrap text-foreground-light hover:text-foreground transition-colors hover:underline"
>
<Check className="stroke-2 w-4" />
<span>{highlight.label}</span>
</Link>
</li>
))}
</motion.ul>
</AnimatePresence>
<BrowserFrame
className="overflow-hidden lg:order-last bg-default w-full max-w-6xl mx-auto"
contentClassName="aspect-video border overflow-hidden rounded-lg"
>
{isInView && (
<AnimatePresence mode="wait">
<motion.div
key={props.tabs[activeTabIdx]?.label}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 0.1, delay: 0.2 } }}
exit={{ opacity: 0, transition: { duration: 0.05 } }}
className="relative w-full max-w-full h-full"
>
<Panel
key={resolvedTheme?.includes('dark')}
isDark={resolvedTheme?.includes('dark')}
/>
</motion.div>
</AnimatePresence>
)}
</BrowserFrame>
</div>
)
}
interface TabProps {
label: string
isActive: boolean
onClick: VoidFunction
}
const Tab = ({ label, isActive, onClick }: TabProps) => (
<button
tabIndex={0}
onClick={onClick}
aria-selected={isActive}
role="tab"
className={cn(
'py-1.5 px-3 lg:py-2 lg:px-8 border rounded-full bg-alternative hover:border-foreground text-sm opacity-80 transition-all',
'hover:border-foreground-lighter hover:text-foreground',
isActive ? 'opacity-100 border-foreground!' : ''
)}
>
{label}
</button>
)
export default TabsWithHighlights