forked from usekaneo/kaneo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar-task-bar.tsx
More file actions
67 lines (61 loc) · 2.04 KB
/
Copy pathcalendar-task-bar.tsx
File metadata and controls
67 lines (61 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { useTranslation } from "react-i18next";
import { cn } from "@/lib/cn";
import { formatDateShort } from "@/lib/format";
import type { PackableTask, WeekSegment } from "./month-grid-model";
export type CalendarTask = PackableTask & {
title: string;
number: number | null;
};
type CalendarTaskBarProps = {
segment: WeekSegment<CalendarTask>;
projectSlug?: string;
onOpenTask: (taskId: string) => void;
};
export default function CalendarTaskBar({
segment,
projectSlug,
onOpenTask,
}: CalendarTaskBarProps) {
const { t } = useTranslation();
const {
task,
lane,
columnStart,
columnEnd,
continuesBefore,
continuesAfter,
} = segment;
const taskKey =
projectSlug && task.number != null
? `${projectSlug}-${task.number}`
: undefined;
const range = `${formatDateShort(task.scheduleStart)} – ${formatDateShort(
task.scheduleEnd,
)}`;
return (
<button
type="button"
style={{
gridColumn: `${columnStart} / ${columnEnd}`,
// Row 1 holds the date numbers, so lanes start at row 2.
gridRow: lane + 2,
}}
title={
taskKey
? `${taskKey} · ${task.title} · ${range}`
: `${task.title} · ${range}`
}
aria-label={t("tasks:calendar.taskAriaLabel", { title: task.title })}
onClick={() => onOpenTask(task.id)}
className={cn(
"z-10 mb-0.5 flex h-6 min-w-0 items-center overflow-hidden border border-primary/25 bg-primary/12 px-1.5 text-left text-[11px] font-medium leading-none text-foreground transition-colors hover:border-primary/40 hover:bg-primary/18 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:h-5",
// Bars that run past a week edge lose their cap there so the two halves
// read as one continuous span across rows.
continuesBefore ? "rounded-l-none border-l-0" : "ml-1 rounded-l-md",
continuesAfter ? "rounded-r-none border-r-0" : "mr-1 rounded-r-md",
)}
>
<span className="truncate">{task.title}</span>
</button>
);
}