'use client'; import { AnimatePresence, motion, useReducedMotion } from 'motion/react'; import posthog from 'posthog-js'; import { useEffect, useRef, useState } from 'react'; const setupOptions = { you: { label: 'For you', displayContent: 'npx @open-slide/cli init', content: 'npx @open-slide/cli init', copyLabel: 'Copy setup command', }, agent: { label: 'For your agent', displayContent: 'Copy Prompt', content: 'Set up an open-slide workspace with `npx @open-slide/cli init`. Install the dependencies, start the dev server, and tell me the local URL when it is ready.', copyLabel: 'Copy agent setup prompt', }, } as const; type SetupMode = keyof typeof setupOptions; type SetupDirection = 1 | -1; const setupModes = Object.keys(setupOptions) as SetupMode[]; const setupContentVariants = { enter: (direction: SetupDirection) => ({ opacity: 0, y: direction === 1 ? 8 : -8 }), center: { opacity: 1, y: 0 }, exit: (direction: SetupDirection) => ({ opacity: 0, y: direction === 1 ? -8 : 8 }), }; export function HeroSetup() { const [mode, setMode] = useState('you'); const [direction, setDirection] = useState(1); const [copied, setCopied] = useState(false); const copiedTimer = useRef>(undefined); const reduceMotion = useReducedMotion(); const option = setupOptions[mode]; useEffect(() => () => clearTimeout(copiedTimer.current), []); const selectMode = (nextMode: SetupMode) => { if (nextMode === mode) return; clearTimeout(copiedTimer.current); setCopied(false); setDirection(nextMode === 'agent' ? 1 : -1); setMode(nextMode); posthog.capture('hero_setup_mode_selected', { mode: nextMode }); }; const copySetup = async () => { if (!(await writeToClipboard(option.content))) return; clearTimeout(copiedTimer.current); setCopied(true); copiedTimer.current = setTimeout(() => setCopied(false), 1500); posthog.capture(mode === 'you' ? 'command_copied' : 'agent_setup_prompt_copied', { location: 'hero', }); }; return (
{setupModes.map((key, index) => (
{index > 0 ? ( ) : null}
))}
); } async function writeToClipboard(content: string): Promise { if (navigator.clipboard?.writeText) { try { await navigator.clipboard.writeText(content); return true; } catch { return copyWithExecCommand(content); } } return copyWithExecCommand(content); } function copyWithExecCommand(content: string): boolean { const textArea = document.createElement('textarea'); textArea.value = content; textArea.setAttribute('readonly', ''); textArea.style.position = 'fixed'; textArea.style.opacity = '0'; document.body.append(textArea); textArea.select(); try { return document.execCommand('copy'); } finally { textArea.remove(); } } function CopyGlyph({ className }: { className?: string }) { return ( ); } function CheckGlyph({ className }: { className?: string }) { return ( ); }