Files
supabase/apps/docs/features/getting-started/GettingStartedStepper.client.tsx
T
anthony lio 22ea45a3ba feat: getting started v2 (#52511)
## Problem

* the getting started page is a stack of content listings: an overview,
use cases, framework quickstarts and tutorials
* a new reader must find a path in that list, and the page gives no
commands or agent prompt for their setup

## Solution

* adds a stepper to the getting started page, so a reader gets the steps
and an agent prompt for their setup
* adds the `docs-getting-started-v2` posthog flag, so the stepper and
the current page can run as an a/b test
* adds events for stepper choices, link clicks and prompt copies, so the
test can compare the two pages
* adds a markdown export of the stepper, so the `.md` page lists every
path for agents
* moves the iso shapes from kb into `ui-patterns`, so the docs feature
cards use the same shapes as the kb heroes
* changes the edge functions shape to a flat puzzle piece, because the
old shape had too many parts

<!-- linear:table-colwidths:397,397 -->
<table>
<thead>
<tr>
<th>state</th>
<th>preview</th>
</tr>
</thead>
<tbody>
<tr>
<td>after</td>
<td>


https://github.com/user-attachments/assets/7127d817-4240-4d08-a1c9-6ada1b1b2563

</td>
</tr>
</tbody>
</table>

## Review instructions

1. open
[/docs/guides/getting-started?docs-getting-started-v2=stepper](<https://docs-git-docs-getting-started-explorations-supabase.vercel.app/docs/guides/getting-started?docs-getting-started-v2=stepper>)
and make sure that the stepper shows with agent selected
2. select next.js and the auth card, then make sure that the setup
prompt names next.js and has a step for auth
3. open
[/docs/guides/getting-started?docs-getting-started-v2=stepper&start=cli&fw=nextjs](<https://docs-git-docs-getting-started-explorations-supabase.vercel.app/docs/guides/getting-started?docs-getting-started-v2=stepper&start=cli&fw=nextjs>)
and make sure that connect your app shows the install command and the
quickstart button

## Checklist

Check all before review:

- [X] I have read
[CONTRIBUTING.md](<https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md>)
- [ ] 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>)
2026-11-13 17:46:38 +02:00

635 lines
23 KiB
TypeScript

'use client'
import { StepHikeCompact } from '~/components/StepHikeCompact'
import { SOURCE_FOOTER_CLASSES, SourceFrame } from '~/features/directives/CodeSample.client'
import { CodeTabs } from '~/features/directives/CodeTabs.components'
import { IconLinkImage } from '~/features/ui/IconLink'
import {
Prompt,
PromptContent,
PromptCopy,
PromptMarkdown,
PromptPanel,
PromptTitle,
} from '~/features/ui/PromptPanel'
import { TabPanel } from '~/features/ui/Tabs'
import { useSendTelemetryEvent } from '~/lib/telemetry'
import { useSearchParamsShallow } from 'common'
import { type DocsContentListingClickedEvent } from 'common/telemetry-constants'
import { ArrowRight, ArrowUpRight, Check } from 'lucide-react'
import { animate, useMotionValue, useMotionValueEvent, useReducedMotion } from 'motion/react'
import Link from 'next/link'
import { RadioGroup } from 'radix-ui'
import { useId, useState, type ReactNode } from 'react'
import { Badge, Button, cn, ToggleGroup, ToggleGroupItem } from 'ui'
import { IsoShape } from 'ui-patterns/IsoShape/IsoShape'
import { FLUID_RISE_MS } from 'ui-patterns/IsoShape/IsoShape.glyphs'
import {
CREATE_PROJECT_URL,
EXPLORE_ITEMS,
NEXT_STEPS,
parseChoices,
START_OPTIONS,
type ExploreItem,
} from './GettingStarted.data'
import { FRAMEWORK_GROUPS, getFramework } from './GettingStarted.frameworks'
import { buildPrompt } from './GettingStarted.prompts'
import { useGettingStartedVariant } from './useGettingStartedVariant'
interface GettingStartedVariantSwitchProps {
control: ReactNode
children: ReactNode
}
interface GettingStartedStepperClientProps {
localCommandsCode: ReactNode
installCodes: Record<string, ReactNode>
}
interface StepperLink {
href: string
title: string
groupTitle: string
}
interface ExploreCardProps {
item: ExploreItem
}
interface LinkCardProps extends StepperLink {
motionHandlers?: ShapeMotion['motionHandlers']
children: ReactNode
}
interface FeatureToggleCardProps {
item: ExploreItem
isSelected: boolean
onFeatureToggle: (id: string) => void
}
interface NotchCardProps {
notch: ReactNode
isSelected?: boolean
children: ReactNode
}
interface ChoiceIndicatorProps {
type: 'checkbox' | 'radio'
isSelected: boolean
}
interface FilledCheckProps {
shape: 'circle' | 'square'
}
interface FeatureCardBodyProps {
item: Pick<ExploreItem, 'name' | 'description'> & Partial<Pick<ExploreItem, 'feature'>>
}
interface ShapeMotion {
shapeProps: { yaw: number; activation: number; fluidStep: number }
motionHandlers: {
onPointerEnter: () => void
onPointerLeave: () => void
onFocus: () => void
onBlur: () => void
}
}
interface StartChoiceCardsProps {
value: string
onValueChange: (value: string) => void
}
// builds without framework quickstarts skip the framework step
const HAS_FRAMEWORKS = FRAMEWORK_GROUPS.length > 0
const FULL_TURN = Math.PI * 2
const TURN_DURATION_S = 2.4
const ACTIVATE_DURATION_S = 0.7
const toStepperLinkEvent = ({
href,
title,
groupTitle,
}: StepperLink): DocsContentListingClickedEvent => ({
action: 'docs_content_listing_clicked',
properties: {
targetPath: href,
linkTitle: title,
groupTitle,
listingId: 'getting-started-stepper',
},
})
const useShapeMotion = (): ShapeMotion => {
const yaw = useMotionValue(0)
const activation = useMotionValue(0)
const [renderedYaw, setRenderedYaw] = useState(0)
const [renderedActivation, setRenderedActivation] = useState(0)
const shouldReduceMotion = useReducedMotion()
useMotionValueEvent(yaw, 'change', setRenderedYaw)
useMotionValueEvent(activation, 'change', setRenderedActivation)
const handleActivate = () => {
animate(activation, 1, {
duration: shouldReduceMotion ? 0 : ACTIVATE_DURATION_S,
ease: 'easeOut',
})
if (shouldReduceMotion) return
animate(yaw, yaw.get() + FULL_TURN, {
duration: TURN_DURATION_S,
ease: 'linear',
repeat: Infinity,
})
}
const handleDeactivate = () => {
animate(activation, 0, {
duration: shouldReduceMotion ? 0 : ACTIVATE_DURATION_S,
ease: 'easeOut',
})
animate(yaw, Math.round(yaw.get() / FULL_TURN) * FULL_TURN, {
duration: 0.6,
ease: 'easeOut',
})
}
return {
shapeProps: {
yaw: renderedYaw,
activation: renderedActivation,
// the glyphs move only while the shape turns
fluidStep: Math.floor(renderedYaw / (FULL_TURN / ((TURN_DURATION_S * 1000) / FLUID_RISE_MS))),
},
motionHandlers: {
onPointerEnter: handleActivate,
onPointerLeave: handleDeactivate,
onFocus: handleActivate,
onBlur: handleDeactivate,
},
}
}
// flags load in the browser, so the server html and readers without javascript get the control
export const GettingStartedVariantSwitch = ({
control,
children,
}: GettingStartedVariantSwitchProps) => {
const { variant, isReady } = useGettingStartedVariant()
return (
<div className={cn(!isReady && 'invisible noscript:visible')}>
{variant === 'stepper' ? children : control}
</div>
)
}
export const GettingStartedStepperClient = ({
localCommandsCode,
installCodes,
}: GettingStartedStepperClientProps) => {
const searchParams = useSearchParamsShallow()
const choices = parseChoices(searchParams)
const framework = getFramework(choices.fw)
const isAgent = choices.start === 'agent'
const setupPrompt = buildPrompt(choices.features)
const sendTelemetryEvent = useSendTelemetryEvent()
const [selectedGroupId, setSelectedGroupId] = useState<string | null>(null)
// until the reader picks a group, show the first group that holds the framework
const activeGroup =
FRAMEWORK_GROUPS.find((group) => group.id === selectedGroupId) ??
FRAMEWORK_GROUPS.find((group) => group.frameworks.some((item) => item.slug === choices.fw)) ??
FRAMEWORK_GROUPS[0]
const handleStartChange = (start: string) => {
searchParams.set('start', start)
sendTelemetryEvent({
action: 'docs_getting_started_option_clicked',
properties: { optionType: 'start', optionId: start },
})
}
const handleFrameworkChange = (fw: string) => {
searchParams.set('fw', fw)
sendTelemetryEvent({
action: 'docs_getting_started_option_clicked',
properties: { optionType: 'framework', optionId: fw },
})
}
// an empty list means the reader skipped the step, so the prompt asks
const handleFeatureToggle = (id: string) => {
const wasSelected = choices.features.includes(id)
searchParams.set(
'features',
wasSelected
? choices.features.filter((feature) => feature !== id).join(',')
: [...choices.features, id].join(',')
)
sendTelemetryEvent({
action: 'docs_getting_started_option_clicked',
properties: { optionType: 'feature', optionId: id, isSelected: !wasSelected },
})
}
const handleQuickstartClick = () => {
if (!framework) return
sendTelemetryEvent(
toStepperLinkEvent({
href: framework.href,
title: `${framework.name} quickstart`,
groupTitle: 'Connect your app',
})
)
}
const handleCreateProjectClick = () =>
sendTelemetryEvent(
toStepperLinkEvent({
href: CREATE_PROJECT_URL,
title: 'Create a project',
groupTitle: 'Create a project',
})
)
const handleGroupChange = (groupId: string) => {
const group = FRAMEWORK_GROUPS.find((item) => item.id === groupId)
if (!group) return
setSelectedGroupId(group.id)
if (!group.frameworks.some((item) => item.slug === choices.fw)) {
searchParams.delete('fw')
}
}
return (
<div className="not-prose @container flex flex-col gap-12">
<p className="m-0 text-lg text-foreground-light">
Create a Supabase project and connect it to your app.
</p>
<StepHikeCompact title="Get started">
<StepHikeCompact.Step step={1} title="Choose how to start">
<StepHikeCompact.Details title="Choose how to start">
<p className="m-0 text-sm text-foreground-light">
Let your AI agent set up Supabase, run Supabase locally, or create a hosted project.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<StartChoiceCards value={choices.start} onValueChange={handleStartChange} />
</StepHikeCompact.Code>
</StepHikeCompact.Step>
{choices.start === 'cli' ? (
<StepHikeCompact.Step step={2} title="Run Supabase locally">
<StepHikeCompact.Details title="Run Supabase locally">
<p className="m-0 text-sm text-foreground-light">
Install the Supabase CLI, initialize your project, then start the local stack. The
CLI needs Node.js 20 or later, and the local stack needs Docker or another container
runtime. Without a Node.js project,{' '}
<Link
href="/guides/local-development/cli/getting-started"
className="text-foreground underline underline-offset-4"
>
install the CLI for your operating system
</Link>{' '}
instead.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>{localCommandsCode}</StepHikeCompact.Code>
</StepHikeCompact.Step>
) : choices.start === 'dashboard' ? (
<StepHikeCompact.Step step={2} title="Create a project">
<StepHikeCompact.Details title="Create a project">
<p className="m-0 text-sm text-foreground-light">
Create a hosted project in the Supabase Dashboard, then return here to connect your
app.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<Button
asChild
variant="primary"
size="small"
iconRight={<ArrowUpRight aria-hidden strokeWidth={2.25} />}
className="w-fit"
>
<a
href={CREATE_PROJECT_URL}
target="_blank"
rel="noreferrer noopener"
onClick={handleCreateProjectClick}
>
Create a project
<span className="sr-only"> (opens in a new tab)</span>
</a>
</Button>
</StepHikeCompact.Code>
</StepHikeCompact.Step>
) : null}
{/* the agent reads the framework from the project, so only the manual paths ask for it */}
{isAgent || !HAS_FRAMEWORKS ? null : (
<StepHikeCompact.Step step={3} title="Choose your framework">
<StepHikeCompact.Details title="Choose your framework">
<p className="m-0 text-sm text-foreground-light">
Choose the framework your app uses.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<CodeTabs value={activeGroup.id} onValueChange={handleGroupChange}>
{FRAMEWORK_GROUPS.map((group) => (
<TabPanel key={group.id} id={group.id} label={group.label}>
<div className="overflow-hidden rounded-lg border border-default bg-200">
<div className="flex flex-wrap items-center gap-2 px-3 py-3">
<ToggleGroup
type="single"
size="tiny"
allowDeselect={false}
aria-label="Framework"
value={choices.fw ?? ''}
onValueChange={handleFrameworkChange}
className="flex-wrap justify-start gap-x-6 gap-y-1"
>
{group.frameworks.map((item) => (
<ToggleGroupItem
key={item.slug}
value={item.slug}
className="cursor-pointer gap-1.5 px-0 hover:bg-transparent hover:text-foreground focus-visible:text-foreground data-[state=on]:bg-transparent"
>
<span className="flex size-4 items-center justify-center [&_img]:w-4">
{item.slug === choices.fw ? (
<FilledCheck shape="circle" />
) : (
<IconLinkImage
path={item.icon}
hasLightIcon={item.hasLightIcon}
/>
)}
</span>
{item.name}
</ToggleGroupItem>
))}
</ToggleGroup>
{framework?.isCommunity ? <Badge>Community SDK</Badge> : null}
</div>
</div>
</TabPanel>
))}
</CodeTabs>
</StepHikeCompact.Code>
</StepHikeCompact.Step>
)}
{isAgent || !framework ? null : (
<StepHikeCompact.Step step={4} title="Connect your app">
<StepHikeCompact.Details title="Connect your app">
<p className="m-0 text-sm text-foreground-light">
{framework.install
? `Install the client library, then follow the ${framework.name} quickstart.`
: framework.sdk === 'postgres'
? `The ${framework.name} quickstart connects your app to Supabase with a Postgres connection string.`
: `The ${framework.name} quickstart covers installing the client library.`}
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<div className="flex flex-col gap-4">
{framework.install ? installCodes[framework.install] : null}
<Button asChild variant="default" size="small" className="w-fit">
<Link href={framework.href} onClick={handleQuickstartClick}>
Follow the {framework.name} quickstart
</Link>
</Button>
</div>
</StepHikeCompact.Code>
</StepHikeCompact.Step>
)}
{isAgent ? (
<StepHikeCompact.Step step={2} title="Add features">
<StepHikeCompact.Details title="Add features">
<p className="m-0 text-sm text-foreground-light">
Choose the features your app needs. If you&apos;re not sure, skip this step and let
your agent help you later.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<ul className="m-0 grid list-none grid-cols-1 gap-4 p-0 @lg:grid-cols-2 @3xl:grid-cols-3">
{/* the prompt already installs the Supabase plugin, so agent mode skips that card */}
{EXPLORE_ITEMS.filter((item) => item.id !== 'ai-tools').map((item) => (
<li key={item.id}>
<FeatureToggleCard
item={item}
isSelected={choices.features.includes(item.id)}
onFeatureToggle={handleFeatureToggle}
/>
</li>
))}
</ul>
</StepHikeCompact.Code>
</StepHikeCompact.Step>
) : null}
{isAgent ? (
<StepHikeCompact.Step step={3} title="Copy the prompt into your agent">
<StepHikeCompact.Details title="Copy the prompt into your agent">
<p className="m-0 text-sm text-foreground-light">
Your agent finds your framework, installs the Supabase CLI and the Supabase plugin,
sets up a project, connects your app, then checks that your app reads data.
</p>
</StepHikeCompact.Details>
<StepHikeCompact.Code>
<PromptPanel telemetry={{ source: 'guide', promptId: 'getting-started-setup' }}>
<Prompt value="prompt" expandable>
<PromptTitle>Agent Prompt</PromptTitle>
<PromptCopy>{setupPrompt}</PromptCopy>
<PromptContent>
<PromptMarkdown>{setupPrompt}</PromptMarkdown>
</PromptContent>
</Prompt>
</PromptPanel>
</StepHikeCompact.Code>
</StepHikeCompact.Step>
) : null}
</StepHikeCompact>
<section aria-labelledby="next-steps" className="flex flex-col gap-4">
<h2 id="next-steps" className="m-0 text-xl text-foreground">
Next steps
</h2>
<ul className="m-0 grid list-none grid-cols-1 gap-4 p-0 @lg:grid-cols-2 @3xl:grid-cols-3">
{/* agent mode selects features in an earlier step, so these cards only link */}
{isAgent
? NEXT_STEPS.map((step) => (
<li key={step.id}>
<LinkCard href={step.href} title={step.title} groupTitle="Next steps">
<FeatureCardBody item={{ name: step.title, description: step.description }} />
</LinkCard>
</li>
))
: EXPLORE_ITEMS.map((item) => (
<li key={item.id}>
<ExploreCard item={item} />
</li>
))}
</ul>
</section>
</div>
)
}
const ExploreCard = ({ item }: ExploreCardProps) => {
const { shapeProps, motionHandlers } = useShapeMotion()
const grainId = useId().replace(/[^a-zA-Z0-9_-]/g, '')
return (
<LinkCard
href={item.href}
title={item.name}
groupTitle="Add features"
motionHandlers={motionHandlers}
>
<span style={{ filter: `url(#${grainId})` }} className="flex">
<svg aria-hidden className="absolute size-0">
{/* srgb keeps the dark fill's color. the default linear rgb shifts it toward green */}
<filter id={grainId} colorInterpolationFilters="sRGB">
<feTurbulence type="fractalNoise" baseFrequency={1.1} numOctaves={1} seed={7} />
<feColorMatrix
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.4 0 0 0 -0.55"
result="grain"
/>
<feComposite in="SourceGraphic" in2="grain" operator="in" />
</filter>
</svg>
<IsoShape
name={item.shape}
{...shapeProps}
preserveAspectRatio="xMinYMid meet"
className={cn(
'h-20 w-28 fill-background-200 text-foreground-muted transition-colors group-hover/card:fill-background-surface-300 group-focus-visible/card:fill-background-surface-300',
item.shapeClassName
)}
/>
</span>
<FeatureCardBody item={item} />
</LinkCard>
)
}
const LinkCard = ({ href, title, groupTitle, motionHandlers, children }: LinkCardProps) => {
const sendTelemetryEvent = useSendTelemetryEvent()
const handleClick = () => sendTelemetryEvent(toStepperLinkEvent({ href, title, groupTitle }))
return (
<Link
href={href}
{...motionHandlers}
onClick={handleClick}
className="group/card block h-full rounded-lg focus-ring"
>
<NotchCard
notch={
<ArrowRight
strokeWidth={2.25}
className={cn(
'size-3.5 -translate-x-7 transition-transform duration-200 ease-enter motion-reduce:transition-none',
'group-hover/card:translate-x-px group-focus-visible/card:translate-x-px'
)}
/>
}
>
{children}
</NotchCard>
</Link>
)
}
const FeatureToggleCard = ({ item, isSelected, onFeatureToggle }: FeatureToggleCardProps) => {
const handleClick = () => onFeatureToggle(item.id)
return (
<button
type="button"
tabIndex={0}
aria-pressed={isSelected}
onClick={handleClick}
className="group/card block h-full w-full cursor-pointer rounded-lg text-left focus-ring"
>
<NotchCard
notch={<ChoiceIndicator type="checkbox" isSelected={isSelected} />}
isSelected={isSelected}
>
<FeatureCardBody item={item} />
</NotchCard>
</button>
)
}
const NotchCard = ({ notch, isSelected, children }: NotchCardProps) => (
<span className="block h-full [&_.code-sample-source]:h-full [&_.codeblock-drop-shadow]:h-full [&_.shiki-wrapper]:my-0!">
<SourceFrame
notchWidth={40}
footer={
<span aria-hidden className={cn(SOURCE_FOOTER_CLASSES, 'justify-center overflow-hidden')}>
{notch}
</span>
}
>
<span
className={cn(
'code-sample-surface flex h-full flex-col gap-4 rounded-lg border border-default p-5 transition-colors group-hover/card:bg-surface-300 group-focus-visible/card:bg-surface-300',
isSelected ? 'bg-surface-300' : 'bg-200'
)}
>
{children}
</span>
</SourceFrame>
</span>
)
const ChoiceIndicator = ({ type, isSelected }: ChoiceIndicatorProps) => {
if (isSelected) return <FilledCheck shape={type === 'checkbox' ? 'square' : 'circle'} />
return (
<span
className={cn(
'size-4 border border-strong',
type === 'checkbox' ? 'rounded-sm' : 'rounded-full'
)}
/>
)
}
const FilledCheck = ({ shape }: FilledCheckProps) => (
<span
className={cn(
'flex size-4 items-center justify-center bg-foreground text-background',
shape === 'circle' ? 'rounded-full' : 'rounded-sm'
)}
>
<Check strokeWidth={5} className="size-2" />
</span>
)
const FeatureCardBody = ({ item }: FeatureCardBodyProps) => (
<span className="flex flex-col gap-1">
<span className="flex flex-wrap items-center gap-2 text-base text-foreground">
{item.name}
{item.feature ? <Badge>{item.feature}</Badge> : null}
</span>
<span className="pr-10 text-sm text-foreground-light">{item.description}</span>
</span>
)
// the radix primitive keeps arrow key movement between the cards
const StartChoiceCards = ({ value, onValueChange }: StartChoiceCardsProps) => (
<RadioGroup.Root
aria-label="Choose how to start"
value={value}
onValueChange={onValueChange}
className="grid grid-cols-1 gap-4 @lg:grid-cols-3"
>
{START_OPTIONS.map((option) => (
<RadioGroup.Item
key={option.id}
value={option.id}
className="group/card block h-full w-full cursor-pointer rounded-lg text-left focus-ring"
>
<NotchCard
notch={<ChoiceIndicator type="radio" isSelected={value === option.id} />}
isSelected={value === option.id}
>
<FeatureCardBody item={{ name: option.label, description: option.description }} />
</NotchCard>
</RadioGroup.Item>
))}
</RadioGroup.Root>
)