Shared Table component

This commit is contained in:
Gregory Schier
2026-03-11 15:51:57 -07:00
parent 3e7d04b2f3
commit 0c52fd03e2
11 changed files with 67 additions and 32 deletions

View File

@@ -6,7 +6,7 @@ import { Checkbox } from './core/Checkbox';
import { IconButton } from './core/IconButton';
import { PlainInput } from './core/PlainInput';
import { HStack, VStack } from './core/Stacks';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from './core/Table';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '@yaakapp-internal/ui';
interface Props {
workspace: Workspace;

View File

@@ -22,7 +22,7 @@ import { Icon } from '@yaakapp-internal/ui';
import { IconButton } from '../core/IconButton';
import { PlainInput } from '../core/PlainInput';
import { HStack, VStack } from '../core/Stacks';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '../core/Table';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '@yaakapp-internal/ui';
const HOLD_KEYS = ['Shift', 'Control', 'Alt', 'Meta'];
const LAYOUT_INSENSITIVE_KEYS = [

View File

@@ -26,7 +26,7 @@ import { InlineCode } from '../core/InlineCode';
import { Link } from '../core/Link';
import { PlainInput } from '../core/PlainInput';
import { HStack } from '../core/Stacks';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '../core/Table';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '@yaakapp-internal/ui';
import { TabContent, Tabs } from '../core/Tabs/Tabs';
import { EmptyStateText } from '../EmptyStateText';
import { SelectFile } from '../SelectFile';

View File

@@ -1,105 +0,0 @@
import classNames from 'classnames';
import type { ReactNode } from 'react';
export function Table({
children,
className,
scrollable,
}: {
children: ReactNode;
className?: string;
scrollable?: boolean;
}) {
return (
<div className={classNames('w-full', scrollable && 'h-full overflow-y-auto')}>
<table
className={classNames(
className,
'w-full text-sm mb-auto min-w-full max-w-full',
'border-separate border-spacing-0',
scrollable && '[&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10',
)}
>
{children}
</table>
</div>
);
}
export function TableBody({ children }: { children: ReactNode }) {
return (
<tbody className="[&>tr:not(:last-child)>td]:border-b [&>tr:not(:last-child)>td]:border-b-surface-highlight">
{children}
</tbody>
);
}
export function TableHead({ children, className }: { children: ReactNode; className?: string }) {
return (
<thead
className={classNames(
className,
'bg-surface [&_th]:border-b [&_th]:border-b-surface-highlight',
)}
>
{children}
</thead>
);
}
export function TableRow({ children }: { children: ReactNode }) {
return <tr>{children}</tr>;
}
export function TableCell({
children,
className,
align = 'left',
}: {
children: ReactNode;
className?: string;
align?: 'left' | 'center' | 'right';
}) {
return (
<td
className={classNames(
className,
'py-2 [&:not(:first-child)]:pl-4 whitespace-nowrap',
align === 'left' ? 'text-left' : align === 'center' ? 'text-center' : 'text-right',
)}
>
{children}
</td>
);
}
export function TruncatedWideTableCell({
children,
className,
}: {
children: ReactNode;
className?: string;
}) {
return (
<TableCell className={classNames(className, 'truncate max-w-0 w-full')}>{children}</TableCell>
);
}
export function TableHeaderCell({
children,
className,
}: {
children?: ReactNode;
className?: string;
}) {
return (
<th
className={classNames(
className,
'py-2 [&:not(:first-child)]:pl-4 text-left text-text-subtle',
)}
>
{children}
</th>
);
}

View File

@@ -2,7 +2,7 @@ import { useGit } from '@yaakapp-internal/git';
import { showDialog } from '../../lib/dialog';
import { Button } from '../core/Button';
import { IconButton } from '../core/IconButton';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '../core/Table';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '@yaakapp-internal/ui';
import { gitCallbacks } from './callbacks';
import { addGitRemote } from './showAddRemoteDialog';

View File

@@ -8,7 +8,7 @@ import {
TableHeaderCell,
TableRow,
TruncatedWideTableCell,
} from '../core/Table';
} from '@yaakapp-internal/ui';
interface Props {
log: GitCommit[];

View File

@@ -1,7 +1,7 @@
import classNames from 'classnames';
import Papa from 'papaparse';
import { useMemo } from 'react';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '../core/Table';
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from '@yaakapp-internal/ui';
interface Props {
text: string | null;