migrate compare and tankopedia loadout to new data-driven components, splitting the old monolithic loadout and compare UI into smaller pieces and adding shared Table, Dialog and Scroller primitives

This commit is contained in:
tresabhi committed 2026-11-14 01:17:38 -06:00
1 parent 287aba853f
commit c311a6ab8b
111 files changed
+4009 -3917

No files matched your search

@@ -0,0 +1,85 @@
.scroller {
/* Fits the table, centered by the parent, never wider than the page */
max-width: 100%;
border: var(--space-0) solid var(--gray-a5);
border-radius: var(--space-3);
overflow: hidden;
}
.table {
border-collapse: separate;
border-spacing: 0;
th,
td {
padding: var(--space-3);
text-align: center;
font-weight: inherit;
}
/* Row dividers sit inside the cells, so they take no space. Borders on a row itself don't paint with separate borders, so rows apply them to their cells here */
tbody tr > * {
box-shadow: inset 0 var(--space-0) var(--gray-a4);
}
.column-header {
position: sticky;
top: 0;
z-index: 1;
padding-top: var(--space-4);
padding-bottom: var(--space-4);
background-color: var(--gray-3);
}
.corner {
left: 0;
z-index: 2;
}
.row-header {
position: sticky;
left: 0;
background-color: var(--gray-2);
text-align: left;
}
.group-title,
.group-cell {
position: sticky;
top: var(--head-height, 0);
z-index: 1;
padding-top: var(--space-4);
padding-bottom: var(--space-4);
background-color: var(--gray-3);
}
.group-title {
left: 0;
color: var(--gray-11);
text-align: left;
}
/* A cell spanning the whole row has no room to slide, so its content pins instead */
.pinned {
position: sticky;
left: var(--space-4);
width: fit-content;
}
.cell {
&[data-align="start"] {
text-align: left;
}
&[data-align="end"] {
text-align: right;
}
}
}
@@ -0,0 +1,138 @@
import { useEffect, useRef, type ComponentProps } from "react";
import { classNames } from "../../ui/classNames";
import { Scroller, ScrollerOrientation } from "../Scroller";
import styles from "./index.module.css";
interface RootProps
extends Omit<ComponentProps<typeof Scroller>, "orientation"> {
scrollable?: boolean;
}
// When scrollable, scrolls both ways, keeping the head, the row headers and the group titles in view
function Root({ children, className, scrollable, ...props }: RootProps) {
const table = useRef<HTMLTableElement>(null);
// Group titles stick right below the head, whatever its height
useEffect(() => {
const head = table.current!.tHead;
if (!head) return;
const observer = new ResizeObserver(() => {
table.current!.style.setProperty(
"--head-height",
`${head.offsetHeight}px`
);
});
observer.observe(head);
return () => observer.disconnect();
}, []);
const content = (
<table ref={table} className={styles.table}>
{children}
</table>
);
if (!scrollable) {
return (
<div className={classNames(styles.scroller, className)} {...props}>
{content}
</div>
);
}
return (
<Scroller
orientation={ScrollerOrientation.Both}
startCurtain={false}
className={classNames(styles.scroller, className)}
{...props}
>
{content}
</Scroller>
);
}
function Head(props: ComponentProps<"thead">) {
return <thead {...props} />;
}
function Body(props: ComponentProps<"tbody">) {
return <tbody {...props} />;
}
function Row(props: ComponentProps<"tr">) {
return <tr {...props} />;
}
// Sits where the head and the row headers meet
function Corner({ className, ...props }: ComponentProps<"th">) {
return (
<th
className={classNames(styles["column-header"], styles.corner, className)}
{...props}
/>
);
}
function ColumnHeader({ className, ...props }: ComponentProps<"th">) {
return (
<th className={classNames(styles["column-header"], className)} {...props} />
);
}
function RowHeader({ className, ...props }: ComponentProps<"th">) {
return (
<th className={classNames(styles["row-header"], className)} {...props} />
);
}
// A title that spans columns pins its content instead of sliding away
function GroupTitle({ className, children, ...props }: ComponentProps<"th">) {
return (
<th className={classNames(styles["group-title"], className)} {...props}>
{props.colSpan === undefined ? (
children
) : (
<div className={styles.pinned}>{children}</div>
)}
</th>
);
}
// Shares the group title's row
function GroupCell({ className, ...props }: ComponentProps<"td">) {
return (
<td className={classNames(styles["group-cell"], className)} {...props} />
);
}
interface CellProps extends Omit<ComponentProps<"td">, "align"> {
align?: "start" | "center" | "end";
}
function Cell({ className, align, ...props }: CellProps) {
return (
<td
className={classNames(styles.cell, className)}
data-align={align}
{...props}
/>
);
}
export const Table = {
Root,
Head,
Body,
Row,
Corner,
ColumnHeader,
RowHeader,
GroupTitle,
GroupCell,
Cell,
};