import { useState, useMemo } from 'react';
import { Gantt, Editor } from '@svar-ui/react-gantt';
import '@svar-ui/react-gantt/all.css';
const tasks = [
{ id: 1, text: 'Kickoff', type: 'task', start: new Date(2026, 3, 2), duration: 2, progress: 100 },
{ id: 2, text: 'Design', type: 'task', start: new Date(2026, 3, 6), duration: 4, progress: 50 },
{ id: 3, text: 'Development', type: 'task', start: new Date(2026, 3, 12), duration: 6, progress: 0 },
{ id: 4, text: 'QA', type: 'task', start: new Date(2026, 3, 20), duration: 3, progress: 0 },
{ id: 5, text: 'Parallel work',type: 'task', start: new Date(2026, 3, 6), duration: 2, progress: 0 },
];
const links = [
{ id: 1, source: 1, target: 2, type: 'e2s' },
{ id: 2, source: 2, target: 3, type: 'e2s' },
{ id: 3, source: 3, target: 4, type: 'e2s' },
{ id: 4, source: 1, target: 5, type: 'e2s' },
];
export default function App() {
const [api, setApi] = useState();
const [pathMode, setPathMode] = useState('flexible');
const [projectEnd, setProjectEnd] = useState(new Date(2026, 3, 24));
return (
<>
<label>
Mode:
<select
value={pathMode}
onChange={(e) => setPathMode(e.target.value)}
>
<option value="flexible">Flexible</option>
<option value="strict">Strict</option>
</select>
</label>
<Gantt
init={setApi}
tasks={tasks}
links={links}
criticalPath={{ type: pathMode }}
projectStart={new Date(2026, 3, 2)}
projectEnd={projectEnd}
/>
{api && <Editor api={api} />}
</>
);
}