Menu Pick
A choose-your-launch menu dims two options and highlights the third on a red bar.
Source
components/kuchi/menu-pick.tsx
1"use client";23import { loadFont as loadRubik } from "@remotion/google-fonts/Rubik";4import type React from "react";5import {6 AbsoluteFill,7 Easing,8 interpolate,9 spring,10 useCurrentFrame,11 useVideoConfig,12} from "remotion";13import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";14import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";15import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1617const rubik = loadRubik("normal", {18 weights: ["300", "400"],19 subsets: ["latin"],20});2122export interface MenuPickProps {23 prompt?: string;24 options?: string[];25 pick?: number;26 accent?: string;27 background?: string;28 /** Hint next to the B key in the footer. */29 backLabel?: string;30 /** Hint next to the A key in the footer. */31 selectLabel?: string;32 /** Frames between rows as the menu builds. */33 stagger?: number;34 /** Text color; overrides the theme ink. */35 ink?: string;36 /** Typeface for the menu. Load it yourself; Rubik by default. */37 fontFamily?: string;38 /** Size of the menu, around the frame's center. */39 scale?: number;40 /** Frames to hold the first frame before anything moves. */41 delay?: number;42 speed?: number;43 theme?: "dark" | "light";44 ground?: GshPresetId;45 groundParams?: Partial<GradientParams>;46}4748const RED = "#E60012";4950const THEMES = {51 dark: {52 ink: "#F4F2F1",53 soft: "rgba(244,242,241,0.56)",54 faint: "rgba(244,242,241,0.08)",55 onAccent: "#FFFFFF",56 panel: "rgba(16,13,14,0.9)",57 depth:58 "inset 0 0 0 1px rgba(255,255,255,0.07), inset 0 1px 0 rgba(255,255,255,0.06), 0 2px 4px rgba(0,0,0,0.3), 0 24px 60px -12px rgba(0,0,0,0.6)",59 key: "rgba(244,242,241,0.14)",60 ground: "garnet" as GshPresetId | undefined,61 groundParams: undefined as Partial<GradientParams> | undefined,62 },63 light: {64 ink: "#141213",65 soft: "rgba(20,18,19,0.52)",66 faint: "rgba(20,18,19,0.07)",67 onAccent: "#FFFFFF",68 panel: "rgba(255,255,255,0.94)",69 depth:70 "inset 0 0 0 1px rgba(0,0,0,0.06), 0 1px 2px rgba(40,10,14,0.06), 0 24px 56px -16px rgba(60,12,20,0.22)",71 key: "rgba(20,18,19,0.1)",72 ground: undefined as GshPresetId | undefined,73 groundParams: {74 kind: "silk",75 colors: ["#f0a8a0", "#fff4ef", "#ffc9c2"],76 background: "#f3efec",77 loopSeconds: 28,78 scale: 0.55,79 warp: 0.3,80 blur: 0.5,81 seed: 2,82 } as Partial<GradientParams> | undefined,83 },84};8586const ROW_IN = 3;87const ROWS_AT = 4;88const CURSOR_AT = 14;89const HOP_GAPS = [10, 9, 7, 7];90const CONFIRM_GAP = 9;91const BLINK = 3;92const BLINKS = 2;93const DIM = 0.3;9495const EASE_ENTER = Easing.bezier(0.32, 0.72, 0, 1);96const EASE_MOVE = Easing.bezier(0.65, 0, 0.35, 1);97const SPRING_HEAVY = { mass: 1, damping: 26, stiffness: 120 };98const SPRING_CHIP = { mass: 0.5, damping: 12, stiffness: 200 };99const SPRING_HOP = { mass: 0.5, damping: 16, stiffness: 260 };100const CLAMP = {101 extrapolateLeft: "clamp",102 extrapolateRight: "clamp",103} as const;104105function estimateEm(text: string) {106 let w = 0;107 for (const ch of text) {108 if (ch === " ") w += 0.26;109 else if (/[ilIj.,'’!|]/.test(ch)) w += 0.27;110 else if (/[mwMW]/.test(ch)) w += 0.86;111 else if (/[A-Z]/.test(ch)) w += 0.68;112 else w += 0.56;113 }114 return w;115}116117function hopRoute(count: number, pick: number) {118 if (count <= 1) return [0];119 const route = [0];120 const near = Math.max(0, Math.min(count - 1, pick === 0 ? 1 : pick - 1));121 const steps = [near, pick, near, pick];122 for (const s of steps) if (s !== route[route.length - 1]) route.push(s);123 if (route[route.length - 1] !== pick) route.push(pick);124 return route;125}126127function Chevron({ size, color }: { size: number; color: string }) {128 return (129 <svg130 width={size}131 height={size}132 viewBox="0 0 24 24"133 fill="none"134 stroke={color}135 strokeWidth={2}136 strokeLinecap="round"137 strokeLinejoin="round"138 aria-hidden139 >140 <path d="M9 5.5 15.5 12 9 18.5" vectorEffect="non-scaling-stroke" />141 </svg>142 );143}144145/** The foreground at `scale`, around the frame's center; nothing extra at 1. */146function ScaleLayer({147 scale,148 children,149}: {150 scale: number;151 children: React.ReactNode;152}) {153 if (scale === 1) return children;154 return (155 <AbsoluteFill style={{ transform: `scale(${scale})` }}>156 {children}157 </AbsoluteFill>158 );159}160161export function MenuPick({162 prompt = "Choose your launch",163 options = ["Keyframe every beat", "Wait on an agency", "Install the scenes"],164 pick = 2,165 accent = RED,166 background,167 backLabel = "Back",168 selectLabel = "Select",169 stagger = ROW_IN,170 ink,171 fontFamily = rubik.fontFamily,172 scale = 1,173 delay = 0,174 speed = 1,175 theme = "dark",176 ground,177 groundParams,178}: MenuPickProps) {179 const t = Math.max(0, useCurrentFrame() - delay) * speed;180 const { width: W, height: H, fps } = useVideoConfig();181 const c = THEMES[theme];182 const fg = ink ?? c.ink;183 const list = options.length > 0 ? options : ["Start"];184 const n = list.length;185 const chosen = Math.max(0, Math.min(n - 1, Math.round(pick)));186 const transparent = background === "transparent";187 const preset = ground ?? (groundParams ? undefined : c.ground);188 const gParams = groundParams ?? c.groundParams;189190 const portrait = H > W * 1.1;191 const panelW = portrait ? W * 0.86 : W * 0.6;192 const panelPad = portrait ? W * 0.03 : W * 0.0125;193 const panelR = panelPad + (portrait ? W * 0.022 : W * 0.0094);194 const rowR = panelR - panelPad;195 const rowPadX = portrait ? W * 0.04 : W * 0.022;196 const chevS = portrait ? W * 0.05 : H * 0.042;197 const widest = Math.max(...list.map(estimateEm));198 const inner = panelW - panelPad * 2 - rowPadX * 2 - chevS * 1.6;199 const F = Math.min(portrait ? W * 0.068 : H * 0.064, inner / widest);200 const rowH = F * (portrait ? 2.2 : 2.05);201 const smallFs = portrait ? W * 0.034 : H * 0.03;202 const headH = smallFs * 3.6;203 const footH = smallFs * 3.4;204 const panelH = panelPad * 2 + headH + rowH * n + footH;205 const panelX = (W - panelW) / 2;206 const panelY = (H - panelH) / 2;207 const rowsTop = panelPad + headH;208 const rowW = panelW - panelPad * 2;209210 const route = hopRoute(n, chosen);211 const hopAt = [CURSOR_AT];212 for (let i = 1; i < route.length; i++) {213 hopAt.push(hopAt[i - 1] + HOP_GAPS[Math.min(i - 1, HOP_GAPS.length - 1)]);214 }215 let pos = route[0] as number;216 for (let i = 1; i < route.length; i++) {217 const s = spring({ frame: t - hopAt[i], fps, config: SPRING_HOP });218 pos += ((route[i] as number) - (route[i - 1] as number)) * s;219 }220 const confirmAt = (hopAt[hopAt.length - 1] as number) + CONFIRM_GAP;221 const blinkEnd = confirmAt + BLINK * 2 * BLINKS;222 const blinking = t >= confirmAt && t < blinkEnd;223 const blinkOff = blinking && Math.floor((t - confirmAt) / BLINK) % 2 === 0;224 const cursorIn = interpolate(t, [CURSOR_AT, CURSOR_AT + 6], [0, 1], {225 ...CLAMP,226 easing: EASE_ENTER,227 });228 const press =229 spring({ frame: t - confirmAt, fps, config: SPRING_CHIP }) -230 spring({ frame: t - confirmAt - 5, fps, config: SPRING_CHIP });231 const barScale = 1 - 0.04 * press;232 const settle = interpolate(t, [blinkEnd, blinkEnd + 10], [0, 1], {233 ...CLAMP,234 easing: EASE_MOVE,235 });236237 const panelIn = spring({ frame: t, fps, config: SPRING_HEAVY });238 const panelO = interpolate(t, [0, 8], [0, 1], {239 ...CLAMP,240 easing: EASE_ENTER,241 });242 const headIn = interpolate(t, [2, 14], [0, 1], {243 ...CLAMP,244 easing: EASE_ENTER,245 });246 const footIn = interpolate(247 t,248 [ROWS_AT + n * stagger, ROWS_AT + n * stagger + 12],249 [0, 1],250 {251 ...CLAMP,252 easing: EASE_ENTER,253 },254 );255256 const rowIn = (i: number) =>257 interpolate(258 t,259 [ROWS_AT + i * stagger, ROWS_AT + i * stagger + 12],260 [0, 1],261 {262 ...CLAMP,263 easing: EASE_ENTER,264 },265 );266267 const barY = rowsTop + pos * rowH;268269 const rowText = (onBar: boolean) =>270 list.map((label, i) => {271 const p = rowIn(i);272 const dim = i === chosen ? 1 : 1 - (1 - DIM) * settle;273 return (274 <div275 key={`r${i}`}276 style={{277 position: "absolute",278 left: panelPad,279 top: rowsTop + i * rowH,280 width: rowW,281 height: rowH,282 paddingLeft: rowPadX,283 paddingRight: rowPadX * 0.7,284 display: "flex",285 alignItems: "center",286 justifyContent: "space-between",287 opacity: p * (onBar ? 1 : dim),288 transform: `translateY(${(1 - p) * rowH * 0.3}px)`,289 color: onBar ? c.onAccent : fg,290 }}291 >292 <span293 style={{294 fontFamily,295 fontWeight: 400,296 fontSize: F,297 lineHeight: 1,298 letterSpacing: "-0.02em",299 whiteSpace: "pre",300 }}301 >302 {label}303 </span>304 {onBar ? <Chevron size={chevS} color={c.onAccent} /> : null}305 </div>306 );307 });308309 const Key = ({ k, label }: { k: string; label: string }) => (310 <div311 style={{312 display: "flex",313 alignItems: "center",314 gap: smallFs * 0.5,315 }}316 >317 <span318 style={{319 width: smallFs * 1.5,320 height: smallFs * 1.5,321 borderRadius: 999,322 backgroundColor: c.key,323 display: "flex",324 alignItems: "center",325 justifyContent: "center",326 fontSize: smallFs * 0.82,327 color: fg,328 }}329 >330 {k}331 </span>332 <span>{label}</span>333 </div>334 );335336 return (337 <AbsoluteFill338 style={{339 background: transparent ? "transparent" : background,340 overflow: "hidden",341 }}342 >343 {transparent || background ? null : (344 <GshGround345 preset={preset}346 params={gParams}347 timeOffset={theme === "light" ? 6 : 4}348 timeScale={0.5}349 />350 )}351 <ScaleLayer scale={scale}>352 <div353 style={{354 position: "absolute",355 left: panelX,356 top: panelY,357 width: panelW,358 height: panelH,359 borderRadius: panelR,360 backgroundColor: c.panel,361 boxShadow: c.depth,362 opacity: panelO,363 transform: `translateY(${(1 - panelIn) * H * 0.05}px) scale(${0.97 + 0.03 * panelIn})`,364 fontFamily,365 overflow: "hidden",366 }}367 >368 <div369 style={{370 position: "absolute",371 left: panelPad + rowPadX,372 right: panelPad + rowPadX,373 top: panelPad,374 height: headH,375 display: "flex",376 alignItems: "center",377 justifyContent: "space-between",378 fontWeight: 400,379 fontSize: smallFs,380 letterSpacing: "-0.005em",381 color: c.soft,382 opacity: headIn,383 transform: `translateY(${(1 - headIn) * smallFs * 0.6}px)`,384 }}385 >386 <span style={{ color: fg }}>{prompt}</span>387 <span style={{ fontVariantNumeric: "tabular-nums" }}>388 {`${Math.min(n, Math.round(pos) + 1)} / ${n}`}389 </span>390 </div>391 {list.slice(1).map((label, i) => (392 <div393 key={`d-${label}`}394 style={{395 position: "absolute",396 left: panelPad + rowPadX,397 right: panelPad + rowPadX,398 top: rowsTop + (i + 1) * rowH,399 height: 1,400 backgroundColor: c.faint,401 opacity: rowIn(i + 1),402 }}403 />404 ))}405 {rowText(false)}406 <div407 style={{408 position: "absolute",409 left: panelPad,410 top: barY,411 width: rowW,412 height: rowH,413 borderRadius: rowR,414 overflow: "hidden",415 backgroundColor: accent,416 opacity: blinkOff ? 0 : cursorIn,417 transform: `scale(${barScale * (0.96 + 0.04 * cursorIn)})`,418 }}419 >420 <div421 style={{422 position: "absolute",423 left: -panelPad,424 top: -barY,425 width: panelW,426 height: panelH,427 }}428 >429 {rowText(true)}430 </div>431 </div>432 <div433 style={{434 position: "absolute",435 left: panelPad + rowPadX,436 right: panelPad + rowPadX,437 bottom: panelPad,438 height: footH,439 display: "flex",440 alignItems: "center",441 justifyContent: "flex-end",442 gap: smallFs * 1.6,443 fontWeight: 400,444 fontSize: smallFs,445 color: c.soft,446 opacity: footIn,447 }}448 >449 <Key k="B" label={backLabel} />450 <Key k="A" label={selectLabel} />451 </div>452 </div>453 </ScaleLayer>454 </AbsoluteFill>455 );456}









