mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
159 lines
4.3 KiB
TypeScript
159 lines
4.3 KiB
TypeScript
import { type ReactNode } from 'react'
|
|
import { Button, Card, CardFooter, CardHeader, cn } from 'ui'
|
|
|
|
export type SteppedFlowStep = {
|
|
id: string
|
|
label: string
|
|
}
|
|
|
|
export type SteppedFlowFinalAction = {
|
|
label: string
|
|
onClick?: () => void
|
|
loading?: boolean
|
|
disabled?: boolean
|
|
form?: string
|
|
type?: 'button' | 'submit'
|
|
}
|
|
|
|
export const SteppedFlowHeader = ({
|
|
title,
|
|
description,
|
|
actions,
|
|
children,
|
|
}: {
|
|
title: string
|
|
description?: ReactNode
|
|
actions?: ReactNode
|
|
children?: ReactNode
|
|
}) => {
|
|
return (
|
|
<CardHeader>
|
|
<header className="flex flex-col space-y-1">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="min-w-0 flex-1 space-y-1">
|
|
<h2 className="text-lg text-foreground">{title}</h2>
|
|
{description ? <p className="text-sm text-foreground-light">{description}</p> : null}
|
|
</div>
|
|
{actions ? <div className="shrink-0">{actions}</div> : null}
|
|
</div>
|
|
{children}
|
|
</header>
|
|
</CardHeader>
|
|
)
|
|
}
|
|
|
|
export interface SteppedFlowProps {
|
|
steps: SteppedFlowStep[]
|
|
currentStep: string
|
|
onStepChange: (stepId: string) => void
|
|
nextDisabled?: boolean
|
|
nextLabel?: string
|
|
onNext?: () => void
|
|
nextLoading?: boolean
|
|
navigationDisabled?: boolean
|
|
onCancel?: () => void
|
|
cancelLabel?: string
|
|
finalAction?: SteppedFlowFinalAction
|
|
children: ReactNode
|
|
}
|
|
|
|
export const SteppedFlow = ({
|
|
steps,
|
|
currentStep,
|
|
onStepChange,
|
|
nextDisabled = false,
|
|
nextLabel = 'Next',
|
|
onNext,
|
|
nextLoading = false,
|
|
navigationDisabled = false,
|
|
onCancel,
|
|
cancelLabel = 'Cancel',
|
|
finalAction,
|
|
children,
|
|
}: SteppedFlowProps) => {
|
|
const currentIndex = Math.max(
|
|
0,
|
|
steps.findIndex((step) => step.id === currentStep)
|
|
)
|
|
const stepCount = steps.length
|
|
const isLastStep = stepCount > 0 && currentIndex === stepCount - 1
|
|
const isFirstStep = currentIndex === 0
|
|
const currentStepLabel = steps[currentIndex]?.label
|
|
const showCancel = isFirstStep && !!onCancel
|
|
const nextStepId = steps[currentIndex + 1]?.id
|
|
|
|
const handleNext = () => {
|
|
if (onNext) {
|
|
onNext()
|
|
return
|
|
}
|
|
|
|
if (nextStepId) {
|
|
onStepChange(nextStepId)
|
|
}
|
|
}
|
|
|
|
if (stepCount === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-full flex-col">
|
|
<div className="mx-auto w-full max-w-[760px] flex-1 px-6 pt-8 pb-10">
|
|
<p className="mb-4 text-xs text-foreground-lighter" role="status">
|
|
Step {currentIndex + 1} of {stepCount}
|
|
{currentStepLabel ? ` · ${currentStepLabel}` : ''}
|
|
</p>
|
|
<Card
|
|
key={currentStep}
|
|
className="animate-in fade-in-0 duration-200 motion-reduce:animate-none"
|
|
>
|
|
{children}
|
|
<CardFooter
|
|
className={cn(currentIndex > 0 || showCancel ? 'justify-between' : 'justify-end')}
|
|
>
|
|
{currentIndex > 0 ? (
|
|
<Button
|
|
type="button"
|
|
disabled={navigationDisabled}
|
|
onClick={() => onStepChange(steps[currentIndex - 1].id)}
|
|
>
|
|
Back
|
|
</Button>
|
|
) : null}
|
|
{currentIndex === 0 && showCancel ? (
|
|
<Button type="button" disabled={navigationDisabled} onClick={onCancel}>
|
|
{cancelLabel}
|
|
</Button>
|
|
) : null}
|
|
<div className="flex items-center gap-2">
|
|
{isLastStep && finalAction ? (
|
|
<Button
|
|
type={finalAction.type ?? (finalAction.form ? 'submit' : 'button')}
|
|
form={finalAction.form}
|
|
variant="primary"
|
|
loading={finalAction.loading}
|
|
disabled={navigationDisabled || finalAction.disabled}
|
|
onClick={finalAction.onClick}
|
|
>
|
|
{finalAction.label}
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
type="button"
|
|
variant="primary"
|
|
disabled={navigationDisabled || nextDisabled || !nextStepId}
|
|
loading={nextLoading}
|
|
onClick={handleNext}
|
|
>
|
|
{nextLabel}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</CardFooter>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|