import React, { useState, useRef, useEffect } from 'react'; import gsap from 'gsap'; import { FileText, ArrowRight, Database, Layers, HardDrive, RefreshCw } from 'lucide-react'; export const GitWorkflowDiagram: React.FC = () => { const [state, setState] = useState<'modified' | 'staged' | 'committed'>('modified'); // Refs for animation targets const fileRef = useRef(null); const workingDirRef = useRef(null); const stagingRef = useRef(null); const repoRef = useRef(null); const containerRef = useRef(null); useEffect(() => { // Initial entrance animation gsap.fromTo(containerRef.current, { opacity: 0, scale: 0.95 }, { opacity: 1, scale: 1, duration: 0.8, ease: "power2.out" } ); }, []); useEffect(() => { const ctx = gsap.context(() => { // Reset file position when state changes, then animate to new spot // Note: In a real complex app we might calculate exact coordinates using getBoundingClientRect // For this demo, we'll rely on the React re-render to place it in the DOM, then animate "from" the previous position if possible, // or just animate "in" to emphasize the move. // Simple scale/pop effect on change if (fileRef.current) { gsap.fromTo(fileRef.current, { scale: 0.5, opacity: 0, y: 20 }, { scale: 1, opacity: 1, y: 0, duration: 0.5, ease: "back.out(1.7)" } ); } }, containerRef); return () => ctx.revert(); }, [state]); const handleReset = () => { setState('modified'); }; return (

Interactive Workflow

{/* Zones Container */}
{/* Working Directory Zone */}
Working Directory

Where you edit files.

{state === 'modified' && (
script.js
Modified
)}
{/* Staging Area Zone */}
Staging Area

Files ready to commit.

{state === 'staged' && (
script.js
Staged
)}
{/* Repository Zone */}
Repository

Saved history.

{state === 'committed' && (
script.js
Committed
)}
{/* Connecting Arrows (Visual only, hidden on mobile for cleaner look) */}
{state === 'modified' && "You have changed a file. It's in your Working Directory."} {state === 'staged' && "You've added the file to the Staging Area. It's ready to be part of the next snapshot."} {state === 'committed' && "Success! The file is safely stored in the Repository history."}
); };