All files / src/components HeaderControls.jsx

0% Statements 0/22
0% Branches 0/10
0% Functions 0/14
0% Lines 0/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                                                                                                                                                                                         
/**
 * @fileoverview Header Controls Component
 * @description Quick access simulation controls for the header area
 * @module components/HeaderControls
 */
 
import { useSimulation, useSimulationDispatch } from '../context/SimulationContext';
import './HeaderControls.css';
 
/**
 * Header Controls Component
 * Provides quick access to common simulation controls
 * @returns {JSX.Element} Header controls bar
 */
function HeaderControls() {
  const simulation = useSimulation();
  const dispatch = useSimulationDispatch();
 
  const handleScreenshot = () => {
    const canvas = document.querySelector('.simulation-canvas');
    if (canvas) {
      const link = document.createElement('a');
      link.download = `simulation-${Date.now()}.png`;
      link.href = canvas.toDataURL('image/png');
      link.click();
    }
  };
 
  return (
    <div className="header-controls">
      <div className="header-control-group">
        <button 
          className={`header-btn ${simulation.isPaused ? 'paused' : 'running'}`}
          onClick={() => dispatch({ type: 'TOGGLE_PAUSE' })}
          title={simulation.isPaused ? 'Resume (Space)' : 'Pause (Space)'}
        >
          {simulation.isPaused ? '▶ Play' : '⏸ Pause'}
        </button>
        <button 
          className="header-btn"
          onClick={() => dispatch({ type: 'RESET_SIMULATION' })}
          title="Reset simulation (R)"
        >
          🔄 Reset
        </button>
        <button 
          className="header-btn danger"
          onClick={() => dispatch({ type: 'CLEAR_ATOMS' })}
          title="Clear all atoms"
        >
          🗑 Clear
        </button>
        <button 
          className="header-btn"
          onClick={() => dispatch({ type: 'UNDO' })}
          disabled={simulation.undoStack.length === 0}
          title="Undo (Ctrl+Z)"
        >
          ↩ Undo
        </button>
        <button 
          className="header-btn"
          onClick={() => dispatch({ type: 'REDO' })}
          disabled={simulation.redoStack.length === 0}
          title="Redo (Ctrl+Y)"
        >
          ↪ Redo
        </button>
      </div>
 
      <div className="header-control-group toggles">
        <label className="header-toggle" title="Show/hide atomic bonds (B)">
          <input
            type="checkbox"
            checked={simulation.showBonds}
            onChange={() => dispatch({ type: 'TOGGLE_BONDS' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Bonds</span>
        </label>
        <label className="header-toggle" title="Enable/disable physics simulation">
          <input
            type="checkbox"
            checked={simulation.enablePhysics}
            onChange={() => dispatch({ type: 'TOGGLE_PHYSICS' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Physics</span>
        </label>
        <label className="header-toggle" title="Show velocity vectors (V)">
          <input
            type="checkbox"
            checked={simulation.showVelocityVectors}
            onChange={() => dispatch({ type: 'TOGGLE_VELOCITY_VECTORS' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Vectors</span>
        </label>
        <label className="header-toggle" title="Show atom labels (L)">
          <input
            type="checkbox"
            checked={simulation.showAtomLabels}
            onChange={() => dispatch({ type: 'TOGGLE_ATOM_LABELS' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Labels</span>
        </label>
        <label className="header-toggle" title="Color atoms by velocity (blue=slow, red=fast)">
          <input
            type="checkbox"
            checked={simulation.colorByVelocity}
            onChange={() => dispatch({ type: 'TOGGLE_COLOR_BY_VELOCITY' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Heat</span>
        </label>
        <label className="header-toggle" title="Show motion trails behind atoms">
          <input
            type="checkbox"
            checked={simulation.showMotionTrails}
            onChange={() => dispatch({ type: 'TOGGLE_MOTION_TRAILS' })}
          />
          <span className="toggle-switch"></span>
          <span className="toggle-text">Trails</span>
        </label>
      </div>
 
      <div className="header-control-group">
        <button 
          className="header-btn"
          onClick={handleScreenshot}
          title="Take screenshot"
        >
          📷
        </button>
        <button 
          className="header-btn"
          onClick={() => dispatch({ type: 'TOGGLE_FULLSCREEN' })}
          title="Toggle fullscreen (F)"
        >
          {simulation.isFullscreen ? '⊡' : '⛶'}
        </button>
      </div>
    </div>
  );
}
 
export default HeaderControls;