Open History to see the last commit
1import { createContext, use, type ComponentProps, type ReactNode } from "react";
2import { cn } from "../../lib/utils";
3
4const GroupedRows = createContext(false);
5
6/** Groups may span virtualized timeline items. Each part owns its trailing space. */
7export function WorkLogBlock({
8 layout = "standalone",
9 continues = false,
10 children,
11}: {
12 layout?: "standalone" | "group-header" | "group-content";
13 continues?: boolean | undefined;
14 children: ReactNode;
15}) {
16 return (
17 <div
18 className={
19 continues || layout === "group-header"
20 ? "pb-0"
21 : layout === "group-content"
22 ? "pb-1"
23 : "pb-2"
24 }
25 >
26 {children}
27 </div>
28 );
29}
30
31/** Expanded members align with the header and use the same compact row geometry. */
32export function WorkLogList({ children }: { children: ReactNode }) {
33 return (
34 <GroupedRows value>
35 <div className="flex min-w-0 flex-col">{children}</div>
36 </GroupedRows>
37 );
38}
39
40type RowContent = {
41 icon?: ReactNode;
42 label: ReactNode;
43 trailing?: ReactNode;
44};
45
46function WorkLogLine({ icon, label, trailing }: RowContent) {
47 return (
48 <div className="flex min-h-6 min-w-0 items-center gap-1.5 text-sm leading-relaxed select-none [&_*]:select-none">
49 {icon ? (
50 <span className="relative flex size-6 shrink-0 items-center justify-center">{icon}</span>
51 ) : null}
52 <div className="min-w-0 flex-1 truncate text-secondary-label [&_*]:whitespace-nowrap">
53 {label}
54 </div>
55 {trailing}
56 </div>
57 );
58}
59
60const interactionClassName =
61 "cursor-pointer hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70";
62
63function useRowClassName(interactive: boolean) {
64 const grouped = use(GroupedRows);
65 return cn(
66 "group/timeline-row relative w-full min-w-0 rounded-md px-0.5 text-left transition-colors",
67 grouped ? "py-0" : "py-0.5",
68 interactive && interactionClassName,
69 );
70}
71
72// No className/style escape hatch: consumers supply content and behavior, not geometry.
73export function WorkLogButton({
74 icon,
75 label,
76 trailing,
77 ...buttonProps
78}: RowContent & Omit<ComponentProps<"button">, "className" | "style" | "children">) {
79 const className = useRowClassName(true);
80 return (
81 <button {...buttonProps} type="button" className={className}>
82 <WorkLogLine icon={icon} label={label} trailing={trailing} />
83 </button>
84 );
85}
86
87/** Div-based disclosure supports selectable detail and nested actions in an entry. */
88export function WorkLogRow({
89 icon,
90 label,
91 trailing,
92 children,
93 ...rowProps
94}: RowContent & Omit<ComponentProps<"div">, "className" | "style">) {
95 const className = useRowClassName(rowProps.onClick !== undefined);
96 return (
97 <div {...rowProps} className={className}>
98 <WorkLogLine icon={icon} label={label} trailing={trailing} />
99 {children}
100 </div>
101 );
102}
103
104export function WorkLogDetails({
105 children,
106 kind = "text",
107}: {
108 children: ReactNode;
109 kind?: "text" | "panel" | "media";
110}) {
111 return (
112 <div
113 className={cn(
114 "ms-7 cursor-auto",
115 kind === "text"
116 ? "flex max-h-96 flex-col gap-3 overflow-auto px-0.5 py-1 select-text"
117 : kind === "panel"
118 ? "mt-1 rounded-md bg-muted/40 px-3 py-2"
119 : "mt-1",
120 )}
121 onClick={(event) => event.stopPropagation()}
122 onPointerDown={(event) => event.stopPropagation()}
123 >
124 {children}
125 </div>
126 );
127}