Gantt chart
A project schedule with a fixed task column and a scrolling date axis: phased bars, progress, milestones and a today marker.
pnpm dlx shadcn@latest add @haze/gantt-chart---
import { Check, CircleAlert, Info, TriangleAlert } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
type Status = "default" | "info" | "success" | "warning" | "destructive";
interface Task {
name: string;
/** Group heading. Tasks with the same phase are listed together, in order of first appearance. */
phase?: string;
/** ISO date, YYYY-MM-DD. */
start: string;
/** ISO date, YYYY-MM-DD, inclusive. */
end: string;
/** Initials of the person responsible. */
owner?: string;
/** 0 to 100. */
progress?: number;
status?: Status;
/** Text shown with the status icon. Defaults to a word for each status. */
statusLabel?: string;
/** Draws a diamond on the start date instead of a bar. */
milestone?: boolean;
}
interface Props {
tasks?: Task[];
/** Accessible name of the scrollable timeline. */
label?: string;
scale?: "day" | "week";
/** Shade Saturdays and Sundays. */
weekends?: boolean;
/** ISO date drawn as a labeled vertical marker. Never read from the clock. */
today?: string;
todayLabel?: string;
taskHeading?: string;
ownerLabel?: string;
doneLabel?: string;
locale?: string;
class?: string;
}
const DAY = 86400000;
const toDay = (iso: string) => Math.floor(Date.parse(`${iso}T00:00:00Z`) / DAY);
const {
tasks = [
{ name: "API freeze", phase: "Build", start: "2026-11-02", end: "2026-11-06", owner: "MO", progress: 100, status: "success" },
{ name: "Checkout redesign", phase: "Build", start: "2026-11-04", end: "2026-11-13", owner: "IS", progress: 60, status: "info" },
{ name: "Pricing page", phase: "Build", start: "2026-11-09", end: "2026-11-13", owner: "TV", progress: 30, status: "destructive", statusLabel: "Blocked" },
{ name: "Beta testing", phase: "Launch", start: "2026-11-12", end: "2026-11-20", owner: "PN", progress: 20, status: "warning" },
{ name: "Launch copy", phase: "Launch", start: "2026-11-16", end: "2026-11-19", owner: "MO", progress: 0 },
{ name: "Public launch", phase: "Launch", start: "2026-11-24", end: "2026-11-24", milestone: true },
],
label = "Product launch schedule, scroll sideways to see all dates",
scale = "week",
weekends = true,
today = "2026-11-12",
todayLabel = "Today",
taskHeading = "Task",
ownerLabel = "Owner",
doneLabel = "done",
locale = "en",
class: className,
} = Astro.props;
const fmt = new Intl.DateTimeFormat(locale, { month: "short", day: "numeric", timeZone: "UTC" });
const dayNum = new Intl.DateTimeFormat(locale, { day: "numeric", timeZone: "UTC" });
const show = (d: number) => fmt.format(new Date(d * DAY));
const NAME_W = "8.5rem";
const statusText: Record<Status, string> = { default: "", info: "In progress", success: "Done", warning: "At risk", destructive: "Blocked" };
const statusIcon = { default: null, info: Info, success: Check, warning: TriangleAlert, destructive: CircleAlert };
const barTone: Record<Status, { track: string; fill: string }> = {
default: { track: "border-border-strong bg-muted", fill: "bg-muted-foreground" },
info: { track: "border-brand-border bg-brand/22", fill: "bg-brand" },
success: { track: "border-success-border bg-success/14", fill: "bg-success" },
warning: { track: "border-warning-border bg-warning/14", fill: "bg-warning" },
destructive: { track: "border-destructive-border bg-destructive/14", fill: "bg-destructive" },
};
const statusColor: Record<Status, string> = { default: "text-muted-foreground", info: "text-brand", success: "text-success", warning: "text-warning", destructive: "text-destructive" };
const rows = tasks
.map((t) => ({ ...t, s: toDay(t.start), e: Math.max(toDay(t.start), toDay(t.end)) }))
.filter((t) => !Number.isNaN(t.s) && !Number.isNaN(t.e));
const todayDay = today ? toDay(today) : NaN;
const hasToday = !Number.isNaN(todayDay);
// Range: whole weeks (Monday to Sunday) around every task and the today marker.
const lo = Math.min(...rows.map((t) => t.s), hasToday ? todayDay : Infinity);
const hi = Math.max(...rows.map((t) => t.e), hasToday ? todayDay : -Infinity);
const mondayOf = (d: number) => d - ((((d + 3) % 7) + 7) % 7); // day 0 (1970-01-01) was a Thursday
const rangeStart = Number.isFinite(lo) ? mondayOf(lo) : mondayOf(toDay("2026-11-02"));
const rangeEnd = Number.isFinite(hi) ? mondayOf(hi) + 7 : rangeStart + 7;
const span = rangeEnd - rangeStart;
const pct = (d: number) => `${(((d - rangeStart) / span) * 100).toFixed(3)}%`;
const minWidth = span * (scale === "day" ? 28 : 16);
const days = Array.from({ length: span }, (_, i) => rangeStart + i);
const mondays = days.filter((d) => mondayOf(d) === d);
const weekendDays = days.filter((d) => {
const w = (((d + 3) % 7) + 7) % 7;
return w >= 5;
});
const phases: { name: string; tasks: typeof rows }[] = [];
for (const t of rows) {
const name = t.phase ?? "";
let group = phases.find((p) => p.name === name);
if (!group) phases.push((group = { name, tasks: [] }));
group.tasks.push(t);
}
const rowStyle = `grid-template-columns: ${NAME_W} minmax(${minWidth}px, 1fr)`;
const innerStyle = `min-width: calc(${NAME_W} + ${minWidth}px)`;
const nameCell = "sticky left-0 z-10 min-w-0 border-r border-border bg-card px-3 py-2";
---
<div class={cn("min-w-0 overflow-hidden rounded-xl border border-frame bg-card", className)}>
<div
role="region"
aria-label={label}
tabindex="0"
class="overflow-x-auto focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
>
<div class="relative" style={innerStyle}>
<div aria-hidden="true" class="pointer-events-none absolute inset-y-0 left-34 right-0">
{weekends && weekendDays.map((d) => <div class="absolute inset-y-0 bg-muted/50" style={`left: ${pct(d)}; width: ${(100 / span).toFixed(3)}%`} />)}
{mondays.map((d) => <div class="absolute inset-y-0 border-l border-border" style={`left: ${pct(d)}`} />)}
{hasToday && <div class="absolute inset-y-0 w-px -translate-x-1/2 bg-brand" style={`left: calc(${pct(todayDay)} + ${(50 / span).toFixed(3)}%)`} />}
</div>
<div class="grid" style={rowStyle}>
<div class={cn(nameCell, "flex items-end text-[0.6875rem]/4 font-medium tracking-wider text-muted-foreground uppercase")}>{taskHeading}</div>
<div aria-hidden="true" class={cn("relative text-xs/4 text-muted-foreground tabular-nums", scale === "day" ? "h-12" : "h-8")}>
{mondays.map((d) => <span class="absolute top-1.5 pl-1.5 whitespace-nowrap" style={`left: ${pct(d)}`}>{show(d)}</span>)}
{scale === "day" && days.map((d) => <span class="absolute bottom-1 text-center text-[0.6875rem]/4" style={`left: ${pct(d)}; width: ${(100 / span).toFixed(3)}%`}>{dayNum.format(new Date(d * DAY))}</span>)}
</div>
</div>
<ul class="m-0 list-none p-0">
{
phases.map((phase) => (
<>
{phase.name && (
<li class="grid border-t border-border" style={rowStyle}>
<p class={cn(nameCell, "py-1.5 text-[0.6875rem]/4 font-medium tracking-wider text-muted-foreground uppercase")}>{phase.name}</p>
<div aria-hidden="true" />
</li>
)}
{phase.tasks.map((t) => {
const status = t.status ?? "default";
const Icon = statusIcon[status];
const text = t.statusLabel ?? statusText[status];
const pctDone = t.progress !== undefined ? Math.min(100, Math.max(0, Math.round(t.progress))) : undefined;
const range = t.milestone ? show(t.s) : `${show(t.s)} – ${show(t.e)}`;
const tone = barTone[status];
return (
<li class="grid border-t border-border" style={rowStyle}>
<div class={nameCell}>
<p class="text-[0.8125rem]/5 font-medium wrap-anywhere text-foreground">{t.name}</p>
<p class="text-xs/4 text-muted-foreground tabular-nums">
{t.milestone && <span class="sr-only">Milestone, </span>}
{range}
{pctDone !== undefined && !t.milestone && <span> · {pctDone}% {doneLabel}</span>}
{t.owner && (
<span>
{" · "}
<span class="sr-only">{ownerLabel} </span>
{t.owner}
</span>
)}
</p>
{text && (
<p class={cn("mt-0.5 flex items-center gap-1 text-xs/4 font-medium", statusColor[status])}>
{Icon && <Icon aria-hidden="true" class="size-3 shrink-0" />}
{text}
</p>
)}
</div>
<div aria-hidden="true" class="relative min-h-10">
{t.milestone ? (
<span
class="absolute top-1/2 size-4 -translate-x-1/2 -translate-y-1/2 rotate-45 rounded-xs border border-border-strong bg-foreground"
style={`left: calc(${pct(t.s)} + ${(50 / span).toFixed(3)}%)`}
/>
) : (
<span
class={cn("absolute top-1/2 h-6 -translate-y-1/2 overflow-hidden rounded-md border", tone.track)}
style={`left: ${pct(t.s)}; width: ${(((t.e - t.s + 1) / span) * 100).toFixed(3)}%`}
>
{pctDone !== undefined && <span class={cn("absolute inset-y-0 left-0", tone.fill)} style={`width: ${pctDone}%`} />}
</span>
)}
</div>
</li>
);
})}
</>
))
}
</ul>
{
hasToday && (
<div class="grid border-t border-border" style={rowStyle}>
<div class={cn(nameCell, "py-1")}>
<span class="sr-only">{todayLabel}: {show(todayDay)}</span>
</div>
<div aria-hidden="true" class="relative h-8">
<span
class={cn(
"absolute top-1.5 rounded-sm bg-brand px-1.5 text-xs/5 font-medium whitespace-nowrap text-brand-foreground tabular-nums",
todayDay - rangeStart < 4 ? "" : rangeEnd - todayDay <= 4 ? "-translate-x-full" : "-translate-x-1/2",
)}
style={`left: calc(${pct(todayDay)} + ${(50 / span).toFixed(3)}%)`}
>
{todayLabel} · {show(todayDay)}
</span>
</div>
</div>
)
}
</div>
</div>
</div>When to use
- A launch or project plan needs to show which tasks overlap and where the milestones fall.
- Task status and progress must read at a glance next to the dates.
- A read-only schedule goes in a status report or client portal.
When not to use
- The list has no dates, only order; use timeline or a plain list.
- Users drag bars to reschedule or link dependencies; that needs a scheduling tool, not this display.
- A single metric over time is plotted; use area-chart or bar-chart.
Installation
Add the Haze registry to components.json once, then install Gantt chart with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/gantt-chartnpx shadcn@latest add @haze/gantt-chartyarn dlx shadcn@latest add @haze/gantt-chartbunx --bun shadcn@latest add @haze/gantt-chartFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| tasks | Task[] | launch demo | Rows with name, phase, start, end (ISO dates, end inclusive), owner initials, progress 0-100, status and milestone. |
| label | string | Product launch schedule, scroll sideways to see all dates | Accessible name of the scrollable timeline region. |
| scale | "day" | "week" | week | Week shows one label per Monday; day adds a number for every day and a wider axis. |
| weekends | boolean | true | Shades Saturdays and Sundays. |
| today | string | 2026-11-12 | ISO date for the today marker. Pass an empty string to hide it. The component never reads the clock. |
| todayLabel | string | Today | Text of the today marker. |
| taskHeading | string | Task | Header of the task column. |
| ownerLabel | string | Owner | Screen reader word read before the owner initials. |
| doneLabel | string | done | Word after the progress percentage. |
| locale | string | en | BCP 47 locale for dates, formatted in UTC. |
| class | string | – | Classes for the outer panel. |
Keyboard interactions
- Tab, then arrow keys
- Focus the timeline region and scroll it sideways.
Accessibility
- Every bar has its meaning as visible text in the task column: dates, percent done, owner and a status word with an icon, so nothing relies on color or bar length.
- The bars, axis and today marker are decorative and hidden from assistive technology; milestones read as 'Milestone, <date>'.
- The scroll region is focusable and named, so keyboard users can pan the timeline with the arrow keys.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Gantt chart" with `npx shadcn@latest add @haze/gantt-chart`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import GanttChart from "@/components/haze/ui/gantt-chart.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/gantt-chart.md
Customize with real content
Adapt the Haze gantt-chart ui for our product. Replace the demo values of these props with our real content: tasks, label, scale, weekends, today, todayLabel, taskHeading, ownerLabel, doneLabel, locale, class. Keep the layout, the heading level rules and these accessibility details: Every bar has its meaning as visible text in the task column: dates, percent done, owner and a status word with an icon, so nothing relies on color or bar length. The bars, axis and today marker are decorative and hidden from assistive technology; milestones read as 'Milestone, <date>'. The scroll region is focusable and named, so keyboard users can pan the timeline with the arrow keys. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using gantt-chart, check it fits: use it when a launch or project plan needs to show which tasks overlap and where the milestones fall.; task status and progress must read at a glance next to the dates.; a read-only schedule goes in a status report or client portal.. Avoid it when the list has no dates, only order; use timeline or a plain list.; users drag bars to reschedule or link dependencies; that needs a scheduling tool, not this display.; a single metric over time is plotted; use area-chart or bar-chart.. Alternatives: @haze/timeline, @haze/bar-chart, @haze/table.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.