Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WorkLog.tsx

135 lines3.6 KB

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