forked from usekaneo/kaneo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday-overflow-popover.tsx
More file actions
81 lines (76 loc) 路 2.79 KB
/
Copy pathday-overflow-popover.tsx
File metadata and controls
81 lines (76 loc) 路 2.79 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { useState } from "react";
import { useTranslation } from "react-i18next";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { formatDate, formatDateShort } from "@/lib/format";
import type { CalendarTask } from "./calendar-task-bar";
type DayOverflowPopoverProps = {
day: Date;
/** Every task on this day, not just the ones the lane cap hid. */
tasks: CalendarTask[];
hiddenCount: number;
projectSlug?: string;
onOpenTask: (taskId: string) => void;
};
export default function DayOverflowPopover({
day,
tasks,
hiddenCount,
projectSlug,
onOpenTask,
}: DayOverflowPopoverProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const dayLabel = formatDate(day, {
weekday: "long",
month: "long",
day: "numeric",
});
const handleSelectTask = (taskId: string) => {
setOpen(false);
onOpenTask(taskId);
};
return (
<Popover onOpenChange={setOpen} open={open}>
<PopoverTrigger
aria-label={t("tasks:calendar.dayTasksAriaLabel", { date: dayLabel })}
className="w-full truncate rounded-sm px-1.5 pb-1 text-left text-[10px] leading-tight text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{t("tasks:calendar.moreTasks", { count: hiddenCount })}
</PopoverTrigger>
<PopoverContent align="start" className="w-64 p-2">
<div className="space-y-1">
<p className="px-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
{dayLabel}
</p>
<div className="max-h-64 space-y-0.5 overflow-y-auto">
{tasks.map((task) => (
<button
key={task.id}
type="button"
onClick={() => handleSelectTask(task.id)}
className="flex w-full min-w-0 flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{projectSlug && task.number != null ? (
<span className="truncate text-[10px] text-muted-foreground">
{projectSlug}-{task.number}
</span>
) : null}
<span className="w-full truncate text-xs font-medium text-foreground">
{task.title}
</span>
<span className="w-full truncate text-[11px] text-muted-foreground">
{formatDateShort(task.scheduleStart)} 鈥搟" "}
{formatDateShort(task.scheduleEnd)}
</span>
</button>
))}
</div>
</div>
</PopoverContent>
</Popover>
);
}