import { useState } from "react"; import { cn } from "~/lib/utils"; import { Minus, ArrowRight, Type, Circle, Square, TrendingUp, Eraser, Undo, Redo, } from "lucide-react"; import { Button } from "@/routes/ui/button"; export type AnnotationType = "line" | "arrow" | "text" | "circle" | "rectangle" | "fibonacci"; export interface Annotation { id: string; type: AnnotationType; coordinates: { x: number; y: number }[]; text?: string; color: string; } export interface AnnotationToolsProps { /** Callback when annotation is added */ onAnnotationAdd?: (annotation: Annotation) => void; /** Callback when annotation is removed */ onAnnotationRemove?: (id: string) => void; /** Callback when undo is clicked */ onUndo?: () => void; /** Callback when redo is clicked */ onRedo?: () => void; /** Additional class names */ className?: string; } /** * AnnotationTools - Drawing tools for chart annotations * * Features: * - Line tool for trend lines, support/resistance * - Arrow tool for directional indicators * - Text tool for labels * - Shape tools (circle, rectangle) * - Fibonacci retracement tool * - Color picker * - Undo/Redo functionality */ export function AnnotationTools({ onAnnotationAdd, onAnnotationRemove, onUndo, onRedo, className, }: AnnotationToolsProps) { const [selectedTool, setSelectedTool] = useState(null); const [selectedColor, setSelectedColor] = useState("#3b82f6"); // blue-500 const tools: { type: AnnotationType; icon: any; label: string }[] = [ { type: "line", icon: Minus, label: "Line" }, { type: "arrow", icon: ArrowRight, label: "Arrow" }, { type: "text", icon: Type, label: "Text" }, { type: "circle", icon: Circle, label: "Circle" }, { type: "rectangle", icon: Square, label: "Rectangle" }, { type: "fibonacci", icon: TrendingUp, label: "Fibonacci" }, ]; const colors = [ { value: "#3b82f6", label: "Blue" }, { value: "#ef4444", label: "Red" }, { value: "#22c55e", label: "Green" }, { value: "#eab308", label: "Yellow" }, { value: "#a855f7", label: "Purple" }, { value: "#ffffff", label: "White" }, ]; const handleToolSelect = (tool: AnnotationType) => { setSelectedTool(tool === selectedTool ? null : tool); }; return (
{/* Drawing Tools */}

Drawing Tools

{tools.map(({ type, icon: Icon, label }) => ( ))}
{/* Color Picker */}

Color

{colors.map(({ value, label }) => (
{/* Actions */}
{/* Instructions */} {selectedTool && (
{selectedTool === "line" && "Click and drag to draw a line"} {selectedTool === "arrow" && "Click and drag to draw an arrow"} {selectedTool === "text" && "Click to add text label"} {selectedTool === "circle" && "Click and drag to draw a circle"} {selectedTool === "rectangle" && "Click and drag to draw a rectangle"} {selectedTool === "fibonacci" && "Click two points to draw Fibonacci retracement"}
)}
); }