GanttCraft Documentation
GanttCraft is a professional-grade, strictly typed, zero-dependency React Gantt library built for performance and enterprise use cases.
Installation
Install the library using your preferred package manager:
npm install ganttcraft# or
pnpm add ganttcraft# or
yarn add ganttcraftBasic Usage
To get started, import the GanttChart component and provide it with an array of tasks.
import { GanttChart } from 'ganttcraft';
import type { GanttTask } from 'ganttcraft';
const tasks: GanttTask[] = [
{
id: 'task-1',
name: 'Project Alpha',
start: new Date('2026-05-01T00:00:00Z'),
end: new Date('2026-05-15T00:00:00Z'),
progress: 50,
},
{
id: 'task-2',
name: 'Design Phase',
start: new Date('2026-05-01T00:00:00Z'),
end: new Date('2026-05-05T00:00:00Z'),
progress: 100,
parentId: 'task-1', // Creates a hierarchy
}
];
export default function MyGanttApp() {
return (
<div style={{ height: '500px', width: '100%' }}>
<GanttChart tasks={tasks} viewMode="day" />
</div>
);
}Advanced Features
Working Calendars
GanttCraft supports different working calendars for date arithmetic. The default is AllDayCalendar (24/7). You can use StandardCalendar to automatically skip weekends (Saturday/Sunday) when dragging tasks or auto-scheduling dependencies.
import { GanttChart, StandardCalendar } from 'ganttcraft';
<GanttChart
tasks={tasks}
calendar={StandardCalendar}
/>Critical Path Analysis
Enable showCriticalPath to highlight tasks that have zero float (tasks that directly impact the project end date). These tasks will be highlighted in red (customizable via theme).
<GanttChart tasks={tasks} showCriticalPath />Resource Panel
Display a resource allocation histogram by enabling showResourcePanel. This uses task assignments to calculate utilization and highlights overallocated resources.
<GanttChart tasks={tasks} showResourcePanel />History Manager (Undo/Redo)
GanttCraft provides a HistoryManager to handle undo/redo operations. You can hook it up to your keyboard events or UI buttons to easily implement standard undo functionality.
import { HistoryManager } from 'ganttcraft';
// Initialize with an empty history or initial state
const history = new HistoryManager();
// After a task update:
history.pushState(newTasks);
// To Undo:
if (history.canUndo()) {
const previousTasks = history.undo();
setTasks(previousTasks);
}
// To Redo:
if (history.canRedo()) {
const nextTasks = history.redo();
setTasks(nextTasks);
}Plugins
Extend GanttCraft by passing an array of plugins to the plugins prop. Plugins can intercept task updates or render custom overlays (like special warning icons or external links).
const myPlugin = {
name: 'my-custom-plugin',
beforeUpdateTask: (task) => {
// Return false to prevent an update
if (task.start < new Date()) return false;
return true;
},
renderTaskOverlay: (task) => (
task.isOverdue ? <div className="text-red-500">!</div> : null
)
};
<GanttChart tasks={tasks} plugins={[myPlugin]} />Internationalization (i18n)
Customize dates and strings by passing an i18n object. It uses date-fns locales for robust date formatting. GanttCraft ships three built-in locales (en, fr, de) via the locales registry.
import { GanttChart, locales } from 'ganttcraft';
// Use a built-in locale
<GanttChart tasks={tasks} i18n={locales.fr} />
// Or override specific keys
const myI18n = {
locale: fr,
strings: {
taskName: 'Nom de la tâche',
startDate: 'Date de début',
endDate: 'Date de fin',
progress: 'Avancement',
editTask: 'Modifier la tâche',
deleteTask: 'Supprimer la tâche',
}
};
<GanttChart tasks={tasks} i18n={myI18n} />Interactive Dependency Linking
Hover over any task bar to reveal a circular link handleon its right edge. Drag from the handle to another task's drop zone to create a Finish-to-Start dependency. If autoSchedule is enabled, successor dates update in real-time.
<GanttChart
tasks={tasks}
autoSchedule
onTasksChange={(updated) => setTasks(updated)}
/>
// Programmatic API via context
import { useGanttContext } from 'ganttcraft';
const { addDependency, deleteTask } = useGanttContext();
addDependency('task-1', 'task-2'); // Creates FS dependency
deleteTask('task-3'); // Removes task + all its dependency refsTask Context Menu
Right-clicking any task bar opens a floating, keyboard-accessible context menu. Available actions:
| Action | Description |
|---|---|
| Edit Task | Integration point for an external edit dialog (hookable via plugin). |
| Add Dependency | Opens a dialog for manually specifying a dependency type (future). |
| Delete Task | Removes the task and all dependency references. Fully undoable. |
Navigate with ↑/↓, confirm with Enter, dismiss with Escape.
PNG Export
Export the current chart view as a PNG image. GanttCraft automatically clones the SVG, strips <foreignObject> elements, and inlines all var(--gantt-*) CSS custom property tokens so theming survives the rasterisation step.
import { exportPNG, inlineCSSCustomProperties, flattenForeignObjects } from 'ganttcraft';
// Simple usage
const svgEl = document.querySelector('.gantt-svg') as SVGSVGElement;
await exportPNG(svgEl, 'my-project.png');
// Advanced: override token colours in the export
const clone = svgEl.cloneNode(true) as SVGSVGElement;
flattenForeignObjects(clone);
inlineCSSCustomProperties(clone, { '--gantt-task-fill': '#1d4ed8' });
// ... then serialise clone to canvas manuallyAPI Reference
GanttChart Props
| Prop | Type | Default | Description |
|---|---|---|---|
| tasks | GanttTask[] | Required | The array of task objects to render. |
| columns | GanttColumn[] | defaultColumns | Columns to display in the left panel. |
| viewMode | 'day' | 'week' | 'month' | 'day' | The timescale resolution. |
| theme | GanttTheme | Built-in Light | Token overrides for the UI theme. |
| headless | boolean | false | If true, strips all injected CSS custom properties. |
| showCriticalPath | boolean | false | If true, highlights tasks on the critical path. |
| showResourcePanel | boolean | false | If true, renders the resource allocation histogram. |
| calendar | WorkingCalendar | AllDayCalendar | Working calendar for scheduling and drag snapping. |
| plugins | GanttPlugin[] | [] | Plugin instances to install into the Gantt. |
| autoSchedule | boolean | false | If true, adding a dependency triggers a scheduling cascade on successors. |
| onTasksChange | (tasks) => void | — | Callback fired when tasks change (move, resize, delete, link). |
| i18n | Partial<I18nOptions> | defaultI18n | Partial i18n overrides. Shipped locales: en, fr, de. |
GanttTask Structure
| Field | Type | Description |
|---|---|---|
| id | string | Unique identifier for the task. |
| name | string | Display name of the task. |
| start | Date | The start date/time. |
| end | Date | The end date/time. |
| progress | number | Completion percentage (0-100). |
| parentId | string (Optional) | If provided, nests this task under the parent task id. |
| dependencies | TaskDependency[] | Dependencies for this task (e.g., FS, SS). |
| assignments | TaskAssignment[] | Resource assignments used in the resource panel. |
Theming & Headless Mode
GanttCraft uses CSS Custom Properties (Variables) to style its components. By default, the library automatically injects a light theme into the DOM tree.
Headless Mode
If your application uses a strict design system (like Tailwind or styled-components) and you want absolute control over styling without our variables interfering, pass headless={true}.
<GanttChart tasks={tasks} headless={true} />This prevents GanttCraft from injecting any CSS variables. You will then need to define all the required CSS variables in your own global stylesheets.
Available CSS Custom Properties
| CSS Variable | Description | Default (Light Mode) |
|---|---|---|
| --gantt-bg | Main background color of the chart container | #ffffff |
| --gantt-surface | Background for headers and secondary areas | #f8f9fa |
| --gantt-border | Color for grid lines and borders | #e2e8f0 |
| --gantt-text-primary | Primary text color | #1a202c |
| --gantt-text-muted | Secondary/muted text color (e.g. headers) | #718096 |
| --gantt-task-fill | Default background color for task bars | #4f46e5 |
| --gantt-task-fill-hover | Task background on hover | #4338ca |
| --gantt-milestone | Color for milestone shapes | #f59e0b |
| --gantt-critical-path | Highlight color for tasks on the critical path | #ef4444 |
| --gantt-progress | Color for the progress bar indicator inside a task | #22c55e |
| --gantt-weekend | Background color highlighting weekend columns | rgba(0,0,0,0.03) |
| --gantt-today-line | Color of the vertical "today" indicator line | #4f46e5 |
| --gantt-focus-ring | Outline color when navigating tasks via keyboard | #4f46e5 |