mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem The C# and Kotlin client libraries are now official Supabase SDKs. Several places in the docs and README still call them community libraries. ## Solution - **Client libraries page**: move Kotlin from "Community libraries" to "Official libraries". C# was already listed as official. - **Kotlin reference intros (v1, v2, v3)**: replace the "not an official library" note with a note that supabase-kt is official. The thanks to the original maintainer and contributors stays. - **Docs nav**: drop the `community: true` flag on the Kotlin entry in both nav configs. - **Getting Started stepper**: remove the "Community SDK" badge and the `isCommunity` field, which only Kotlin used. - **README**: move the C# and Kotlin rows into the Official section. - Point supabase-kt links in the changed spots at `supabase/supabase-kt`. Not changed: - Links to repos still in the `supabase-community` org (for example `postgrest-csharp` and `gotrue-csharp`) and old release-note issue links. - `guides/getting-started/features.mdx`. It redirects to `/features`, so the docs app never serves it. - The v4 Kotlin note that credits the community for creating supabase-kt. It's a thank-you, not a claim that the SDK is unofficial. ## Review category (docs PRs only) - [ ] Critical: needs a review as soon as possible - [ ] Urgent: the feature ships soon, or it's blocking something else - [x] Moderate: good to have soon, not urgent - [ ] Low: get to it when you can ## Review instructions 1. Open `/docs/guides/api/rest/client-libs` and check that Kotlin is in the official table. 2. Open `/docs/reference/kotlin/introduction` and check that the note no longer says the library is unofficial. 3. Open the docs nav reference menu and check that Kotlin has no community marker. 4. Open the Getting Started page, pick the Kotlin quickstart, and check that no "Community SDK" badge shows. 5. Check the README client libraries table. ## Checklist - [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)
634 lines
22 KiB
TypeScript
634 lines
22 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>
|
|
</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'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>
|
|
)
|