Files
supabase/apps/www/app/blog/BlogHero.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

121 lines
4.0 KiB
TypeScript

'use client'
import FeaturedThumb from 'components/Blog/FeaturedThumb'
import { motion } from 'motion/react'
import Image from 'next/image'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import type PostTypes from 'types/post'
import SectionContainer from '../../components/Layouts/SectionContainer'
import blogAuthors from '@/lib/authors.json'
function SecondarySpotlight({ post }: { post: PostTypes }) {
const resolveImagePath = (img: string | undefined): string | null => {
if (!img) return null
return img.startsWith('/') || img.startsWith('http') ? img : `/images/blog/${img}`
}
const imageUrl =
resolveImagePath(post.imgThumb) ||
resolveImagePath(post.imgSocial) ||
'/images/blog/blog-placeholder.png'
const authorNames = (post.author?.split(',') ?? [])
.map((id) => blogAuthors.find((a: any) => a.author_id === id.trim())?.author)
.filter(Boolean)
.join(', ')
return (
<Link
href={post.path}
prefetch={false}
className="group flex gap-4 items-center hover:bg-surface-200 dark:hover:bg-surface-75 p-2 sm:p-4 rounded-xl"
>
<div
className="relative hidden md:block shrink-0 w-36 aspect-[1.91/1] overflow-hidden rounded-md border border-foreground/10"
aria-hidden="true"
>
<Image
src={imageUrl}
fill
sizes="112px"
quality={80}
className="object-cover group-hover:scale-[1.03] transition-transform duration-300"
alt=""
/>
</div>
<div className="flex flex-col gap-1 min-w-0">
<h3 className="text-foreground text-sm leading-snug group-hover:underline line-clamp-3">
{post.title}
</h3>
{post.formattedDate && (
<p className="text-foreground-lighter text-xs">
<span className="sr-only">Published </span>
{post.formattedDate}
</p>
)}
{authorNames && (
<p className="text-foreground-light text-xs">
<span className="sr-only">Author: </span>
{authorNames}
</p>
)}
</div>
</Link>
)
}
/**
* Featured hero for the blog. Rendered by the blog route layout so it stays
* mounted across navigation between `/blog` and `/blog/categories/*`. It's only
* meant for the index, so on other blog routes we animate its height to 0 —
* collapsing it smoothly slides the page content up/down instead of jumping.
*/
export default function BlogHero({
featuredPost,
secondaryPosts,
}: {
featuredPost: PostTypes | null
secondaryPosts: PostTypes[]
}) {
const pathname = usePathname()
// Only mount the hero on the listing routes it animates between (index ⇄
// category). Elsewhere (posts, tags, authors) it's irrelevant — rendering it
// would needlessly preload the featured image.
const isListingRoute = pathname === '/blog' || Boolean(pathname?.startsWith('/blog/categories/'))
const expanded = pathname === '/blog'
if (!featuredPost || !isListingRoute) return null
// When collapsed, `inert` removes the clipped hero (and its links) from the
// a11y tree and tab order entirely.
const collapsedProps = expanded ? {} : ({ inert: '' } as any)
return (
<motion.div
{...collapsedProps}
initial={false}
animate={{ height: expanded ? 'auto' : 0, opacity: expanded ? 1 : 0 }}
transition={{ duration: 0.4, ease: [0.22, 1, 0.36, 1] }}
aria-hidden={!expanded}
className="overflow-hidden"
>
<SectionContainer className="py-6! md:py-8!">
<FeaturedThumb key={featuredPost.slug} {...featuredPost} />
{secondaryPosts.length > 0 && (
<ul
aria-label="More recent posts"
className="mt-4 pt-4 border-t border-muted grid grid-cols-1 sm:grid-cols-2 gap-4"
>
{secondaryPosts.map((post) => (
<li key={post.slug}>
<SecondarySpotlight post={post} />
</li>
))}
</ul>
)}
</SectionContainer>
</motion.div>
)
}