# Advanced Reference: Component Patterns & Code Templates This file contains advanced patterns and code templates to reference when implementing specific tasks. ## Table of Contents 1. [Responsive Slide Engine](#responsive-slide-engine) 2. [Device Simulation Frames](#device-simulation-frames) 3. [Tweaks Panel Implementation](#tweaks-panel-implementation) 4. [Animation Timeline Engine](#animation-timeline-engine) 5. [Design Canvas (Multi-option Comparison)](#design-canvas) 6. [Dark Mode Toggle](#dark-mode-toggle) 7. [Data Visualization Templates](#data-visualization-templates) --- ## Responsive Slide Engine For building fixed-size presentations that auto-fit to any viewport. **Key conventions**: - Internal arrays use 0-indexed, **but numbers displayed to the user are always 1-indexed** - Each `
` gets `data-screen-label="01 Title"`, `data-screen-label="02 Agenda"`, etc. for easy reference - Control buttons go **outside** the `.stage` scaled container to ensure usability on small screens ```html ``` --- ## Device Simulation Frames ### iPhone Frame ```jsx const IPhoneFrame = ({ children, title = "App" }) => (
{/* Status bar */}
9:41
⚡ 📶
{/* Content */}
{children}
{/* Home indicator */}
); ``` ### Browser Window Frame ```jsx const BrowserFrame = ({ children, url = "https://example.com", title = "Page" }) => (
{/* Title bar */}
{url}
{/* Content */}
{children}
); ``` --- ## Tweaks Panel Implementation ```jsx const TweaksPanel = ({ config, onChange, visible }) => { if (!visible) return null; return (
Tweaks
{Object.entries(config).map(([key, value]) => (
{typeof value === 'boolean' ? ( onChange({ ...config, [key]: e.target.checked })} /> ) : typeof value === 'number' ? ( onChange({ ...config, [key]: Number(e.target.value) })} style={{ width: '100%' }} /> ) : value.startsWith('#') ? ( onChange({ ...config, [key]: e.target.value })} /> ) : ( onChange({ ...config, [key]: e.target.value })} style={{ width: '100%', background: 'rgba(255,255,255,0.1)', border: '1px solid rgba(255,255,255,0.2)', borderRadius: 4, padding: '4px 8px', color: '#fff' }} /> )}
))}
); }; ``` --- ## Animation Timeline Engine ```jsx const useTime = (duration = 5000) => { const [time, setTime] = React.useState(0); const [playing, setPlaying] = React.useState(true); const frameRef = React.useRef(); const startRef = React.useRef(); React.useEffect(() => { if (!playing) return; const animate = (timestamp) => { if (!startRef.current) startRef.current = timestamp; const elapsed = (timestamp - startRef.current) % duration; setTime(elapsed / duration); // 0 to 1 frameRef.current = requestAnimationFrame(animate); }; frameRef.current = requestAnimationFrame(animate); return () => cancelAnimationFrame(frameRef.current); }, [playing, duration]); return { time, playing, setPlaying }; }; const Easing = { linear: t => t, easeInOut: t => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t, easeOut: t => 1 - Math.pow(1 - t, 3), easeIn: t => t * t * t, spring: t => 1 - Math.pow(Math.E, -6 * t) * Math.cos(8 * t) }; const interpolate = (t, from, to, easing = Easing.easeInOut) => { const progress = easing(Math.max(0, Math.min(1, t))); return from + (to - from) * progress; }; // Usage example: // const { time } = useTime(3000); // const opacity = interpolate(time, 0, 1); // const x = interpolate(time, -100, 0, Easing.spring); ``` --- ## Design Canvas For displaying multiple design options side by side for comparison: ```jsx const DesignCanvas = ({ options, columns = 3 }) => (
{options.map((option, i) => (
Option {String.fromCharCode(65 + i)}: {option.label}
{option.content}
))}
); ``` --- ## Dark Mode Toggle ```jsx const ThemeProvider = ({ children }) => { const [dark, setDark] = React.useState( window.matchMedia('(prefers-color-scheme: dark)').matches ); const theme = dark ? { bg: '#0a0a0b', surface: '#18181b', border: '#27272a', text: '#fafafa', textMuted: '#a1a1aa', primary: '#3b82f6' } : { bg: '#ffffff', surface: '#f4f4f5', border: '#e4e4e7', text: '#18181b', textMuted: '#71717a', primary: '#2563eb' }; return (
{children}
); }; ``` --- ## Data Visualization Templates ### Chart.js Quick Start ```html ``` --- ## Color System Best Practices Use oklch to define a harmonious color system: ```css :root { /* oklch-based color system */ --primary-h: 250; /* hue */ --primary: oklch(0.55 0.25 var(--primary-h)); --primary-light: oklch(0.75 0.15 var(--primary-h)); --primary-dark: oklch(0.35 0.2 var(--primary-h)); /* Neutrals */ --gray-50: oklch(0.98 0.002 250); --gray-100: oklch(0.96 0.004 250); --gray-200: oklch(0.92 0.006 250); --gray-300: oklch(0.87 0.008 250); --gray-400: oklch(0.71 0.01 250); --gray-500: oklch(0.55 0.014 250); --gray-600: oklch(0.45 0.014 250); --gray-700: oklch(0.37 0.014 250); --gray-800: oklch(0.27 0.014 250); --gray-900: oklch(0.21 0.014 250); } ``` --- ## Font Recommendations (Non-default Choices) > ⚠️ **These are experience-based suggestions, not hard rules.** > - Always prefer fonts already specified by the brand or design system; only refer to this table when the user hasn't provided any font scheme. > - The only hard rule: **Avoid Inter / Roboto / Arial / Fraunces / system-ui — fonts overused by AI-generated content** that instantly signal "this was assembled by AI." > - When choosing fonts, focus on "personality fit" rather than "what's trendy." The table below lists common high-quality choices, not an exhaustive list. | Use Case | Recommendation | Google Fonts Name | |------|------|------------------| | Modern headings | Plus Jakarta Sans | Plus+Jakarta+Sans | | Elegant body text | Outfit | Outfit | | Technical feel | Space Grotesk | Space+Grotesk | | Premium brand | Sora | Sora | | Editorial feel | Newsreader | Newsreader | | Handwritten style | Caveat | Caveat | | Monospace / code | JetBrains Mono | JetBrains+Mono | ```html ``` --- ## Color × Font Pairing Reference > ⚠️ **These are experience-based pairing suggestions, not hard rules.** When you have **absolutely no design context**, pick one as a starting point — it's far better than starting from Inter + #3b82f6. > Once the user provides a brand / design system / reference site, drop this table immediately and follow their materials. For quickly establishing a visual system with personality: | Style | Primary Color (oklch) | Font Pairing | Best For | |---|---|---|---| | Modern tech | `oklch(0.55 0.25 250)` blue-violet | Space Grotesk + Inter | SaaS, dev tools, AI products | | Elegant editorial | `oklch(0.35 0.10 30)` warm brown | Newsreader + Outfit | Content platforms, blogs, editorial | | Premium brand | `oklch(0.20 0.02 250)` near-black | Sora + Plus Jakarta Sans | Luxury, consulting, finance | | Lively consumer | `oklch(0.70 0.20 30)` coral | Plus Jakarta Sans + Outfit | E-commerce, lifestyle, social | | Minimal professional | `oklch(0.50 0.15 200)` teal-blue | Outfit + Space Grotesk | Data products, dashboards, B2B | | Artisan warmth | `oklch(0.55 0.15 80)` caramel | Caveat (decorative) + Newsreader | Food & beverage, education, creative | Avoid these combos: - ❌ Inter + Roboto + blue buttons (peak AI aesthetic) - ❌ Fraunces + purple-pink gradients (overused) - ❌ More than three font families (visual chaos)