# React Native Gantt Chart (Pro)

> A React Native Gantt chart for iOS, Android and the web: task bars with progress, milestones, dependency arrows, weekends and a today line, day, week and month scales, and drag to move or stretch tasks, with keyboard and screen-reader alternatives.

# Gantt Pro

A project's tasks on a timeline: bars from start to end with the done part filled in, milestones as diamonds, arrows from each task to those waiting on it, weekends shaded and a dashed line at today. Drag a bar to move it or its end to stretch it, in whole days, with a live preview. Days, weeks or months across, with the task names beside.

```tsx
import { Gantt } from '@patine-ui/pro';
```

```tsx live full
import { Gantt } from '@patine-ui/pro';

const inDays = (d) => new Date(Date.now() + d * 86400000);
const start = [
  { id: 'research', name: 'Research', start: inDays(-8), end: inDays(-4), progress: 1, assignee: 'Maya' },
  { id: 'design', name: 'Design', start: inDays(-3), end: inDays(3), progress: 0.6, dependencies: ['research'], assignee: 'Noa', color: '#8B5CF6' },
  { id: 'build', name: 'Build', start: inDays(2), end: inDays(14), progress: 0.15, dependencies: ['design'], assignee: 'Omer' },
  { id: 'qa', name: 'QA', start: inDays(12), end: inDays(17), dependencies: ['build'], assignee: 'Dana', color: 'warning' },
  { id: 'launch', name: 'Launch', start: inDays(19), end: inDays(19), milestone: true, dependencies: ['qa'], color: 'success' },
];

export default function Example() {
  const [tasks, setTasks] = React.useState(start);
  return <Gantt tasks={tasks} onTasksChange={setTasks} style={{ width: '100%' }} />;
}
```

## Example: an office move

An office move planned by the week: tasks depend on each other, the list shows who owns each, and pressing a bar shows its dates. Drag a bar to reschedule it.

```tsx live wide
import { useState } from 'react';
import { View } from 'react-native';
import { Text } from 'patine-ui';
import { Gantt } from '@patine-ui/pro';

const inDays = (d: number) => new Date(Date.now() + d * 86400000);
const START = [
  { id: 'lease', name: 'Sign the lease', start: inDays(-14), end: inDays(-10), progress: 1, assignee: 'Ruth' },
  { id: 'fitout', name: 'Fit-out and wiring', start: inDays(-9), end: inDays(12), progress: 0.4, dependencies: ['lease'], assignee: 'BuildCo', color: '#8B5CF6' },
  { id: 'it', name: 'Network and Wi-Fi', start: inDays(8), end: inDays(16), progress: 0, dependencies: ['fitout'], assignee: 'Omar' },
  { id: 'furniture', name: 'Furniture delivery', start: inDays(14), end: inDays(17), dependencies: ['fitout'], assignee: 'Lena', color: 'warning' },
  { id: 'pack', name: 'Pack the old office', start: inDays(15), end: inDays(19), assignee: 'Everyone' },
  { id: 'move', name: 'Move day', start: inDays(20), end: inDays(20), milestone: true, dependencies: ['it', 'furniture', 'pack'], color: 'success' },
];

export default function Example() {
  const [tasks, setTasks] = useState(START);
  const [picked, setPicked] = useState('');
  return (
    <View style={{ width: '100%', gap: 8 }}>
      <Gantt
        tasks={tasks}
        onTasksChange={setTasks}
        defaultScale="week"
        onTaskPress={(t) => setPicked(`${t.name}: ${t.start.toLocaleDateString()} – ${t.end.toLocaleDateString()}`)}
      />
      <Text size="sm" color="textSecondary">{picked || 'Press a bar for its dates.'}</Text>
    </View>
  );
}
```

## Tasks

A task is `{ id, name, start, end, progress?, dependencies?, color?, milestone?, assignee?, locked?, data? }`. `end` is the last day, included. A milestone is a single day drawn as a diamond. `dependencies` lists the tasks that must finish first, drawn as arrows from their end into this task's start.

## Editing

`onTasksChange(tasks, change)` gets the new tasks after each move: set them as `tasks`, or use `defaultTasks`. `onTaskChange(change)` is the place to save: `{ task, start, end, kind }`, where `kind` is `'move'` or `'resize'`. `editable={false}` makes the chart read-only; a `locked` task stays put. A tap opens a task with `onTaskPress`.

## Scales

`scale` is `'day'`, `'week'` or `'month'` (controlled with `onScaleChange`, or `defaultScale`), with a switch above unless `showScaleSwitch={false}`. `columnWidth` sets a column's width. The range is the tasks' span padded by the scale; `startDate` and `endDate` fix it.

```tsx live full
import { Gantt } from '@patine-ui/pro';

const month = (m, d) => new Date(new Date().getFullYear(), m, d);
const roadmap = [
  { id: 'q1', name: 'Mobile app', start: month(0, 5), end: month(2, 20), progress: 1, color: 'success' },
  { id: 'q2', name: 'Payments', start: month(2, 1), end: month(5, 15), progress: 0.7, dependencies: ['q1'] },
  { id: 'q3', name: 'Marketplace', start: month(5, 1), end: month(8, 30), progress: 0.2, dependencies: ['q2'], color: '#8B5CF6' },
  { id: 'ga', name: 'General availability', start: month(9, 1), end: month(9, 1), milestone: true, dependencies: ['q3'], color: 'danger' },
];

export default function Example() {
  return <Gantt tasks={roadmap} defaultScale="month" editable={false} listWidth={180} style={{ width: '100%' }} />;
}
```

## Accessibility

Each bar is a button read as "Build, Mar 9 to Mar 20, 40% done" (or "Launch, milestone, Mar 23"), with a hint on how to move it. Dragging needs a pointer, so the same moves are screen-reader actions (a day earlier or later, a day shorter or longer) and, on the web, arrow keys and Shift + arrow keys on the focused bar.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tasks` / `defaultTasks` | `GanttTask[]` | `[]` | See [Tasks](#tasks). |
| `onTasksChange` | `(tasks, change) => void` | — | |
| `onTaskChange` | `(change) => void` | — | |
| `onTaskPress` | `(task) => void` | — | |
| `scale` / `defaultScale` / `onScaleChange` | `'day'` \| `'week'` \| `'month'` | `'day'` | |
| `showScaleSwitch` | `boolean` | `true` | |
| `columnWidth` | `number` | day 40, week 96, month 140 | |
| `rowHeight` | `number` | `44` | |
| `showList` / `listWidth` | `boolean` / `number` | `true` / `200` | Task names beside the chart. |
| `editable` | `boolean` | `true` | Drag and keys. |
| `showDependencies` / `showProgress` | `boolean` | `true` | |
| `startDate` / `endDate` | `Date` | the tasks' span | |
| `now` / `locale` | | | |
| `renderBarLabel` | `(info) => ReactNode` | — | |
| `loading` / `error` / `onRetry` / `emptyTitle` / `renderEmpty` | | | States. |
| `density` / `labels` / `design` / `theme` / `accessibilityLabel` / `style` | | | |

Time runs left to right in every language for now.
