Polaroid
An instant-photo frame with a handwritten caption for video, images, or live compositions.
Source
components/kuchi/polaroid.tsx
1"use client";23import type React from "react";4import { Handwrite } from "@/components/kuchi/handwrite";5import { DEFAULT_STEP } from "@/lib/kuchi/stop-motion";67const BASE_WIDTH = 652;8const BASE_PAD = 16;9const BASE_MEDIA_WIDTH = 620;10const BASE_MEDIA_HEIGHT = 349;11const BASE_CAPTION_HEIGHT = 62;12const BASE_CAPTION_SIZE = 36;1314export type PolaroidGeometry = {15 pad: number;16 mediaWidth: number;17 mediaHeight: number;18 captionHeight: number;19 height: number;20};2122export function polaroidGeometry(width: number): PolaroidGeometry {23 const scale = width / BASE_WIDTH;24 const pad = BASE_PAD * scale;25 const mediaWidth = BASE_MEDIA_WIDTH * scale;26 const mediaHeight = BASE_MEDIA_HEIGHT * scale;27 const captionHeight = BASE_CAPTION_HEIGHT * scale;28 return {29 pad,30 mediaWidth,31 mediaHeight,32 captionHeight,33 height: pad + mediaHeight + captionHeight,34 };35}3637export interface PolaroidProps {38 children: React.ReactNode;39 caption?: string;40 captionAt?: number;41 width?: number;42 frameColor?: string;43 captionColor?: string;44 captionSize?: number;45 step?: number;46}4748export function Polaroid({49 children,50 caption,51 captionAt = 0,52 width = BASE_WIDTH,53 frameColor = "#fdfcf8",54 captionColor = "#26242c",55 captionSize,56 step = DEFAULT_STEP,57}: PolaroidProps) {58 const { pad, mediaWidth, mediaHeight, captionHeight, height } =59 polaroidGeometry(width);60 const resolvedCaptionSize =61 captionSize ?? BASE_CAPTION_SIZE * (width / BASE_WIDTH);6263 return (64 <div65 style={{66 width,67 height,68 boxSizing: "border-box",69 background: frameColor,70 borderRadius: 4,71 boxShadow:72 "0 8px 20px rgba(38,36,44,0.18), 0 2px 5px rgba(38,36,44,0.12)",73 paddingTop: pad,74 }}75 >76 <div77 style={{78 position: "relative",79 width: mediaWidth,80 height: mediaHeight,81 margin: "0 auto",82 background: "#100f14",83 overflow: "hidden",84 }}85 >86 {children}87 </div>88 <div style={{ position: "relative", height: captionHeight }}>89 {caption ? (90 <Handwrite91 text={caption}92 fontSize={resolvedCaptionSize}93 color={captionColor}94 delay={captionAt}95 perStep={1.4}96 weight={600}97 step={step}98 />99 ) : null}100 </div>101 </div>102 );103}









