-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawingToolsPanel.tsx
More file actions
237 lines (220 loc) · 7.21 KB
/
Copy pathDrawingToolsPanel.tsx
File metadata and controls
237 lines (220 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import React, { useState } from 'react';
import { DrawingTool } from '@/types/charting';
interface DrawingToolsPanelProps {
tools: DrawingTool[];
onStartDrawing: (toolType: DrawingTool['type']) => void;
onRemoveTool: (toolId: string) => void;
onToggleToolVisibility: (toolId: string) => void;
onUpdateToolColor: (toolId: string, color: string) => void;
onClearAll: () => void;
}
const DRAWING_TOOLS: Array<{ type: DrawingTool['type']; label: string }> = [
{ type: 'line', label: 'Line' },
{ type: 'rectangle', label: 'Rectangle' },
{ type: 'circle', label: 'Circle' },
{ type: 'triangle', label: 'Triangle' },
{ type: 'freehand', label: 'Freehand' },
{ type: 'trendline', label: 'Trend Line' },
];
export function DrawingToolsPanel({
tools,
onStartDrawing,
onRemoveTool,
onToggleToolVisibility,
onUpdateToolColor,
onClearAll,
}: DrawingToolsPanelProps) {
const [selectedToolType, setSelectedToolType] = useState<DrawingTool['type'] | null>(null);
const [expandedToolId, setExpandedToolId] = useState<string | null>(null);
return (
<div className="drawing-tools-panel">
<div className="panel-header">
<h3>Drawing Tools</h3>
{tools.length > 0 && (
<button className="clear-all-btn" onClick={onClearAll} aria-label="Clear all drawings">
Clear All
</button>
)}
</div>
<div className="tools-selector">
<label>Select Tool:</label>
<div className="tools-grid">
{DRAWING_TOOLS.map(tool => (
<button
key={tool.type}
className={`tool-btn ${selectedToolType === tool.type ? 'active' : ''}`}
onClick={() => {
setSelectedToolType(tool.type);
onStartDrawing(tool.type);
}}
title={tool.label}
>
{tool.label}
</button>
))}
</div>
</div>
<div className="tools-list">
<h4>Active Drawings ({tools.length})</h4>
{tools.length === 0 ? (
<p className="no-tools">No drawings yet</p>
) : (
tools.map(tool => (
<div key={tool.id} className="tool-item">
<div
className="tool-header"
onClick={() =>
setExpandedToolId(expandedToolId === tool.id ? null : tool.id)
}
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setExpandedToolId(expandedToolId === tool.id ? null : tool.id); } }}
role="button"
tabIndex={0}
aria-expanded={expandedToolId === tool.id}
>
<div className="tool-info">
<input
type="checkbox"
checked={tool.visible}
onChange={() => onToggleToolVisibility(tool.id)}
className="tool-toggle"
/>
<span className="tool-type">{tool.type}</span>
{tool.label && <span className="tool-label">{tool.label}</span>}
<span className="tool-points">({tool.points.length} pts)</span>
<div
className="tool-color-indicator"
style={{ backgroundColor: tool.color }}
/>
</div>
<button
className="remove-btn"
onClick={e => {
e.stopPropagation();
onRemoveTool(tool.id);
}}
aria-label={`Remove ${tool.type} drawing`}
>
×
</button>
</div>
{expandedToolId === tool.id && (
<div className="tool-settings">
<div className="setting-item">
<label>Color:</label>
<div className="color-picker">
<input
type="color"
value={tool.color}
onChange={e => onUpdateToolColor(tool.id, e.target.value)}
/>
<span className="color-value">{tool.color}</span>
</div>
</div>
<div className="setting-item">
<label>Width:</label>
<span className="width-value">{tool.width}px</span>
</div>
<div className="setting-item">
<label>Type:</label>
<span className="type-value">{tool.type}</span>
</div>
{tool.label && (
<div className="setting-item">
<label>Label:</label>
<span className="label-value">{tool.label}</span>
</div>
)}
<div className="setting-item">
<label>Points:</label>
<span className="points-value">{tool.points.length}</span>
</div>
</div>
)}
</div>
))
)}
</div>
</div>
);
}
interface DrawingToolbarProps {
isDrawing: boolean;
currentTool: DrawingTool['type'] | null;
onStartDrawing: (toolType: DrawingTool['type']) => void;
onStopDrawing: () => void;
onUndo?: () => void;
onRedo?: () => void;
}
export function DrawingToolbar({
isDrawing,
currentTool,
onStartDrawing,
onStopDrawing,
onUndo,
onRedo,
}: DrawingToolbarProps) {
return (
<div className="drawing-toolbar">
<div className="toolbar-section">
<span className="status">
{isDrawing ? `Drawing: ${currentTool}` : 'Ready'}
</span>
</div>
{isDrawing && (
<div className="toolbar-actions">
<button onClick={onStopDrawing} className="stop-btn" aria-label="Stop drawing">
Stop Drawing
</button>
{onUndo && (
<button onClick={onUndo} className="undo-btn" title="Undo" aria-label="Undo last action">
↶
</button>
)}
{onRedo && (
<button onClick={onRedo} className="redo-btn" title="Redo" aria-label="Redo last action">
↷
</button>
)}
</div>
)}
</div>
);
}
interface LineDrawingOptionsProps {
width: number;
color: string;
onWidthChange: (width: number) => void;
onColorChange: (color: string) => void;
}
export function LineDrawingOptions({
width,
color,
onWidthChange,
onColorChange,
}: LineDrawingOptionsProps) {
return (
<div className="line-options">
<div className="option-item">
<label>Line Width:</label>
<input
type="range"
min="1"
max="10"
value={width}
onChange={e => onWidthChange(Number(e.target.value))}
className="width-slider"
/>
<span className="width-value">{width}px</span>
</div>
<div className="option-item">
<label>Color:</label>
<input
type="color"
value={color}
onChange={e => onColorChange(e.target.value)}
className="color-input"
/>
</div>
</div>
);
}