Open source CapCut alternative.
TypeScript
"use client";
import { useFormatter, useLocale, useTranslations } from "next-intl";
import { useEffect, useRef } from "react";
import { BLUE_TEXT } from "@/cut/components/accent";
import { burstConfetti } from "@/cut/components/onboarding/confetti";
import { creditCountLabel, creditsFromDollars } from "@/lib/credits/format-credits";
import { cn } from "@/lib/utils";
// The signup grant already landed when the account was created, so this slide
// never grants anything — it says what's there: the credits the grant carried,
// read from the account. That's as true on a replay as on a first run, so the words
// don't change between them; the burst fires every time the slide is reached.
// A grant with an expiry names the date under the amount.
export function CreditsSlide({
credits,
expiresAt,
}: {
credits: string;
expiresAt: string | null;
}) {
const t = useTranslations("onboarding.credits");
const format = useFormatter();
const locale = useLocale();
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
return burstConfetti(canvas);
}, [credits]);
return (
<div className="relative flex flex-col items-center text-center">
{/* Fixed to the window: the burst covers the whole overlay and, being out
of flow, can't stretch the slide's scroll area. The explicit size is
load-bearing — a canvas left to `auto` takes its 300×150 intrinsic
size rather than the inset box. */}
<canvas
ref={canvasRef}
aria-hidden
className="pointer-events-none fixed inset-0 h-full w-full"
/>
<div className="relative max-w-[900px]">
{/* One line, two sizes: the amount at display size in the accent blue, the words
a couple of steps down and thin beside it. */}
<h2 className="flex flex-wrap items-baseline justify-center gap-x-4 leading-[1.02] tracking-[-0.03em]">
<span className={cn("text-[clamp(40px,7.4vw,84px)] font-semibold tabular-nums", BLUE_TEXT)}>
{creditCountLabel(creditsFromDollars(credits, "down"), locale)}
</span>
<span className="text-[clamp(26px,4.4vw,52px)] font-light">
{t("onUs")}
</span>
</h2>
{/* Ragged right on a narrow measure: the line breaks stay put instead
of the last line floating in the middle of the slide. */}
<p className="mx-auto mt-4 max-w-[460px] text-left text-[16px] leading-[1.55] text-foreground/70">
{t("body")}
</p>
{expiresAt !== null && (
<p className="mt-3 text-[13px] leading-[1.5] text-foreground/70">
{t("expires", {
date: format.dateTime(new Date(expiresAt), { day: "numeric", month: "long", year: "numeric" }),
})}
</p>
)}
</div>
</div>
);
}