Skip to content

Commit 8ad7443

Browse files
committed
Table reverted to use linked cells rather than rows
1 parent 47a560b commit 8ad7443

File tree

1 file changed

+26
-37
lines changed
  • apps/webapp/app/components/primitives

1 file changed

+26
-37
lines changed

apps/webapp/app/components/primitives/Table.tsx

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChevronRightIcon } from "@heroicons/react/24/solid";
2-
import { useNavigate } from "@remix-run/react";
2+
import { Link, useNavigate } from "@remix-run/react";
33
import React, { ReactNode, forwardRef, useState } from "react";
44
import { cn } from "~/utils/cn";
55
import { Popover, PopoverContent, PopoverVerticalEllipseTrigger } from "./Popover";
@@ -76,42 +76,11 @@ type TableRowProps = {
7676
};
7777

7878
export const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
79-
({ className, disabled, isSelected, children, to, onClick }, ref) => {
80-
const navigate = useNavigate();
81-
82-
const handleInteraction = (event: React.KeyboardEvent | React.MouseEvent) => {
83-
if ((event.target as HTMLElement).closest('button, a, [role="button"]')) {
84-
return;
85-
}
86-
87-
const firstCellWithTo = React.Children.toArray(children).find((child) => {
88-
if (React.isValidElement(child) && child.type === TableCell) {
89-
return child.props.to;
90-
}
91-
return false;
92-
}) as React.ReactElement | undefined;
93-
94-
if (firstCellWithTo?.props.to) {
95-
navigate(firstCellWithTo.props.to);
96-
} else if (onClick) {
97-
onClick(event);
98-
}
99-
};
100-
101-
const handleKeyDown = (event: React.KeyboardEvent) => {
102-
if (event.key === "Enter") {
103-
event.preventDefault();
104-
event.stopPropagation();
105-
handleInteraction(event);
106-
}
107-
};
108-
79+
({ className, disabled, isSelected, children }, ref) => {
10980
return (
11081
<tr
11182
ref={ref}
11283
tabIndex={disabled ? -1 : 0}
113-
onClick={handleInteraction}
114-
onKeyDown={handleKeyDown}
11584
className={cn(
11685
"group/table-row relative w-full cursor-pointer outline-none after:absolute after:bottom-0 after:left-3 after:right-0 after:h-px after:bg-grid-dimmed focus-visible:bg-background-bright",
11786
disabled && "opacity-50",
@@ -208,6 +177,8 @@ export const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
208177
alignment = "left",
209178
children,
210179
colSpan,
180+
to,
181+
onClick,
211182
hasAction = false,
212183
isSticky = false,
213184
rowHoverStyle = "default",
@@ -225,22 +196,40 @@ export const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
225196
break;
226197
}
227198

199+
const flexClasses = cn(
200+
"flex w-full whitespace-nowrap px-3 py-3 items-center text-xs text-text-dimmed",
201+
alignment === "left"
202+
? "justify-start text-left"
203+
: alignment === "center"
204+
? "justify-center text-center"
205+
: "justify-end text-right"
206+
);
207+
228208
return (
229209
<td
230210
ref={ref}
231211
className={cn(
232212
"text-xs text-charcoal-400",
233-
hasAction ? "cursor-pointer" : "h-10 min-h-10 px-3 align-middle",
234-
alignmentClassName,
235-
actionClassName,
213+
to || onClick || hasAction ? "cursor-pointer" : "px-3 py-3 align-middle",
214+
!to && !onClick && alignmentClassName,
236215
isSticky && stickyStyles,
237216
isSelected && isSelectedStyle,
238217
!isSelected && rowHoverStyles[rowHoverStyle],
239218
className
240219
)}
241220
colSpan={colSpan}
242221
>
243-
{children}
222+
{to ? (
223+
<Link to={to} className={cn("focus-custom", flexClasses, actionClassName)}>
224+
{children}
225+
</Link>
226+
) : onClick ? (
227+
<button onClick={onClick} className={cn("focus-custom", flexClasses, actionClassName)}>
228+
{children}
229+
</button>
230+
) : (
231+
<>{children}</>
232+
)}
244233
</td>
245234
);
246235
}

0 commit comments

Comments
 (0)