mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 23:59:08 +03:00
* add products pag subnav * functions page first sections * new functions page sections * functions dx section images * functions hero layout setup * functions page hero animation * final cta * revisit functions page structure * functions realtime logs animation * functions query logs animation * function metrics chart * finish edge functions hero animation * finish edge functions metrics graph * update products cta section * edge functions page code cleanup * restore Panel * restore code block bg * pause timed sections when not in view to optimize perf * create new code window component and add functions code snippets * finish edge functions * update functions page * improve animation timing in functions page * fix type error * clean up functions page code * update swiper and fix hydration errors * fix swiper module import * fix swiper css import * image bg * edge functions page details fix * fix scroll bug * edge functions page * finalize edge functions page * add anchors and improve semantics * remove double prop * add links to docs * add link to edge runtime * fix timed panel progress bar retrigger * fix timed accordion progress bar retrigger
92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
// Import Swiper styles if swiper used on page
|
|
import 'swiper/css'
|
|
|
|
import { useState } from 'react'
|
|
import { Button, IconArrowUpRight, Tabs } from 'ui'
|
|
import { Swiper, SwiperSlide } from 'swiper/react'
|
|
import CodeBlock from '../CodeBlock/CodeBlock'
|
|
import Link from 'next/link'
|
|
|
|
interface Example {
|
|
lang: 'js' | 'py' | 'sql'
|
|
title: string
|
|
code: string
|
|
}
|
|
|
|
interface Props {
|
|
size?: 'small' | 'large'
|
|
content: Example[]
|
|
title: string | React.ReactNode
|
|
footer?: React.ReactNode
|
|
text?: React.ReactNode
|
|
autoHeight?: boolean
|
|
documentation_link?: 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="h3">{props.title}</h2>
|
|
<div className="p">{props.text}</div>
|
|
{props.documentation_link && (
|
|
<Button asChild size="small" className="mt-4" type="default" icon={<IconArrowUpRight />}>
|
|
<Link href={props.documentation_link} as={props.documentation_link}>
|
|
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">
|
|
<Tabs
|
|
scrollable
|
|
activeId={apiSwiperActiveIndex.toString()}
|
|
onChange={(id: string) => handleApiSwiperNavChange(Number(id))}
|
|
>
|
|
{props.content &&
|
|
props.content.map((content: Example, i) => (
|
|
<Tabs.Panel label={content.title} id={i.toString()} key={i}>
|
|
<span key={i}></span>
|
|
</Tabs.Panel>
|
|
))}
|
|
</Tabs>
|
|
<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: Example, i) => (
|
|
<SwiperSlide key={i}>
|
|
<CodeBlock key={i} lang={content.lang} size={props.size ? props.size : 'small'}>
|
|
{content.code}
|
|
</CodeBlock>
|
|
</SwiperSlide>
|
|
))}
|
|
</Swiper>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default APISection
|