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 wrapLabel?: boolean;
45};
46
47function WorkLogLine({ icon, label, trailing, wrapLabel }: RowContent) {
48 return (
49 <div
50 className={cn(
51 "flex min-h-6 min-w-0 gap-1.5 text-sm leading-relaxed select-none [&_*]:select-none",
52 // A wrapped label keeps its icon beside the first line.
53 wrapLabel ? "items-start" : "items-center",
54 )}
55 >
56 {icon ? (
57 <span className="relative flex size-6 shrink-0 items-center justify-center">{icon}</span>
58 ) : null}
59 <div
60 className={cn(
61 "min-w-0 flex-1 text-secondary-label",
62 !wrapLabel && "truncate [&_*]:whitespace-nowrap",
63 )}
64 >
65 {label}
66 </div>
67 {trailing}
68 </div>
69 );
70}
71
72const interactionClassName =
73 "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70";
74
75function useRowClassName(interactive: boolean) {
76 const grouped = use(GroupedRows);
77 return cn(
78 "group/timeline-row relative w-full min-w-0 rounded-md px-0.5 text-left transition-colors",
79 grouped ? "py-0" : "py-0.5",
80 interactive && interactionClassName,
81 );
82}
83
84// No className/style escape hatch: consumers supply content and behavior, not geometry.
85export function WorkLogButton({
86 icon,
87 label,
88 trailing,
89 wrapLabel = false,
90 ...buttonProps
91}: RowContent & Omit<ComponentProps<"button">, "className" | "style" | "children">) {
92 const className = useRowClassName(true);
93 return (
94 <button {...buttonProps} type="button" className={className}>
95 <WorkLogLine icon={icon} label={label} trailing={trailing} wrapLabel={wrapLabel} />
96 </button>
97 );
98}
99
100/** Div-based disclosure supports selectable detail and nested actions in an entry. */
101export function WorkLogRow({
102 icon,
103 label,
104 trailing,
105 wrapLabel = false,
106 children,
107 ...rowProps
108}: RowContent & Omit<ComponentProps<"div">, "className" | "style">) {
109 const className = useRowClassName(rowProps.onClick !== undefined);
110 return (
111 <div {...rowProps} className={className}>
112 <WorkLogLine icon={icon} label={label} trailing={trailing} wrapLabel={wrapLabel} />
113 {children}
114 </div>
115 );
116}
117
118export function WorkLogDetails({
119 children,
120 kind = "text",
121}: {
122 children: ReactNode;
123 kind?: "text" | "panel" | "media";
124}) {
125 return (
126 <div
127 className={cn(
128 "cursor-auto",
129 kind === "text"
130 ? "ms-7 flex max-h-96 flex-col gap-3 overflow-auto px-0.5 py-1 select-text"
131 : kind === "panel"
132 ? "mt-0.5 mb-1.5"
133 : "mt-1",
134 )}
135 onClick={(event) => event.stopPropagation()}
136 onPointerDown={(event) => event.stopPropagation()}
137 >
138 {children}
139 </div>
140 );
141}