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>
209 lines
6.1 KiB
TypeScript
209 lines
6.1 KiB
TypeScript
import 'swiper/css'
|
|
|
|
import { useBreakpoint } from 'common'
|
|
import { domAnimation, LazyMotion, m, useAnimation, useInView } from 'motion/react'
|
|
import React, { useEffect, useRef, useState } from 'react'
|
|
import { Swiper, SwiperSlide } from 'swiper/react'
|
|
import { cn } from 'ui'
|
|
|
|
import Panel from '../Panel'
|
|
|
|
interface PanelProps {
|
|
id: string
|
|
label: string | React.ReactNode
|
|
paragraph?: string
|
|
icon?: React.ReactNode
|
|
isActive?: boolean
|
|
isInView?: boolean
|
|
onClick?: VoidFunction
|
|
progress?: number | undefined
|
|
intervalDuration?: number
|
|
image?: any
|
|
}
|
|
|
|
const TimedPanel = ({
|
|
isActive,
|
|
label,
|
|
paragraph,
|
|
onClick,
|
|
progress,
|
|
intervalDuration,
|
|
image,
|
|
isInView,
|
|
}: PanelProps) => {
|
|
const isSm = useBreakpoint()
|
|
const Image: any = image ?? null
|
|
|
|
return (
|
|
<button
|
|
tabIndex={0}
|
|
onMouseEnter={() => !isSm && onClick && onClick()}
|
|
onClick={() => isSm && onClick && onClick()}
|
|
className={cn(
|
|
'relative hover:text-foreground w-full h-[500px] text-left text-lg flex flex-col group transition-all',
|
|
isActive ? 'text-foreground md:flex-2' : 'text-foreground-light md:flex-1'
|
|
)}
|
|
aria-selected={isActive}
|
|
role="tab"
|
|
>
|
|
<Panel outerClassName="w-full h-full mb-4" innerClassName="p-4">
|
|
<div className="relative z-10 flex flex-col h-full justify-between">
|
|
<h3
|
|
className={cn(
|
|
'font-mono text-sm uppercase transition-colors',
|
|
isActive && 'text-foreground'
|
|
)}
|
|
>
|
|
{label}
|
|
</h3>
|
|
<p
|
|
className={cn(
|
|
'pt-2 text-foreground-lighter text-sm max-w-[220px] md:opacity-0 transition-opacity lg:opacity-100',
|
|
isActive && 'opacity-100!'
|
|
)}
|
|
>
|
|
{paragraph}
|
|
</p>
|
|
</div>
|
|
<div
|
|
className={cn(
|
|
'absolute h-[calc(100%-150px)] mt-14 inset-0 m-auto flex items-center justify-center transition-opacity',
|
|
isActive ? 'opacity-100' : 'opacity-25'
|
|
)}
|
|
>
|
|
<div
|
|
className={cn(
|
|
'absolute z-20 w-full h-full inset-0 bg-linear-to-r from-transparent to-background-surface-100 transition-opacity pointer-events-none',
|
|
isActive && 'opacity-0'
|
|
)}
|
|
/>
|
|
<Image isActive={isActive} isInView={isInView} />
|
|
</div>
|
|
</Panel>
|
|
{!isSm && isActive && (
|
|
<div className="opacity-0 animate-fade-in absolute bottom-0 w-full h-px bg-border-strong group-hover:opacity-100 rounded-full overflow-hidden">
|
|
<LazyMotion features={domAnimation}>
|
|
<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 Props {
|
|
panels: PanelProps[]
|
|
intervalDuration?: number
|
|
updateFrequency?: number
|
|
isInView?: boolean
|
|
}
|
|
|
|
const TimedAccordionPanels = ({ panels, intervalDuration = 10, 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()
|
|
|
|
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)
|
|
}
|
|
}, [isInView])
|
|
|
|
useEffect(() => {
|
|
if (progress >= 100.9) {
|
|
setActiveTab((prevActiveTab) => (prevActiveTab === panels.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 gap-8 xl:gap-32 justify-between">
|
|
<div className="hidden md:flex gap-4" role="tablist">
|
|
{panels.map((panel, index) => (
|
|
<TimedPanel
|
|
key={index}
|
|
isActive={index === activeTab}
|
|
isInView={isInView}
|
|
onClick={() => handleTabClick(index)}
|
|
progress={index === activeTab ? progress : undefined}
|
|
intervalDuration={intervalDuration}
|
|
{...panel}
|
|
/>
|
|
))}
|
|
</div>
|
|
<div className="md:hidden relative w-full lg:w-1/2 min-h-[300px] overflow-visible">
|
|
<Swiper
|
|
// @ts-ignore
|
|
onSwiper={setApiSwiper}
|
|
style={{ zIndex: 0, overflow: 'visible' }}
|
|
initialSlide={0}
|
|
spaceBetween={10}
|
|
onSlideChange={(s) => handleTabClick(s.activeIndex)}
|
|
slidesPerView={1.1}
|
|
speed={300}
|
|
>
|
|
{panels.map((panel, index) => (
|
|
<SwiperSlide key={index}>
|
|
<TimedPanel
|
|
isActive={index === activeTab}
|
|
isInView={isInView}
|
|
onClick={() => handleTabClick(index)}
|
|
progress={index === activeTab ? progress : undefined}
|
|
intervalDuration={intervalDuration}
|
|
{...panel}
|
|
/>
|
|
</SwiperSlide>
|
|
))}
|
|
</Swiper>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default TimedAccordionPanels
|