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 ganttcraft

Basic 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 refs

Task Context Menu

Right-clicking any task bar opens a floating, keyboard-accessible context menu. Available actions:

ActionDescription
Edit TaskIntegration point for an external edit dialog (hookable via plugin).
Add DependencyOpens a dialog for manually specifying a dependency type (future).
Delete TaskRemoves 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 manually

API Reference

GanttChart Props

PropTypeDefaultDescription
tasksGanttTask[]RequiredThe array of task objects to render.
columnsGanttColumn[]defaultColumnsColumns to display in the left panel.
viewMode'day' | 'week' | 'month''day'The timescale resolution.
themeGanttThemeBuilt-in LightToken overrides for the UI theme.
headlessbooleanfalseIf true, strips all injected CSS custom properties.
showCriticalPathbooleanfalseIf true, highlights tasks on the critical path.
showResourcePanelbooleanfalseIf true, renders the resource allocation histogram.
calendarWorkingCalendarAllDayCalendarWorking calendar for scheduling and drag snapping.
pluginsGanttPlugin[][]Plugin instances to install into the Gantt.
autoSchedulebooleanfalseIf true, adding a dependency triggers a scheduling cascade on successors.
onTasksChange(tasks) => voidCallback fired when tasks change (move, resize, delete, link).
i18nPartial<I18nOptions>defaultI18nPartial i18n overrides. Shipped locales: en, fr, de.

GanttTask Structure

FieldTypeDescription
idstringUnique identifier for the task.
namestringDisplay name of the task.
startDateThe start date/time.
endDateThe end date/time.
progressnumberCompletion percentage (0-100).
parentIdstring (Optional)If provided, nests this task under the parent task id.
dependenciesTaskDependency[]Dependencies for this task (e.g., FS, SS).
assignmentsTaskAssignment[]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 VariableDescriptionDefault (Light Mode)
--gantt-bgMain background color of the chart container#ffffff
--gantt-surfaceBackground for headers and secondary areas#f8f9fa
--gantt-borderColor for grid lines and borders#e2e8f0
--gantt-text-primaryPrimary text color#1a202c
--gantt-text-mutedSecondary/muted text color (e.g. headers)#718096
--gantt-task-fillDefault background color for task bars#4f46e5
--gantt-task-fill-hoverTask background on hover#4338ca
--gantt-milestoneColor for milestone shapes#f59e0b
--gantt-critical-pathHighlight color for tasks on the critical path#ef4444
--gantt-progressColor for the progress bar indicator inside a task#22c55e
--gantt-weekendBackground color highlighting weekend columnsrgba(0,0,0,0.03)
--gantt-today-lineColor of the vertical "today" indicator line#4f46e5
--gantt-focus-ringOutline color when navigating tasks via keyboard#4f46e5