ChatGPT
Animated ChatGPT composer — types a prompt into the pill input, the blue voice button morphs into a send button, and the suggestion chips fade out. Light/dark themes.
Source
components/kuchi/chat-gpt.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/Inter";4import {5 AbsoluteFill,6 interpolate,7 spring,8 useCurrentFrame,9 useVideoConfig,10} from "remotion";11import { Caret } from "@/components/kuchi/type-caret";12import { useTypewriter } from "@/lib/kuchi-kit";1314const { fontFamily: SANS_FAMILY } = loadFont();1516export interface ChatGptProps {17 greeting?: string;18 placeholder?: string;19 prompt?: string;20 accentColor?: string;21 speed?: number;22}2324interface Theme {25 page: string;26 inputBg: string;27 inputBorder: string;28 fg: string;29 fgMuted: string;30 chipBorder: string;31 chipFg: string;32 sendBg: string;33 sendArrow: string;34 iconColor: string;35}3637export const THEMES: Record<"light" | "dark", Theme> = {38 light: {39 page: "#FFFFFF",40 inputBg: "#FFFFFF",41 inputBorder: "#E3E3E3",42 fg: "#0D0D0D",43 fgMuted: "#9B9B9B",44 chipBorder: "#E3E3E3",45 chipFg: "#5D5D5D",46 sendBg: "#0D0D0D",47 sendArrow: "#FFFFFF",48 iconColor: "#5D5D5D",49 },50 dark: {51 page: "#212121",52 inputBg: "#303030",53 inputBorder: "#454545",54 fg: "#ECECEC",55 fgMuted: "#9B9B9B",56 chipBorder: "#454545",57 chipFg: "#C5C5C5",58 sendBg: "#FFFFFF",59 sendArrow: "#0D0D0D",60 iconColor: "#C5C5C5",61 },62};6364export const TYPING_START_FRAME = 42;6566export const TYPING_CPS = 22;6768export function morphProgressAt(69 frame: number,70 opts: { startFrame?: number; fps: number; speed: number },71): number {72 const startFrame = opts.startFrame ?? TYPING_START_FRAME;73 const value = spring({74 fps: opts.fps,75 frame: frame * opts.speed - startFrame,76 config: { damping: 14, stiffness: 200, mass: 0.6 },77 });78 return Math.max(0, Math.min(value, 1));79}8081function introBounceIn(82 frame: number,83 fps: number,84): { translateY: number; scale: number } {85 const s = spring({86 fps,87 frame,88 config: { damping: 14, stiffness: 110, mass: 0.7 },89 });90 const translateY = interpolate(s, [0, 1], [28, 0]);91 const scale = interpolate(s, [0, 1], [0.97, 1]);92 return { translateY, scale };93}9495function fadeUpAt(96 frame: number,97 range: [number, number],98): { opacity: number; translateY: number } {99 const opts = {100 extrapolateLeft: "clamp" as const,101 extrapolateRight: "clamp" as const,102 };103 return {104 opacity: interpolate(frame, range, [0, 1], opts),105 translateY: interpolate(frame, range, [12, 0], opts),106 };107}108109function PlusIcon({ size, color }: { size: number; color: string }) {110 return (111 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">112 <title>Add</title>113 <path114 d="M12 5v14M5 12h14"115 stroke={color}116 strokeWidth={2}117 strokeLinecap="round"118 />119 </svg>120 );121}122123function MicIcon({ size, color }: { size: number; color: string }) {124 return (125 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">126 <title>Voice input</title>127 <rect128 x={9}129 y={3}130 width={6}131 height={11}132 rx={3}133 stroke={color}134 strokeWidth={1.8}135 />136 <path137 d="M5.5 11a6.5 6.5 0 0013 0M12 17.5V21M9 21h6"138 stroke={color}139 strokeWidth={1.8}140 strokeLinecap="round"141 strokeLinejoin="round"142 />143 </svg>144 );145}146147function WaveformIcon({ size, color }: { size: number; color: string }) {148 const bars = [149 { x: 4, h: 8 },150 { x: 9, h: 16 },151 { x: 14, h: 12 },152 { x: 19, h: 20 },153 ];154 return (155 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">156 <title>Voice</title>157 {bars.map((bar) => (158 <rect159 key={bar.x}160 x={bar.x - 1}161 y={(24 - bar.h) / 2}162 width={2.4}163 height={bar.h}164 rx={1.2}165 fill={color}166 />167 ))}168 </svg>169 );170}171172function ArrowUpIcon({ size, color }: { size: number; color: string }) {173 return (174 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">175 <title>Send</title>176 <path177 d="M12 19V6M12 6l-6 6M12 6l6 6"178 stroke={color}179 strokeWidth={2.2}180 strokeLinecap="round"181 strokeLinejoin="round"182 />183 </svg>184 );185}186187function ImageIcon({ size, color }: { size: number; color: string }) {188 return (189 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">190 <title>Create an image</title>191 <rect192 x={3}193 y={4}194 width={18}195 height={16}196 rx={3}197 stroke={color}198 strokeWidth={1.7}199 />200 <circle cx={8.5} cy={9} r={1.6} stroke={color} strokeWidth={1.7} />201 <path202 d="M5 18l5-5 4 4 2-2 3 3"203 stroke={color}204 strokeWidth={1.7}205 strokeLinecap="round"206 strokeLinejoin="round"207 />208 </svg>209 );210}211212function PencilIcon({ size, color }: { size: number; color: string }) {213 return (214 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">215 <title>Write or edit</title>216 <path217 d="M4 20h4L19 9a2.1 2.1 0 00-3-3L5 17v3z"218 stroke={color}219 strokeWidth={1.7}220 strokeLinecap="round"221 strokeLinejoin="round"222 />223 <path224 d="M14 7l3 3"225 stroke={color}226 strokeWidth={1.7}227 strokeLinecap="round"228 strokeLinejoin="round"229 />230 </svg>231 );232}233234function GlobeIcon({ size, color }: { size: number; color: string }) {235 return (236 <svg width={size} height={size} viewBox="0 0 24 24" fill="none">237 <title>Look something up</title>238 <circle cx={12} cy={12} r={9} stroke={color} strokeWidth={1.7} />239 <path240 d="M3 12h18M12 3c2.5 2.5 2.5 15 0 18M12 3c-2.5 2.5-2.5 15 0 18"241 stroke={color}242 strokeWidth={1.7}243 strokeLinecap="round"244 strokeLinejoin="round"245 />246 </svg>247 );248}249250function SuggestionChip({251 label,252 border,253 color,254 icon,255}: {256 label: string;257 border: string;258 color: string;259 icon: React.ReactNode;260}) {261 return (262 <div263 style={{264 display: "inline-flex",265 alignItems: "center",266 gap: 8,267 padding: "10px 16px",268 borderRadius: 20,269 border: `1px solid ${border}`,270 color,271 fontFamily: SANS_FAMILY,272 fontSize: 15,273 }}274 >275 {icon}276 <span>{label}</span>277 </div>278 );279}280281export function ChatGpt({282 greeting = "What's on your mind today?",283 placeholder = "Ask anything",284 prompt = "Make a sunset over a calm ocean",285 accentColor = "#2F6FED",286 speed = 1,287}: ChatGptProps) {288 const frame = useCurrentFrame();289 const { width, height, fps } = useVideoConfig();290 const t = THEMES.light;291292 const refW = 1280;293 const refH = 720;294 const stageScale = Math.min(width / refW, height / refH);295296 const tw = useTypewriter(prompt, {297 cps: TYPING_CPS,298 speed,299 startFrame: TYPING_START_FRAME,300 });301 const visibleText = tw.text;302 const showText = tw.count > 0;303 const morph = morphProgressAt(frame, { fps, speed });304305 const intro = introBounceIn(frame * speed, fps);306 const headingFade = fadeUpAt(frame * speed, [4, 20]);307 const pillFade = fadeUpAt(frame * speed, [10, 26]);308 const chipsFade = fadeUpAt(frame * speed, [16, 32]);309310 const pillWidth = 820;311 const pillLeft = (refW - pillWidth) / 2;312 const pillTop = 300;313 const pillHeight = 64;314 const morphSize = 44;315316 const chipsOpacity = chipsFade.opacity * (1 - morph);317 const chipsShift = chipsFade.translateY + 8 * morph;318319 return (320 <AbsoluteFill style={{ background: "transparent" }}>321 <div322 style={{323 position: "absolute",324 left: "50%",325 top: "50%",326 width: refW,327 height: refH,328 translate: "-50% -50%",329 scale: `${stageScale}`,330 }}331 >332 <div333 style={{334 position: "absolute",335 left: 0,336 top: 196,337 width: refW,338 textAlign: "center",339 fontFamily: SANS_FAMILY,340 fontSize: 40,341 fontWeight: 700,342 color: t.fg,343 opacity: headingFade.opacity,344 translate: `0 ${headingFade.translateY + intro.translateY * 0.4}px`,345 }}346 >347 {greeting}348 </div>349350 <div351 style={{352 position: "absolute",353 left: pillLeft,354 top: pillTop,355 width: pillWidth,356 height: pillHeight,357 background: t.inputBg,358 border: `1px solid ${t.inputBorder}`,359 borderRadius: 32,360 boxShadow: "0 8px 30px -14px rgba(13,13,13,0.14)",361 opacity: pillFade.opacity,362 translate: `0 ${pillFade.translateY + intro.translateY * 0.6}px`,363 scale: `${intro.scale}`,364 transformOrigin: "center top",365 display: "flex",366 alignItems: "center",367 paddingLeft: 20,368 paddingRight: 12,369 boxSizing: "border-box",370 }}371 >372 <PlusIcon size={24} color={t.fg} />373374 <div375 style={{376 flex: 1,377 display: "flex",378 alignItems: "center",379 marginLeft: 14,380 fontFamily: SANS_FAMILY,381 fontSize: 19,382 overflow: "hidden",383 whiteSpace: "nowrap",384 }}385 >386 {showText ? (387 <span388 style={{389 color: t.fg,390 display: "inline-flex",391 alignItems: "center",392 }}393 >394 {visibleText}395 <Caret396 color={t.fg}397 blink={!tw.typing}398 speed={speed}399 height={22}400 marginLeft={2}401 />402 </span>403 ) : (404 <span405 style={{406 color: t.fgMuted,407 display: "inline-flex",408 alignItems: "center",409 }}410 >411 <Caret412 color={t.fg}413 blink={!tw.typing}414 speed={speed}415 height={22}416 />417 <span style={{ marginLeft: 6 }}>{placeholder}</span>418 </span>419 )}420 </div>421422 <div423 style={{424 display: "flex",425 alignItems: "center",426 gap: 8,427 flexShrink: 0,428 }}429 >430 <div431 style={{432 width: 40,433 height: 40,434 display: "flex",435 alignItems: "center",436 justifyContent: "center",437 }}438 >439 <MicIcon size={22} color={t.iconColor} />440 </div>441442 <div443 style={{444 position: "relative",445 width: morphSize,446 height: morphSize,447 flexShrink: 0,448 }}449 >450 <div451 style={{452 position: "absolute",453 inset: 0,454 display: "flex",455 alignItems: "center",456 justifyContent: "center",457 borderRadius: "100%",458 background: accentColor,459 opacity: 1 - morph,460 scale: `${1 - 0.1 * morph}`,461 }}462 >463 <WaveformIcon size={22} color="#FFFFFF" />464 </div>465 <div466 style={{467 position: "absolute",468 inset: 0,469 display: "flex",470 alignItems: "center",471 justifyContent: "center",472 borderRadius: "100%",473 background: t.sendBg,474 opacity: morph,475 scale: `${0.8 + 0.2 * morph}`,476 }}477 >478 <ArrowUpIcon size={22} color={t.sendArrow} />479 </div>480 </div>481 </div>482 </div>483484 <div485 style={{486 position: "absolute",487 left: 0,488 top: pillTop + pillHeight + 24,489 width: refW,490 display: "flex",491 justifyContent: "center",492 gap: 12,493 opacity: chipsOpacity,494 translate: `0 ${chipsShift}px`,495 }}496 >497 <SuggestionChip498 label="Create an image"499 border={t.chipBorder}500 color={t.chipFg}501 icon={<ImageIcon size={18} color={t.chipFg} />}502 />503 <SuggestionChip504 label="Write or edit"505 border={t.chipBorder}506 color={t.chipFg}507 icon={<PencilIcon size={18} color={t.chipFg} />}508 />509 <SuggestionChip510 label="Look something up"511 border={t.chipBorder}512 color={t.chipFg}513 icon={<GlobeIcon size={18} color={t.chipFg} />}514 />515 </div>516 </div>517 </AbsoluteFill>518 );519}







