mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05: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
83 lines
2.8 KiB
TypeScript
83 lines
2.8 KiB
TypeScript
import { Check, Loader2 } from 'lucide-react'
|
|
import { toast } from 'sonner'
|
|
import { Button, Progress } from 'ui'
|
|
|
|
export default function SonnerUpload() {
|
|
const uploadPromise = (files: number, toastId: number) => {
|
|
toast.loading(<UploadContent progress={0} files={files} />, {
|
|
id: toastId,
|
|
})
|
|
|
|
return new Promise((resolve) => {
|
|
let currentProgress = 0
|
|
|
|
toast.loading(<UploadContent progress={currentProgress} files={files} />, {
|
|
id: toastId,
|
|
})
|
|
|
|
const intervalId = setInterval(() => {
|
|
currentProgress += Math.floor(Math.random() * 10) + 1 // Increment progress by a random value
|
|
if (currentProgress > 100) currentProgress = 100 // Ensure progress does not exceed 100%
|
|
|
|
if (currentProgress >= 100) {
|
|
clearInterval(intervalId) // Clear the interval once upload is complete
|
|
resolve({ progress: currentProgress, message: 'Upload complete', files: 3, toastId }) // Resolve the promise when progress reaches 100
|
|
}
|
|
|
|
toast.loading(<UploadContent progress={currentProgress} files={files} />, {
|
|
id: toastId,
|
|
})
|
|
}, 200) // Adjust the interval time as needed
|
|
})
|
|
}
|
|
|
|
const UploadContent = ({ progress, files }: { progress: number; files: number }) => (
|
|
<div className="flex gap-3 w-full">
|
|
{progress >= 100 ? (
|
|
<Check className="text-foreground mt-0.5" size={16} strokeWidth={4} />
|
|
) : (
|
|
<Loader2 className="animate-spin text-foreground-muted mt-0.5" size={16} />
|
|
)}
|
|
<div className="flex flex-col gap-2 w-full">
|
|
<div className="flex w-full justify-between">
|
|
<p className="text-foreground text-sm">
|
|
{progress >= 100
|
|
? `Upload complete`
|
|
: files
|
|
? `Uploading ${files} files...`
|
|
: `Uploading...`}
|
|
</p>
|
|
<p className="text-foreground-light text-sm font-mono">{`${progress}%`}</p>
|
|
</div>
|
|
<Progress value={progress} className="w-full" />
|
|
<small className="text-foreground-muted text-xs">
|
|
Please do not close the browser until completed
|
|
</small>
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<div className="flex flex-col gap-3">
|
|
<Button
|
|
onClick={async () => {
|
|
// random id
|
|
const toastId = Math.random()
|
|
const max = 20 // specify the maximum value
|
|
const files = Math.floor(Math.random() * max)
|
|
try {
|
|
const promise = await uploadPromise(files, toastId)
|
|
// @ts-expect-error
|
|
toast.success(<UploadContent progress={promise.progress} files={promise.files} />, {
|
|
duration: 2000,
|
|
id: toastId,
|
|
})
|
|
} catch (error) {}
|
|
}}
|
|
>
|
|
Start upload
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|