Skip to content

Commit db211b7

Browse files
committed
Use nebari table.
1 parent 1d18672 commit db211b7

16 files changed

Lines changed: 1294 additions & 918 deletions

‎frontend/package-lock.json‎

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎frontend/package.json.md5‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a40e966fad08faa6ae7cb9d42e23138d
1+
84fe402c69f4878124e03cf2a0fdf3bf
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
import type * as React from 'react';
2+
import { useCallback, useEffect, useRef, useState } from 'react';
3+
import { cn } from '@/lib/utils';
4+
5+
type TableProps = React.ComponentProps<'table'> & {
6+
/** Accessible name for the horizontal scroll container. */
7+
scrollContainerLabel?: string;
8+
/** Additional classes for the horizontal scroll container. */
9+
scrollContainerClassName?: string;
10+
/**
11+
* Props forwarded to the horizontal scroll container. Its `tabIndex`
12+
* overrides the automatic focusability applied when the table overflows.
13+
*/
14+
scrollContainerProps?: Omit<React.ComponentProps<'section'>, 'children'>;
15+
};
16+
17+
type TableHeadProps = Omit<
18+
React.ComponentProps<'th'>,
19+
'onClick' | 'onKeyDown'
20+
> & {
21+
/** Makes the header sortable by rendering its contents in a real button. */
22+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
23+
onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;
24+
};
25+
26+
/** Responsive table frame with Nebari border, radius, and surface styling. */
27+
function Table({
28+
className,
29+
scrollContainerClassName,
30+
scrollContainerLabel,
31+
scrollContainerProps,
32+
'aria-label': ariaLabel,
33+
'aria-labelledby': ariaLabelledBy,
34+
...props
35+
}: TableProps) {
36+
const {
37+
className: scrollContainerPropsClassName,
38+
'aria-label': scrollContainerAriaLabel,
39+
'aria-labelledby': scrollContainerAriaLabelledBy,
40+
ref: scrollContainerRef,
41+
tabIndex: scrollContainerTabIndex,
42+
...resolvedScrollContainerProps
43+
} = scrollContainerProps ?? {};
44+
const internalScrollContainerRef = useRef<HTMLElement>(null);
45+
const [isHorizontallyScrollable, setIsHorizontallyScrollable] =
46+
useState(false);
47+
const setScrollContainerRef = useCallback(
48+
(element: HTMLElement | null) => {
49+
internalScrollContainerRef.current = element;
50+
51+
if (typeof scrollContainerRef === 'function') {
52+
return scrollContainerRef(element);
53+
}
54+
55+
if (scrollContainerRef) {
56+
scrollContainerRef.current = element;
57+
}
58+
},
59+
[scrollContainerRef],
60+
);
61+
const resolvedScrollContainerLabel =
62+
scrollContainerAriaLabel ??
63+
scrollContainerLabel ??
64+
(ariaLabel === undefined
65+
? 'Table scroll area'
66+
: `${ariaLabel} scroll area`);
67+
68+
useEffect(() => {
69+
const scrollContainer = internalScrollContainerRef.current;
70+
if (!scrollContainer) {
71+
return;
72+
}
73+
74+
const updateScrollability = () => {
75+
setIsHorizontallyScrollable(
76+
scrollContainer.scrollWidth > scrollContainer.clientWidth,
77+
);
78+
};
79+
80+
updateScrollability();
81+
window.addEventListener('resize', updateScrollability);
82+
83+
const resizeObserver =
84+
typeof ResizeObserver === 'undefined'
85+
? undefined
86+
: new ResizeObserver(updateScrollability);
87+
resizeObserver?.observe(scrollContainer);
88+
89+
const table = scrollContainer.querySelector('table');
90+
if (table) {
91+
resizeObserver?.observe(table);
92+
}
93+
94+
return () => {
95+
window.removeEventListener('resize', updateScrollability);
96+
resizeObserver?.disconnect();
97+
};
98+
}, []);
99+
100+
return (
101+
<section
102+
{...resolvedScrollContainerProps}
103+
aria-label={
104+
scrollContainerAriaLabelledBy === undefined
105+
? resolvedScrollContainerLabel
106+
: undefined
107+
}
108+
aria-labelledby={scrollContainerAriaLabelledBy}
109+
data-slot="table-container"
110+
ref={setScrollContainerRef}
111+
tabIndex={
112+
scrollContainerTabIndex ?? (isHorizontallyScrollable ? 0 : undefined)
113+
}
114+
className={cn(
115+
'relative w-full overflow-x-auto rounded-md border border-border bg-card outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
116+
scrollContainerClassName,
117+
scrollContainerPropsClassName,
118+
)}
119+
>
120+
<table
121+
aria-label={ariaLabel}
122+
aria-labelledby={ariaLabelledBy}
123+
data-slot="table"
124+
className={cn(
125+
'w-full border-collapse bg-card caption-bottom text-left text-sm',
126+
className,
127+
)}
128+
{...props}
129+
/>
130+
</section>
131+
);
132+
}
133+
134+
function TableHeader({ className, ...props }: React.ComponentProps<'thead'>) {
135+
return (
136+
<thead
137+
data-slot="table-header"
138+
className={cn('bg-background', className)}
139+
{...props}
140+
/>
141+
);
142+
}
143+
144+
function TableBody({ className, ...props }: React.ComponentProps<'tbody'>) {
145+
return (
146+
<tbody
147+
data-slot="table-body"
148+
className={cn('[&_tr:last-child]:border-0', className)}
149+
{...props}
150+
/>
151+
);
152+
}
153+
154+
function TableFooter({ className, ...props }: React.ComponentProps<'tfoot'>) {
155+
return (
156+
<tfoot
157+
data-slot="table-footer"
158+
className={cn(
159+
'border-t border-border bg-card font-medium [&>tr]:last:border-b-0',
160+
className,
161+
)}
162+
{...props}
163+
/>
164+
);
165+
}
166+
167+
function TableRow({ className, ...props }: React.ComponentProps<'tr'>) {
168+
return (
169+
<tr
170+
data-slot="table-row"
171+
className={cn(
172+
'border-b border-border hover:bg-muted/50 data-[state=selected]:bg-muted data-[state=selected]:hover:bg-muted motion-safe:transition-[color,background-color] motion-safe:duration-(--duration-fast) motion-safe:ease-(--ease-standard)',
173+
className,
174+
)}
175+
{...props}
176+
/>
177+
);
178+
}
179+
180+
function TableHead({
181+
className,
182+
children,
183+
onClick,
184+
onKeyDown,
185+
tabIndex,
186+
...props
187+
}: TableHeadProps) {
188+
const isInteractive = onClick != null;
189+
const ariaSort = props['aria-sort'] ?? (isInteractive ? 'none' : undefined);
190+
191+
return (
192+
<th
193+
{...props}
194+
aria-sort={ariaSort}
195+
data-slot="table-head"
196+
tabIndex={isInteractive ? undefined : tabIndex}
197+
className={cn(
198+
'relative h-10 bg-background text-left align-middle font-medium text-foreground text-sm leading-5 tracking-normal whitespace-nowrap [&:has([role=checkbox])]:pr-0',
199+
isInteractive ? 'p-0' : 'px-4',
200+
className,
201+
)}
202+
>
203+
{isInteractive ? (
204+
<button
205+
className="inline-flex h-10 w-full cursor-pointer items-center justify-start gap-1 bg-transparent px-4 text-left font-medium text-foreground text-sm leading-5 tracking-normal underline-offset-4 outline-none hover:bg-muted-foreground/10 hover:underline focus-visible:bg-muted-foreground/10 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset motion-safe:transition-[color,background-color] motion-safe:duration-(--duration-fast) motion-safe:ease-(--ease-standard)"
206+
data-slot="table-head-button"
207+
onClick={onClick}
208+
onKeyDown={onKeyDown}
209+
tabIndex={tabIndex}
210+
type="button"
211+
>
212+
{children}
213+
</button>
214+
) : (
215+
children
216+
)}
217+
</th>
218+
);
219+
}
220+
221+
function TableCell({ className, ...props }: React.ComponentProps<'td'>) {
222+
return (
223+
<td
224+
data-slot="table-cell"
225+
className={cn(
226+
'h-12 px-4 py-3 align-middle text-foreground text-sm leading-5 [&:has([role=checkbox])]:pr-0',
227+
className,
228+
)}
229+
{...props}
230+
/>
231+
);
232+
}
233+
234+
function TableCaption({
235+
className,
236+
...props
237+
}: React.ComponentProps<'caption'>) {
238+
return (
239+
<caption
240+
data-slot="table-caption"
241+
className={cn('px-4 py-3 text-muted-foreground text-xs', className)}
242+
{...props}
243+
/>
244+
);
245+
}
246+
247+
export type { TableHeadProps, TableProps };
248+
export {
249+
Table,
250+
TableBody,
251+
TableCaption,
252+
TableCell,
253+
TableFooter,
254+
TableHead,
255+
TableHeader,
256+
TableRow,
257+
};

