mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## 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>
178 lines
5.2 KiB
TypeScript
178 lines
5.2 KiB
TypeScript
import 'swiper/css'
|
|
|
|
import { useBreakpoint } from 'common'
|
|
import { domAnimation, LazyMotion, m, useAnimation, useInView } from 'motion/react'
|
|
import React, { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
import { Swiper, SwiperSlide } from 'swiper/react'
|
|
import { cn } from 'ui'
|
|
|
|
interface TabProps {
|
|
label: string | React.ReactNode
|
|
paragraph?: string | React.ReactNode
|
|
isActive: boolean
|
|
onClick: VoidFunction
|
|
progress: number | undefined
|
|
intervalDuration?: number
|
|
}
|
|
|
|
const Tab = ({ isActive, label, paragraph, onClick, progress, intervalDuration }: TabProps) => {
|
|
const paragraphRef = useRef<HTMLParagraphElement | null>(null)
|
|
const [height, setHeight] = useState<number | 'auto'>('auto')
|
|
useEffect(() => {
|
|
if (!paragraphRef) return
|
|
setHeight(isActive ? (paragraphRef.current?.clientHeight ?? 0) : 0)
|
|
}, [isActive])
|
|
|
|
return (
|
|
<button
|
|
tabIndex={0}
|
|
onClick={onClick}
|
|
className={cn(
|
|
'hover:text-foreground w-full text-left text-lg flex flex-col group transition-all',
|
|
isActive ? 'text-foreground' : 'text-foreground-light'
|
|
)}
|
|
aria-selected={isActive}
|
|
role="tab"
|
|
>
|
|
<div className="flex flex-col py-4">
|
|
<h3 className="font-mono text-sm uppercase">{label}</h3>
|
|
<div
|
|
className={cn(
|
|
'text-foreground-lighter text-sm inline-block overflow-hidden transition-all',
|
|
isActive ? 'opacity-100' : 'opacity-0'
|
|
)}
|
|
style={{ height: isActive ? `${height}px` : 0 }}
|
|
>
|
|
<p ref={paragraphRef} className="pt-2">
|
|
{paragraph}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="relative w-full h-px bg-border-strong opacity-80 group-hover:opacity-100 rounded-full overflow-hidden">
|
|
<LazyMotion features={domAnimation}>
|
|
{isActive && (
|
|
<m.div
|
|
className={cn(
|
|
'absolute inset-0 w-full right-full bg-foreground h-full transition-opacity',
|
|
progress! > 99.7 ? 'opacity-0' : 'opacity-100'
|
|
)}
|
|
style={{ x: `${progress! - 100}%` }}
|
|
transition={{ duration: intervalDuration }}
|
|
/>
|
|
)}
|
|
</LazyMotion>
|
|
</div>
|
|
</button>
|
|
)
|
|
}
|
|
|
|
interface Tab {
|
|
label: ReactNode
|
|
paragraph?: ReactNode
|
|
panel?: ReactNode
|
|
code?: string
|
|
}
|
|
|
|
interface Props {
|
|
tabs: Tab[]
|
|
intervalDuration?: number
|
|
updateFrequency?: number
|
|
}
|
|
|
|
const TimedAccordionSection = ({ tabs, intervalDuration = 25, updateFrequency = 10 }: Props) => {
|
|
const ref = useRef(null)
|
|
const isInView = useInView(ref, { margin: '-25%' })
|
|
const [activeTab, setActiveTab] = useState(0)
|
|
const [progress, setProgress] = useState(0)
|
|
const [apiSwiper, setApiSwiper] = useState(undefined)
|
|
const controls = useAnimation()
|
|
const isMobile = useBreakpoint()
|
|
|
|
useEffect(() => {
|
|
if (!apiSwiper) return
|
|
// @ts-ignore
|
|
apiSwiper.slideTo(activeTab)
|
|
}, [activeTab])
|
|
|
|
const restartInterval = (tabIndex: number) => {
|
|
setProgress(0)
|
|
setActiveTab(tabIndex)
|
|
}
|
|
|
|
const animation = {
|
|
width: '100%',
|
|
transition: { duration: intervalDuration, ease: 'linear' },
|
|
}
|
|
|
|
useEffect(() => {
|
|
// pause timer when component is not in view
|
|
if (!isInView) {
|
|
controls.stop()
|
|
setProgress(progress)
|
|
return
|
|
}
|
|
|
|
const progressIncrement = (100 / intervalDuration) * (updateFrequency / 1000)
|
|
controls.start(animation)
|
|
const progressInterval = setInterval(() => {
|
|
setProgress((prevProgress) => (prevProgress + progressIncrement) % 101)
|
|
}, updateFrequency)
|
|
|
|
return () => {
|
|
clearInterval(progressInterval)
|
|
setProgress(0)
|
|
}
|
|
}, [activeTab, controls, isInView])
|
|
|
|
useEffect(() => {
|
|
if (progress >= 100.9) {
|
|
setActiveTab((prevActiveTab) => (prevActiveTab === tabs.length - 1 ? 0 : prevActiveTab + 1))
|
|
}
|
|
}, [progress])
|
|
|
|
const handleTabClick = (tabIndex: number) => {
|
|
// Disable trigger if tab is already active
|
|
if (tabIndex === activeTab) return
|
|
restartInterval(tabIndex)
|
|
}
|
|
|
|
return (
|
|
<div ref={ref} className="flex flex-col lg:flex-row gap-8 xl:gap-24 justify-between">
|
|
<div className="lg:w-1/3 gap-1 flex flex-col items-start" role="tablist">
|
|
{tabs.map((tab, index) => (
|
|
<Tab
|
|
key={index}
|
|
isActive={index === activeTab}
|
|
label={tab.label}
|
|
paragraph={tab.paragraph}
|
|
onClick={() => handleTabClick(index)}
|
|
progress={index === activeTab ? progress : undefined}
|
|
intervalDuration={intervalDuration}
|
|
/>
|
|
))}
|
|
</div>
|
|
<div className="relative w-full lg:flex-1 min-h-[400px] md:overflow-hidden -mt-4">
|
|
<Swiper
|
|
// @ts-ignore
|
|
onSwiper={setApiSwiper}
|
|
style={{ zIndex: 0, marginRight: '1px', overflow: 'visible' }}
|
|
initialSlide={activeTab}
|
|
spaceBetween={20}
|
|
onSlideChange={(s) => handleTabClick(s.activeIndex)}
|
|
slidesPerView={1}
|
|
speed={300}
|
|
allowTouchMove={isMobile}
|
|
>
|
|
{tabs.map((tab, i) => (
|
|
<SwiperSlide key={i} className="md:p-4">
|
|
{tab.panel}
|
|
</SwiperSlide>
|
|
))}
|
|
</Swiper>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default TimedAccordionSection
|