Files
supabase/apps/www/components/Sections/APISection.tsx
Gildas Garcia d7543d536f chore: www Tabs migration (#47449)
## Problem

We're still maintaining the old `Tabs` component which is deprecated.

## Solution

Cleanup its usages in `www`:
- Remove dead code
- Migrate actual tabs to the new Shadcn component
- Migrate non tabs to use `Button` instead

There should be almost no visual changes (slight background color change
on the active button below):

- https://zone-www-dot-8z5cao88c-supabase.vercel.app/solutions/agencies
(at the bottom)

Before:
<img width="999" height="412" alt="image"
src="https://github.com/user-attachments/assets/97675380-e5fb-4e7e-a39e-93bcc0f2f70f"
/>

After:
<img width="732" height="377" alt="image"
src="https://github.com/user-attachments/assets/c4150142-218d-4c32-b8ce-f68f4939706e"
/>

-
https://zone-www-dot-8z5cao88c-supabase.vercel.app/blog/postgres-full-text-search-vs-the-rest#results

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Simplified navigation in API examples and chart tabs for a more
consistent browsing experience.
  * Updated chart tab switching to better match the current UI behavior.
* **Refactor**
* Removed several carousel and admin access components, along with
related styling, reducing unused page elements.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-30 16:32:02 +02:00

105 lines
3.2 KiB
TypeScript

// Import Swiper styles if swiper used on page
import 'swiper/css'
import { ArrowUpRight } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
import { Swiper, SwiperSlide } from 'swiper/react'
import { Button, cn } from 'ui'
import CodeBlock, { LANG } from '../CodeBlock/CodeBlock'
export interface APIExample {
lang: LANG
title: string
code: string
}
interface Props {
size?: 'small' | 'large'
content: APIExample[]
title: string | React.ReactNode
footer?: React.ReactNode
text?: React.ReactNode
autoHeight?: boolean
documentation_link?: string
showLineNumbers?: boolean
ctaLabel?: string
}
function APISection(props: Props) {
// store API swiper instance
const [apiSwiper, setApiSwiper] = useState(undefined)
const [apiSwiperActiveIndex, setApiSwiperActiveIndex] = useState(0)
function handleApiSwiperNavChange(e: number) {
setApiSwiperActiveIndex(e)
// @ts-ignore
apiSwiper.slideTo(e)
}
return (
<div className="grid grid-cols-12 lg:gap-16">
<div className="col-span-12 pb-8 lg:col-span-5 xl:col-span-5">
<h2 className="h2">{props.title}</h2>
<div className="p">{props.text}</div>
{props.documentation_link && (
<Button asChild size="small" className="mt-4" variant="default" icon={<ArrowUpRight />}>
<Link href={props.documentation_link} as={props.documentation_link}>
{props.ctaLabel ? props.ctaLabel : 'Explore documentation'}
</Link>
</Button>
)}
{props.footer && <div className="py-8">{props.footer}</div>}
</div>
<div className="sbui-tabs--alt col-span-12 lg:col-span-7 xl:col-span-6 xl:col-start-7">
<div className="flex gap-2 mb-2">
{props.content &&
props.content.map((content: APIExample, i) => (
<Button
id={i.toString()}
variant={apiSwiperActiveIndex === i ? 'default' : 'outline'}
className={cn({
'text-muted hover:text-foreground': apiSwiperActiveIndex !== i,
})}
key={i}
onClick={() => handleApiSwiperNavChange(i)}
>
{content.title}
</Button>
))}
</div>
<div className="overflow-hidden">
<Swiper
// @ts-ignore
onSwiper={setApiSwiper}
style={{ zIndex: 0, marginRight: '1px' }}
initialSlide={apiSwiperActiveIndex}
spaceBetween={0}
slidesPerView={1}
speed={300}
allowTouchMove={false}
autoHeight={props.autoHeight ? props.autoHeight : false}
>
{props.content &&
props.content.map((content: APIExample, i) => (
<SwiperSlide key={i}>
<CodeBlock
key={i}
lang={content.lang}
size={props.size ? props.size : 'small'}
showLineNumbers={props.showLineNumbers}
>
{content.code}
</CodeBlock>
</SwiperSlide>
))}
</Swiper>
</div>
</div>
</div>
)
}
export default APISection