Drop Upload
A file card drops in and fills an upload bar until a check confirms it.
Source
components/kuchi/drop-upload.tsx
1"use client";23import { loadFont as loadInstrument } from "@remotion/google-fonts/InstrumentSans";4import { loadFont as loadJetBrains } from "@remotion/google-fonts/JetBrainsMono";5import type React from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 spring,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";14import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";15import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";16import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1718const instrument = loadInstrument("normal", {19 weights: ["400"],20 subsets: ["latin"],21});22const jetbrains = loadJetBrains("normal", {23 weights: ["300", "400"],24 subsets: ["latin"],25});2627const ENTER = Easing.bezier(0.32, 0.72, 0, 1);28const EXIT = Easing.bezier(0.55, 0, 1, 0.45);29const FILL = Easing.bezier(0.83, 0, 0.17, 1);30const HEAVY = { mass: 1, damping: 26, stiffness: 120 };31const CARD = { mass: 0.8, damping: 18, stiffness: 160 };32const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };33const MORPH = { damping: 200 };3435const B = {36 zone: -8,37 title: -2,38 fly: 6,39 hover: 30,40 drop: 54,41 collapse: 60,42 info: 72,43 progress: 78,44 done: 114,45 end: 162,46};4748const ramp = (f: number, start: number, dur: number, easing = ENTER) =>49 interpolate(f, [start, start + dur], [0, 1], {50 extrapolateLeft: "clamp",51 extrapolateRight: "clamp",52 easing,53 });5455const mix = (a: number, b: number, t: number) => a + (b - a) * t;5657function FileTile({58 kind,59 accent,60 w,61}: {62 kind: string;63 accent: string;64 w: number;65}) {66 const h = w * 1.26;67 const fold = w * 0.27;68 return (69 <div style={{ position: "relative", width: w, height: h }}>70 <svg71 width={w}72 height={h}73 viewBox={`0 0 ${w} ${h}`}74 style={{ position: "absolute", inset: 0, overflow: "visible" }}75 aria-hidden76 >77 <defs>78 <linearGradient id="du-paper" x1="0" y1="0" x2="0" y2="1">79 <stop offset="0" stopColor="#ffffff" />80 <stop offset="1" stopColor="#eceef6" />81 </linearGradient>82 </defs>83 <path84 d={`M ${w * 0.1} 0 H ${w - fold} L ${w} ${fold} V ${h - w * 0.1} Q ${w} ${h} ${w * 0.9} ${h} H ${w * 0.1} Q 0 ${h} 0 ${h - w * 0.1} V ${w * 0.1} Q 0 0 ${w * 0.1} 0 Z`}85 fill="url(#du-paper)"86 stroke="rgba(20,24,48,0.1)"87 />88 <path89 d={`M ${w - fold} 0 V ${fold * 0.72} Q ${w - fold} ${fold} ${w - fold * 0.72} ${fold} H ${w} Z`}90 fill="#d7dbea"91 />92 {[0.3, 0.4, 0.5, 0.6].map((y, i) => (93 <rect94 key={y}95 x={w * 0.16}96 y={h * y}97 width={w * (i === 3 ? 0.36 : i === 0 ? 0.4 : 0.62)}98 height={w * 0.045}99 rx={w * 0.022}100 fill={i === 0 ? "#b9bfd6" : "#d9dce8"}101 />102 ))}103 </svg>104 <div105 style={{106 position: "absolute",107 left: w * 0.12,108 bottom: w * 0.12,109 height: w * 0.24,110 padding: `0 ${w * 0.08}px`,111 borderRadius: w * 0.06,112 background: accent,113 color: "#fff",114 fontFamily: jetbrains.fontFamily,115 fontSize: w * 0.15,116 display: "flex",117 alignItems: "center",118 letterSpacing: "0.04em",119 boxShadow: "inset 0 1px 0 rgba(255,255,255,0.3)",120 }}121 >122 {kind}123 </div>124 </div>125 );126}127128export interface DropUploadProps {129 theme?: "dark" | "light";130 accent?: string;131 title?: string;132 fileName?: string;133 fileKind?: string;134 fileSize?: string;135 hint?: string;136 history?: { name: string; kind: string; size: string; ago: string }[];137 ground?: GshPresetId;138 groundParams?: Partial<GradientParams>;139 /** Line inside the empty drop zone, before the "browse" link. */140 dropLabel?: string;141 /** Line that replaces it while the file hovers over the zone. */142 releaseLabel?: string;143 /** Status shown once the progress bar fills. */144 doneLabel?: string;145 /** Text color; overrides the theme ink. */146 ink?: string;147 /** Solid fill in place of the gradient ground; "transparent" drops it. */148 background?: string;149 /** Typeface for the copy. Load it yourself; Instrument Sans by default. */150 fontFamily?: string;151 /** Size of the drop zone and file, around the frame's center. */152 scale?: number;153 /** Frames to hold the first frame before anything moves. */154 delay?: number;155 speed?: number;156}157158/** The foreground at `scale`, around the frame's center; nothing extra at 1. */159function ScaleLayer({160 scale,161 children,162}: {163 scale: number;164 children: React.ReactNode;165}) {166 if (scale === 1) return children;167 return (168 <AbsoluteFill style={{ transform: `scale(${scale})` }}>169 {children}170 </AbsoluteFill>171 );172}173174export function DropUpload({175 theme = "dark",176 accent = "#3B5BFD",177 title = "Drop in your launch notes",178 fileName = "launch-notes.md",179 fileKind = "MD",180 fileSize = "2.4 MB",181 hint = "MD, PDF or ZIP · up to 50 MB",182 history = [183 {184 name: "changelog-2.0.pdf",185 kind: "PDF",186 size: "1.1 MB",187 ago: "4 min ago",188 },189 { name: "press-kit.zip", kind: "ZIP", size: "18.6 MB", ago: "12 min ago" },190 ],191 ground,192 groundParams,193 dropLabel = "Drag and drop a file, or",194 releaseLabel = "Release to upload",195 doneLabel = "Uploaded",196 ink: inkProp,197 background,198 fontFamily = instrument.fontFamily,199 scale = 1,200 delay = 0,201 speed: rate = 1,202}: DropUploadProps) {203 const frame = Math.max(0, useCurrentFrame() - delay) * rate;204 const { width, height, fps } = useVideoConfig();205 const dark = theme === "dark";206 const portrait = height > width * 1.2;207 const stageW = portrait ? 760 : 1280;208 const stageH = portrait ? 1351 : 720;209 const sc = width / stageW;210211 const ink = inkProp ?? (dark ? "#f1f2fb" : "#151824");212 const soft = dark ? "rgba(225,228,250,0.7)" : "rgba(21,24,36,0.66)";213 const muted = dark ? "rgba(225,228,250,0.46)" : "rgba(21,24,36,0.44)";214 const dash = dark ? "rgba(225,228,250,0.34)" : "rgba(21,24,36,0.26)";215 const base = dark ? "#11141f" : "#ffffff";216 const rowShadow = (k: number) =>217 dark218 ? `0 0 0 1px rgba(255,255,255,${0.08 * k}), 0 40px 90px -24px rgba(0,2,14,${0.7 * k})`219 : `0 0 0 1px rgba(20,24,48,${0.07 * k}), 0 1px 3px rgba(20,24,48,${0.06 * k}), 0 36px 80px -24px rgba(20,30,70,${0.22 * k})`;220 const accentMix = (pct: number, base: string) =>221 `color-mix(in oklab, ${accent} ${pct}%, ${base})`;222223 const zoneW = portrait ? 564 : 760;224 const zoneH = portrait ? 440 : 320;225 const rowW = portrait ? 564 : 760;226 const rowH = 104;227 const cx = stageW / 2;228 const cy = portrait ? 640 : 412;229 const titleSize = portrait ? 50 : 60;230 const titleGap = portrait ? 56 : 44;231232 const zoneIn = spring({ frame: frame - B.zone, fps, config: HEAVY });233 const titleIn = ramp(frame, B.title, 15);234 const collapse = spring({ frame: frame - B.collapse, fps, config: MORPH });235 const highlight =236 ramp(frame, B.hover - 8, 12) * (1 - ramp(frame, B.collapse, 8, EXIT));237 const breathe =238 Math.sin(((frame - B.hover) / 22) * Math.PI * 2) * 0.012 * highlight;239 const dropHit = spring({ frame: frame - B.drop - 6, fps, config: CHIP });240 const dropPunch =241 0.03 *242 Math.sin(Math.PI * Math.min(1, dropHit)) *243 (1 - ramp(frame, B.drop + 14, 6));244245 const solid = ramp(frame, B.collapse - 2, 14);246 const tint = accentMix(Math.round(12 * highlight), "transparent");247 const radius = mix(24, 20, collapse);248 const zW = mix(zoneW, rowW, collapse);249 const zH = mix(zoneH, rowH, collapse);250 const zL = cx - zW / 2;251 const zT = cy - zH / 2;252253 const startX = portrait ? cx + 260 : cx + 560;254 const startY = portrait ? cy + 600 : cy + 360;255 const ctrlX = portrait ? cx + 300 : cx + 300;256 const ctrlY = portrait ? cy - 200 : cy - 300;257 const hoverX = cx + 30;258 const hoverY = cy - (portrait ? 84 : 66);259 const flyT = (f: number) =>260 spring({ frame: f - B.fly, fps, config: CARD, durationInFrames: 26 });261 const bez = (t: number, a: number, c: number, b: number) =>262 (1 - t) * (1 - t) * a + 2 * (1 - t) * t * c + t * t * b;263 const p = flyT(frame);264 const pPrev = flyT(frame - 1);265 let tx = bez(p, startX, ctrlX, hoverX);266 let ty = bez(p, startY, ctrlY, hoverY);267 const speed = Math.hypot(268 tx - bez(pPrev, startX, ctrlX, hoverX),269 ty - bez(pPrev, startY, ctrlY, hoverY),270 );271 const hoverAmt = ramp(frame, B.hover - 4, 10) * (1 - ramp(frame, B.drop, 8));272 tx += Math.sin((frame - B.hover) / 7) * 5 * hoverAmt;273 ty += Math.cos((frame - B.hover) / 9) * 5 * hoverAmt;274 let rot = mix(28, -7, p) + Math.sin((frame - B.hover) / 10) * 2.5 * hoverAmt;275 let lift = mix(1.2, 0.74, p);276 const drop = ramp(frame, B.drop, 8, EXIT);277 lift *= mix(1, 0.84, drop);278 ty += 16 * drop;279 rot = mix(rot, -3, drop);280 const tileW = 112;281 const iconW = 48;282 const iconX = cx - rowW / 2 + 26 + iconW / 2;283 const iconY = cy;284 const toRow = spring({ frame: frame - B.collapse - 2, fps, config: MORPH });285 tx = mix(tx, iconX, toRow);286 ty = mix(ty, iconY, toRow);287 rot = mix(rot, 0, toRow);288 const tileScale = mix(lift, iconW / tileW, toRow);289 const tileBlur = Math.min(6, speed * 0.1);290 const shadowAmt = (1 - drop * 0.7) * (1 - toRow);291292 const zoneContent = 1 - ramp(frame, B.collapse - 2, 8, EXIT);293 const info = ramp(frame, B.info, 12);294 const prog = interpolate(frame, [B.progress, B.done - 4], [0, 1], {295 extrapolateLeft: "clamp",296 extrapolateRight: "clamp",297 easing: FILL,298 });299 const done = spring({ frame: frame - B.done, fps, config: CHIP });300 const doneIn = ramp(frame, B.done, 6);301 const pct = Math.round(prog * 100);302303 const camIn = spring({ frame: frame + 8, fps, config: HEAVY });304 const rowFocus = spring({ frame: frame - B.collapse, fps, config: HEAVY });305 const rotX = mix(18, 4, camIn) - 2.5 * rowFocus;306 const rotY = mix(14, 4, camIn) - 4 * rowFocus;307 const push =308 mix(0.9, 1, camIn) +309 0.025 * ramp(frame, 0, B.end, Easing.linear) +310 (portrait ? 0.06 : 0.26) * rowFocus;311 const titleTop0 = cy - zoneH / 2 - titleGap - titleSize * 1.05;312 const titleTop1 = cy - rowH / 2 - (portrait ? 44 : 34) - titleSize * 1.05;313 const titleTop = mix(titleTop0, titleTop1, rowFocus);314 const histH = 84;315 const histGap = 14;316 const shown = portrait ? history : [];317 const listBottom = cy + rowH / 2 + shown.length * (histH + histGap);318 const groupMid = (titleTop1 + listBottom) / 2;319 const camY = rowFocus * (groupMid - cy) * 0.9;320321 const resolvedGround: GshPresetId =322 ground ?? (dark ? "earthshine" : "paper-crease");323 const resolvedParams =324 groundParams ??325 (dark326 ? undefined327 : {328 colors: ["#9db8e6", "#d4e1f4", "#eef2f8", "#2c4f9e"],329 background: "#f1f3f6",330 });331332 return (333 <AbsoluteFill style={{ fontFamily, overflow: "hidden" }}>334 {background === undefined ? (335 <GshGround336 preset={resolvedGround}337 params={resolvedParams}338 timeOffset={2}339 timeScale={0.5}340 />341 ) : (342 <AbsoluteFill343 style={{344 background: background === "transparent" ? undefined : background,345 }}346 />347 )}348 <ScaleLayer scale={scale}>349 <div350 style={{351 position: "absolute",352 left: 0,353 top: 0,354 width: stageW,355 height: stageH,356 transform: `scale(${sc})`,357 transformOrigin: "0 0",358 perspective: 2000,359 }}360 >361 <div362 style={{363 position: "absolute",364 inset: 0,365 transformStyle: "preserve-3d",366 transformOrigin: `${cx}px ${cy}px`,367 transform: `translateY(${-camY * push}px) scale(${push}) rotateX(${rotX}deg) rotateY(${rotY}deg)`,368 }}369 >370 <div371 style={{372 position: "absolute",373 left: 40,374 right: 40,375 top: titleTop,376 height: titleSize * 1.25,377 overflow: "hidden",378 textAlign: "center",379 }}380 >381 <div382 style={{383 fontSize: titleSize,384 lineHeight: 1.15,385 letterSpacing: "-0.035em",386 fontWeight: 400,387 color: ink,388 transform: `translateY(${mix(105, 0, titleIn)}%)`,389 }}390 >391 {title}392 </div>393 </div>394395 <div396 style={{397 position: "absolute",398 left: zL,399 top: zT,400 width: zW,401 height: zH,402 borderRadius: radius,403 background: `linear-gradient(${tint}, ${tint}), color-mix(in oklab, ${base} ${Math.round(mix(dark ? 58 : 52, 100, solid))}%, transparent)`,404 boxShadow: rowShadow(solid),405 opacity: ramp(frame, -6, 8),406 transform: `translateY(${mix(60, 0, zoneIn)}px) scale(${mix(0.94, 1, zoneIn) * (1 + breathe + dropPunch)})`,407 overflow: "hidden",408 }}409 >410 <svg411 width={zW}412 height={zH}413 style={{ position: "absolute", inset: 0, opacity: zoneContent }}414 aria-hidden415 >416 <rect417 x={0.75}418 y={0.75}419 width={Math.max(0, zW - 1.5)}420 height={Math.max(0, zH - 1.5)}421 rx={radius - 0.75}422 fill="none"423 stroke={424 highlight > 0.02425 ? accentMix(Math.round(85 * highlight), dash)426 : dash427 }428 strokeWidth={1.5}429 strokeDasharray="9 7"430 strokeDashoffset={-frame * 0.7 * (0.25 + highlight)}431 />432 </svg>433 <div434 style={{435 position: "absolute",436 inset: 0,437 display: "flex",438 flexDirection: "column",439 alignItems: "center",440 justifyContent: "center",441 gap: 14,442 opacity: zoneContent,443 transform: `translateY(${36 * highlight}px) scale(${mix(0.94, 1, zoneContent)})`,444 }}445 >446 <div447 style={{448 width: 44,449 height: 44,450 display: "flex",451 alignItems: "center",452 justifyContent: "center",453 transform: `scale(${mix(1, 0.6, highlight)})`,454 opacity: 1 - highlight,455 }}456 >457 <svg viewBox="0 0 24 24" width={34} height={34} aria-hidden>458 <path459 d="M12 15V4M7.5 8.5 12 4l4.5 4.5M5 14v4.5A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5V14"460 fill="none"461 stroke={soft}462 strokeWidth={1.5}463 strokeLinecap="round"464 strokeLinejoin="round"465 />466 </svg>467 </div>468 <div469 style={{470 position: "relative",471 height: 28,472 width: zW - 60,473 textAlign: "center",474 }}475 >476 <div477 style={{478 position: "absolute",479 inset: 0,480 fontSize: 21,481 color: ink,482 letterSpacing: "-0.01em",483 opacity: 1 - highlight,484 transform: `translateY(${-8 * highlight}px)`,485 }}486 >487 {dropLabel}{" "}488 <span489 style={{490 color: dark ? accentMix(50, "#ffffff") : accent,491 textDecoration: "underline",492 textUnderlineOffset: 4,493 textDecorationThickness: 1,494 }}495 >496 browse497 </span>498 </div>499 <div500 style={{501 position: "absolute",502 inset: 0,503 fontSize: 21,504 color: dark ? "#ffffff" : accent,505 opacity: highlight,506 transform: `translateY(${8 * (1 - highlight)}px)`,507 }}508 >509 {releaseLabel}510 </div>511 </div>512 <div513 style={{514 fontFamily: jetbrains.fontFamily,515 fontSize: 17,516 color: muted,517 }}518 >519 {hint}520 </div>521 </div>522523 <div524 style={{525 position: "absolute",526 left: 26 + iconW + 20,527 right: 26,528 top: 0,529 height: rowH,530 opacity: info,531 display: frame >= B.info ? "block" : "none",532 }}533 >534 <div535 style={{536 position: "absolute",537 left: 0,538 right: 64,539 top: 24,540 display: "flex",541 alignItems: "baseline",542 gap: 12,543 transform: `translateY(${mix(12, 0, info)}px)`,544 }}545 >546 <span547 style={{548 fontSize: 21,549 color: ink,550 letterSpacing: "-0.01em",551 }}552 >553 {fileName}554 </span>555 <span556 style={{557 fontFamily: jetbrains.fontFamily,558 fontSize: 17,559 color: muted,560 }}561 >562 {fileSize}563 </span>564 <div style={{ flex: 1 }} />565 <span566 style={{567 position: "relative",568 fontSize: 17,569 color: soft,570 width: 110,571 textAlign: "right",572 }}573 >574 <span575 style={{576 position: "absolute",577 right: 0,578 opacity: 1 - doneIn,579 }}580 >581 Uploading582 </span>583 <span584 style={{585 position: "absolute",586 right: 0,587 color: dark ? accentMix(45, "#ffffff") : accent,588 opacity: doneIn,589 transform: `translateY(${mix(8, 0, doneIn)}px)`,590 }}591 >592 {doneLabel}593 </span>594 </span>595 </div>596 <div597 style={{598 position: "absolute",599 left: 0,600 right: 64,601 top: 64,602 height: 6,603 borderRadius: 3,604 background: dark605 ? "rgba(255,255,255,0.08)"606 : "rgba(20,24,48,0.07)",607 overflow: "hidden",608 }}609 >610 <div611 style={{612 width: `${prog * 100}%`,613 height: "100%",614 borderRadius: 3,615 background: accent,616 }}617 />618 </div>619 <div620 style={{621 position: "absolute",622 right: 0,623 top: (rowH - 40) / 2,624 width: 40,625 height: 40,626 display: "flex",627 alignItems: "center",628 justifyContent: "center",629 }}630 >631 <span632 style={{633 position: "absolute",634 fontFamily: jetbrains.fontFamily,635 fontSize: 17,636 color: muted,637 opacity: 1 - doneIn,638 fontVariantNumeric: "tabular-nums",639 }}640 >641 {pct}%642 </span>643 <div644 style={{645 width: 40,646 height: 40,647 borderRadius: 20,648 background: accent,649 boxShadow: "inset 0 1px 0 rgba(255,255,255,0.25)",650 transform: `scale(${done})`,651 opacity: doneIn,652 display: "flex",653 alignItems: "center",654 justifyContent: "center",655 }}656 >657 <svg viewBox="0 0 24 24" width={22} height={22} aria-hidden>658 <path659 d="m6 12.5 4 4 8-9"660 fill="none"661 stroke="#fff"662 strokeWidth={2.2}663 strokeLinecap="round"664 strokeLinejoin="round"665 strokeDasharray={20}666 strokeDashoffset={20 * (1 - ramp(frame, B.done + 2, 8))}667 />668 </svg>669 </div>670 </div>671 </div>672 </div>673674 {shown.map((h, i) => {675 const at = B.info + 2 + i * 5;676 const k = spring({ frame: frame - at, fps, config: CARD });677 return (678 <div679 key={h.name}680 style={{681 position: "absolute",682 left: cx - rowW / 2,683 top: cy + rowH / 2 + histGap + i * (histH + histGap),684 width: rowW,685 height: histH,686 borderRadius: 20,687 background: base,688 boxShadow: rowShadow(0.55),689 display: "flex",690 alignItems: "center",691 gap: 20,692 padding: "0 26px 0 32px",693 opacity: ramp(frame, at, 8),694 transform: `translateY(${mix(28, 0, k)}px)`,695 }}696 >697 <FileTile kind={h.kind} accent={accent} w={38} />698 <span699 style={{700 fontSize: 21,701 color: ink,702 letterSpacing: "-0.01em",703 }}704 >705 {h.name}706 </span>707 <span708 style={{709 fontFamily: jetbrains.fontFamily,710 fontSize: 17,711 color: muted,712 }}713 >714 {h.size}715 </span>716 <div style={{ flex: 1 }} />717 <span style={{ fontSize: 17, color: muted }}>{h.ago}</span>718 </div>719 );720 })}721722 <div723 style={{724 position: "absolute",725 left: tx - tileW / 2,726 top: ty - (tileW * 1.26) / 2,727 transform: `rotate(${rot}deg) scale(${tileScale})`,728 filter: [729 tileBlur > 0.3 ? `blur(${tileBlur}px)` : "",730 `drop-shadow(0 ${mix(4, 34, shadowAmt)}px ${mix(6, 36, shadowAmt)}px rgba(4,6,30,${dark ? 0.55 : 0.22}))`,731 ].join(" "),732 opacity: ramp(frame, B.fly, 4),733 }}734 >735 <FileTile kind={fileKind} accent={accent} w={tileW} />736 </div>737 </div>738 </div>739 </ScaleLayer>740 </AbsoluteFill>741 );742}743744export default DropUpload;