‎frontend/src/components/workspace/PixiTomlEditor.tsx‎

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { useEffect, useId, useRef, useState } from 'react';
33
import { Button } from '@/components/ui/button';
44
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
55
import { Input } from '@/components/ui/input';
6+
import {
7+
Table,
8+
TableBody,
9+
TableCell,
10+
TableHead,
11+
TableHeader,
12+
TableRow,
13+
} from '@/components/ui/table';
614
import { Textarea } from '@/components/ui/textarea';
715

816
interface Package {
@@ -394,43 +402,39 @@ export const PixiTomlEditor = ({
394402
>
395403
Packages
396404
</h3>
397-
<div className="border rounded-lg overflow-hidden">
398-
<table className="w-full" aria-labelledby={packagesHeadingId}>
399-
<thead className="bg-muted/50 border-b">
400-
<tr>
401-
<th className="text-left p-3 text-sm font-medium">Name</th>
402-
<th className="text-left p-3 text-sm font-medium">
403-
Version Constraint
404-
</th>
405-
<th className="w-16"></th>
406-
</tr>
407-
</thead>
408-
<tbody className="divide-y">
409-
{packages.map((pkg) => (
410-
<tr key={pkg.name} className="hover:bg-muted/30">
411-
<td className="p-3">
412-
<span className="font-mono text-sm">{pkg.name}</span>
413-
</td>
414-
<td className="p-3">
415-
<span className="font-mono text-sm text-muted-foreground">
416-
{pkg.version || '-'}
417-
</span>
418-
</td>
419-
<td className="p-3">
420-
<Button
421-
type="button"
422-
variant="ghost"
423-
size="sm"
424-
onClick={() => handleRemovePackage(pkg.name)}
425-
>
426-
<Trash2 className="h-4 w-4" />
427-
</Button>
428-
</td>
429-
</tr>
430-
))}
431-
</tbody>
432-
</table>
433-
</div>
405+
<Table aria-labelledby={packagesHeadingId}>
406+
<TableHeader>
407+
<TableRow>
408+
<TableHead>Name</TableHead>
409+
<TableHead>Version Constraint</TableHead>
410+
<TableHead className="w-16" />
411+
</TableRow>
412+
</TableHeader>
413+
<TableBody>
414+
{packages.map((pkg) => (
415+
<TableRow key={pkg.name}>
416+
<TableCell>
417+
<span className="font-mono">{pkg.name}</span>
418+
</TableCell>
419+
<TableCell>
420+
<span className="font-mono text-muted-foreground">
421+
{pkg.version || '-'}
422+
</span>
423+
</TableCell>
424+
<TableCell>
425+
<Button
426+
type="button"
427+
variant="ghost"
428+
size="sm"
429+
onClick={() => handleRemovePackage(pkg.name)}
430+
>
431+
<Trash2 className="h-4 w-4" />
432+
</Button>
433+
</TableCell>
434+
</TableRow>
435+
))}
436+
</TableBody>
437+
</Table>
434438
</div>
435439

436440
<div className="flex gap-2">

0 commit comments

Comments
 (0)