Skip to content

Modern Docker Management, Designed for Everyone

fix: improve container list table

Kyle Mendell13822befb2db
diff --git a/package-lock.json b/package-lock.json
index eee6f79a8..8a1ac8535 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,6 +8,7 @@
"name": "arcane",
"version": "0.0.1",
"dependencies": {
+ "@tanstack/table-core": "^8.21.3",
"@types/dockerode": "^3.3.38",
"dockerode": "^4.0.5",
"mode-watcher": "^1.0.2"
@@ -1855,6 +1856,19 @@
"vite": "^5.2.0 || ^6"
}
},
+ "node_modules/@tanstack/table-core": {
+ "version": "8.21.3",
+ "resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.3.tgz",
+ "integrity": "sha512-ldZXEhOBb8Is7xLs01fR3YEc3DERiz5silj8tnGkFZytt1abEvl/GhUmCE0PMLaMPTa3Jk4HbKmRlHmu+gCftg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ }
+ },
"node_modules/@types/cookie": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz",
diff --git a/package.json b/package.json
index 3a206f34d..8c986497a 100644
--- a/package.json
+++ b/package.json
@@ -39,6 +39,7 @@
"zod": "^3.24.3"
},
"dependencies": {
+ "@tanstack/table-core": "^8.21.3",
"@types/dockerode": "^3.3.38",
"dockerode": "^4.0.5",
"mode-watcher": "^1.0.2"
diff --git a/src/lib/components/data-table-actions.svelte b/src/lib/components/data-table-actions.svelte
new file mode 100644
index 000000000..9a88b4894
--- /dev/null
+++ b/src/lib/components/data-table-actions.svelte
@@ -0,0 +1,34 @@
+<script lang="ts">
+ import Ellipsis from "@lucide/svelte/icons/ellipsis";
+ import { Button } from "$lib/components/ui/button/index.js";
+ import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
+
+ let { id }: { id: string } = $props();
+</script>
+
+<DropdownMenu.Root>
+ <DropdownMenu.Trigger>
+ {#snippet child({ props })}
+ <Button
+ {...props}
+ variant="ghost"
+ size="icon"
+ class="relative size-8 p-0"
+ >
+ <span class="sr-only">Open menu</span>
+ <Ellipsis />
+ </Button>
+ {/snippet}
+ </DropdownMenu.Trigger>
+ <DropdownMenu.Content>
+ <DropdownMenu.Group>
+ <DropdownMenu.GroupHeading>Actions</DropdownMenu.GroupHeading>
+ <DropdownMenu.Item onclick={() => navigator.clipboard.writeText(id)}>
+ Copy payment ID
+ </DropdownMenu.Item>
+ </DropdownMenu.Group>
+ <DropdownMenu.Separator />
+ <DropdownMenu.Item>View customer</DropdownMenu.Item>
+ <DropdownMenu.Item>View payment details</DropdownMenu.Item>
+ </DropdownMenu.Content>
+</DropdownMenu.Root>
diff --git a/src/lib/components/data-table.svelte b/src/lib/components/data-table.svelte
new file mode 100644
index 000000000..dc0dac2bf
--- /dev/null
+++ b/src/lib/components/data-table.svelte
@@ -0,0 +1,64 @@
+<script lang="ts" generics="TData, TValue">
+ import { type ColumnDef, getCoreRowModel } from "@tanstack/table-core";
+ import {
+ createSvelteTable,
+ FlexRender,
+ } from "$lib/components/ui/data-table/index.js";
+ import * as Table from "$lib/components/ui/table/index.js";
+
+ type DataTableProps<TData, TValue> = {
+ columns: ColumnDef<TData, TValue>[];
+ data: TData[];
+ };
+
+ let { data, columns }: DataTableProps<TData, TValue> = $props();
+
+ const table = createSvelteTable({
+ get data() {
+ return data;
+ },
+ columns,
+ getCoreRowModel: getCoreRowModel(),
+ });
+</script>
+
+<div class="rounded-md border">
+ <Table.Root>
+ <Table.Header>
+ {#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
+ <Table.Row>
+ {#each headerGroup.headers as header (header.id)}
+ <Table.Head>
+ {#if !header.isPlaceholder}
+ <FlexRender
+ content={header.column.columnDef.header}
+ context={header.getContext()}
+ />
+ {/if}
+ </Table.Head>
+ {/each}
+ </Table.Row>
+ {/each}
+ </Table.Header>
+ <Table.Body>
+ {#each table.getRowModel().rows as row (row.id)}
+ <Table.Row data-state={row.getIsSelected() && "selected"}>
+ {#each row.getVisibleCells() as cell (cell.id)}
+ <Table.Cell>
+ <FlexRender
+ content={cell.column.columnDef.cell}
+ context={cell.getContext()}
+ />
+ </Table.Cell>
+ {/each}
+ </Table.Row>
+ {:else}
+ <Table.Row>
+ <Table.Cell colspan={columns.length} class="h-24 text-center">
+ No results.
+ </Table.Cell>
+ </Table.Row>
+ {/each}
+ </Table.Body>
+ </Table.Root>
+</div>
diff --git a/src/lib/components/ui/data-table/data-table.svelte.ts b/src/lib/components/ui/data-table/data-table.svelte.ts
new file mode 100644
index 000000000..b4834ce60
--- /dev/null
+++ b/src/lib/components/ui/data-table/data-table.svelte.ts
@@ -0,0 +1,112 @@
+import {
+ type RowData,
+ type TableOptions,
+ type TableOptionsResolved,
+ type TableState,
+ createTable,
+} from "@tanstack/table-core";
+
+/**
+ * Creates a reactive TanStack table object for Svelte.
+ * @param options Table options to create the table with.
+ * @returns A reactive table object.
+ * @example
+ * ```svelte
+ * <script>
+ * const table = createSvelteTable({ ... })
+ * </script>
+ *
+ * <table>
+ * <thead>
+ * {#each table.getHeaderGroups() as headerGroup}
+ * <tr>
+ * {#each headerGroup.headers as header}
+ * <th colspan={header.colSpan}>
+ * <FlexRender content={header.column.columnDef.header} context={header.getContext()} />
+ * </th>
+ * {/each}
+ * </tr>
+ * {/each}
+ * </thead>
+ * <!-- ... -->
+ * </table>
+ * ```
+ */
+export function createSvelteTable<TData extends RowData>(options: TableOptions<TData>) {
+ const resolvedOptions: TableOptionsResolved<TData> = mergeObjects(
+ {
+ state: {},
+ onStateChange() {},
+ renderFallbackValue: null,
+ mergeOptions: (
+ defaultOptions: TableOptions<TData>,
+ options: Partial<TableOptions<TData>>
+ ) => {
+ return mergeObjects(defaultOptions, options);
+ },
+ },
+ options
+ );
+
+ const table = createTable(resolvedOptions);
+ let state = $state<Partial<TableState>>(table.initialState);
+
+ function updateOptions() {
+ table.setOptions((prev) => {
+ return mergeObjects(prev, options, {
+ state: mergeObjects(state, options.state || {}),
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ onStateChange: (updater: any) => {
+ if (updater instanceof Function) state = updater(state);
+ else state = mergeObjects(state, updater);
+
+ options.onStateChange?.(updater);
+ },
+ });
+ });
+ }
+
+ updateOptions();
+
+ $effect.pre(() => {
+ updateOptions();
+ });
+
+ return table;
+}
+
+/**
+ * Merges objects together while keeping their getters alive.
+ * Taken from SolidJS: {@link https://github.com/solidjs/solid/blob/24abc825c0996fd2bc8c1de1491efe9a7e743aff/packages/solid/src/server/rendering.ts#L82-L115}
+ */
+function mergeObjects<T>(source: T): T;
+function mergeObjects<T, U>(source: T, source1: U): T & U;
+function mergeObjects<T, U, V>(source: T, source1: U, source2: V): T & U & V;
+function mergeObjects<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+function mergeObjects(...sources: any): any {
+ const target = {};
+ for (let i = 0; i < sources.length; i++) {
+ let source = sources[i];
+ if (typeof source === "function") source = source();
+ if (source) {
+ const descriptors = Object.getOwnPropertyDescriptors(source);
+ for (const key in descriptors) {
+ if (key in target) continue;
+ Object.defineProperty(target, key, {
+ enumerable: true,
+ get() {
+ for (let i = sources.length - 1; i >= 0; i--) {
+ let s = sources[i];
+ if (typeof s === "function") s = s();
+ const v = (s || {})[key];
+ if (v !== undefined) return v;
+ }
+ },
+ });
+ }
+ }
+ }
+ return target;
+}
diff --git a/src/lib/components/ui/data-table/flex-render.svelte b/src/lib/components/ui/data-table/flex-render.svelte
new file mode 100644
index 000000000..de3563f0e
--- /dev/null
+++ b/src/lib/components/ui/data-table/flex-render.svelte
@@ -0,0 +1,43 @@
+<script lang="ts" module>
+ import type { CellContext, ColumnDefTemplate, HeaderContext } from "@tanstack/table-core";
+
+ type TData = unknown;
+ type TValue = unknown;
+ type TContext = unknown;
+</script>
+
+<script
+ lang="ts"
+ generics="TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>"
+>
+ import { RenderComponentConfig, RenderSnippetConfig } from "./render-helpers.js";
+ type Props = {
+ /** The cell or header field of the current cell's column definition. */
+ content?: TContext extends HeaderContext<TData, TValue>
+ ? ColumnDefTemplate<HeaderContext<TData, TValue>>
+ : TContext extends CellContext<TData, TValue>
+ ? ColumnDefTemplate<CellContext<TData, TValue>>
+ : never;
+ /** The result of the `getContext()` function of the header or cell */
+ context: TContext;
+ };
+
+ let { content, context }: Props = $props();
+</script>
+
+{#if typeof content === "string"}
+ {content}
+{:else if content instanceof Function}
+ <!-- It's unlikely that a CellContext will be passed to a Header -->
+ <!-- eslint-disable-next-line @typescript-eslint/no-explicit-any -->
+ {@const result = content(context as any)}
+ {#if result instanceof RenderComponentConfig}
+ {@const { component: Component, props } = result}
+ <Component {...props} />
+ {:else if result instanceof RenderSnippetConfig}
+ {@const { snippet, params } = result}
+ {@render snippet(params)}
+ {:else}
+ {result}
+ {/if}
+{/if}
diff --git a/src/lib/components/ui/data-table/index.ts b/src/lib/components/ui/data-table/index.ts
new file mode 100644
index 000000000..5f4e77ea0
--- /dev/null
+++ b/src/lib/components/ui/data-table/index.ts
@@ -0,0 +1,3 @@
+export { default as FlexRender } from "./flex-render.svelte";
+export { renderComponent, renderSnippet } from "./render-helpers.js";
+export { createSvelteTable } from "./data-table.svelte.js";
diff --git a/src/lib/components/ui/data-table/render-helpers.ts b/src/lib/components/ui/data-table/render-helpers.ts
new file mode 100644
index 000000000..1984642ee
--- /dev/null
+++ b/src/lib/components/ui/data-table/render-helpers.ts
@@ -0,0 +1,111 @@
+import type { Component, ComponentProps, Snippet } from "svelte";
+
+/**
+ * A helper class to make it easy to identify Svelte components in
+ * `columnDef.cell` and `columnDef.header` properties.
+ *
+ * > NOTE: This class should only be used internally by the adapter. If you're
+ * reading this and you don't know what this is for, you probably don't need it.
+ *
+ * @example
+ * ```svelte
+ * {@const result = content(context as any)}
+ * {#if result instanceof RenderComponentConfig}
+ * {@const { component: Component, props } = result}
+ * <Component {...props} />
+ * {/if}
+ * ```
+ */
+export class RenderComponentConfig<TComponent extends Component> {
+ component: TComponent;
+ props: ComponentProps<TComponent> | Record<string, never>;
+ constructor(
+ component: TComponent,
+ props: ComponentProps<TComponent> | Record<string, never> = {}
+ ) {
+ this.component = component;
+ this.props = props;
+ }
+}
+
+/**
+ * A helper class to make it easy to identify Svelte Snippets in `columnDef.cell` and `columnDef.header` properties.
+ *
+ * > NOTE: This class should only be used internally by the adapter. If you're
+ * reading this and you don't know what this is for, you probably don't need it.
+ *
+ * @example
+ * ```svelte
+ * {@const result = content(context as any)}
+ * {#if result instanceof RenderSnippetConfig}
+ * {@const { snippet, params } = result}
+ * {@render snippet(params)}
+ * {/if}
+ * ```
+ */
+export class RenderSnippetConfig<TProps> {
+ snippet: Snippet<[TProps]>;
+ params: TProps;
+ constructor(snippet: Snippet<[TProps]>, params: TProps) {
+ this.snippet = snippet;
+ this.params = params;
+ }
+}
+
+/**
+ * A helper function to help create cells from Svelte components through ColumnDef's `cell` and `header` properties.
+ *
+ * This is only to be used with Svelte Components - use `renderSnippet` for Svelte Snippets.
+ *
+ * @param component A Svelte component
+ * @param props The props to pass to `component`
+ * @returns A `RenderComponentConfig` object that helps svelte-table know how to render the header/cell component.
+ * @example
+ * ```ts
+ * // +page.svelte
+ * const defaultColumns = [
+ * columnHelper.accessor('name', {
+ * header: header => renderComponent(SortHeader, { label: 'Name', header }),
+ * }),
+ * columnHelper.accessor('state', {
+ * header: header => renderComponent(SortHeader, { label: 'State', header }),
+ * }),
+ * ]
+ * ```
+ * @see {@link https://tanstack.com/table/latest/docs/guide/column-defs}
+ */
+export function renderComponent<
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ T extends Component<any>,
+ Props extends ComponentProps<T>,
+>(component: T, props: Props) {
+ return new RenderComponentConfig(component, props);
+}
+
+/**
+ * A helper function to help create cells from Svelte Snippets through ColumnDef's `cell` and `header` properties.
+ *
+ * The snippet must only take one parameter.
+ *
+ * This is only to be used with Snippets - use `renderComponent` for Svelte Components.
+ *
+ * @param snippet
+ * @param params
+ * @returns - A `RenderSnippetConfig` object that helps svelte-table know how to render the header/cell snippet.
+ * @example
+ * ```ts
+ * // +page.svelte
+ * const defaultColumns = [
+ * columnHelper.accessor('name', {
+ * cell: cell => renderSnippet(nameSnippet, { name: cell.row.name }),
+ * }),
+ * columnHelper.accessor('state', {
+ * cell: cell => renderSnippet(stateSnippet, { state: cell.row.state }),
+ * }),
+ * ]
+ * ```
+ * @see {@link https://tanstack.com/table/latest/docs/guide/column-defs}
+ */
+export function renderSnippet<TProps>(snippet: Snippet<[TProps]>, params: TProps) {
+ return new RenderSnippetConfig(snippet, params);
+}
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte
new file mode 100644
index 000000000..3f1575a36
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte
@@ -0,0 +1,40 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive, type WithoutChildrenOrChild } from "bits-ui";
+ import Check from "@lucide/svelte/icons/check";
+ import Minus from "@lucide/svelte/icons/minus";
+ import { cn } from "$lib/utils.js";
+ import type { Snippet } from "svelte";
+
+ let {
+ ref = $bindable(null),
+ checked = $bindable(false),
+ indeterminate = $bindable(false),
+ class: className,
+ children: childrenProp,
+ ...restProps
+ }: WithoutChildrenOrChild<DropdownMenuPrimitive.CheckboxItemProps> & {
+ children?: Snippet;
+ } = $props();
+</script>
+
+<DropdownMenuPrimitive.CheckboxItem
+ bind:ref
+ bind:checked
+ bind:indeterminate
+ class={cn(
+ "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
+ className
+ )}
+ {...restProps}
+>
+ {#snippet children({ checked, indeterminate })}
+ <span class="absolute left-2 flex size-3.5 items-center justify-center">
+ {#if indeterminate}
+ <Minus class="size-4" />
+ {:else}
+ <Check class={cn("size-4", !checked && "text-transparent")} />
+ {/if}
+ </span>
+ {@render childrenProp?.()}
+ {/snippet}
+</DropdownMenuPrimitive.CheckboxItem>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte
new file mode 100644
index 000000000..fdbaa4710
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte
@@ -0,0 +1,26 @@
+<script lang="ts">
+ import { cn } from "$lib/utils.js";
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+
+ let {
+ ref = $bindable(null),
+ sideOffset = 4,
+ portalProps,
+ class: className,
+ ...restProps
+ }: DropdownMenuPrimitive.ContentProps & {
+ portalProps?: DropdownMenuPrimitive.PortalProps;
+ } = $props();
+</script>
+
+<DropdownMenuPrimitive.Portal {...portalProps}>
+ <DropdownMenuPrimitive.Content
+ bind:ref
+ {sideOffset}
+ class={cn(
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-md outline-none",
+ className
+ )}
+ {...restProps}
+ />
+</DropdownMenuPrimitive.Portal>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte
new file mode 100644
index 000000000..84d5cca29
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte
@@ -0,0 +1,19 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ inset,
+ ...restProps
+ }: DropdownMenuPrimitive.GroupHeadingProps & {
+ inset?: boolean;
+ } = $props();
+</script>
+
+<DropdownMenuPrimitive.GroupHeading
+ bind:ref
+ class={cn("px-2 py-1.5 text-sm font-semibold", inset && "pl-8", className)}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte
new file mode 100644
index 000000000..70a523615
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import { cn } from "$lib/utils.js";
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ inset,
+ ...restProps
+ }: DropdownMenuPrimitive.ItemProps & {
+ inset?: boolean;
+ } = $props();
+</script>
+
+<DropdownMenuPrimitive.Item
+ bind:ref
+ class={cn(
+ "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
+ inset && "pl-8",
+ className
+ )}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte
new file mode 100644
index 000000000..9837d5a48
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import { cn } from "$lib/utils.js";
+ import { type WithElementRef } from "bits-ui";
+ import type { HTMLAttributes } from "svelte/elements";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ inset,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
+ inset?: boolean;
+ } = $props();
+</script>
+
+<div
+ bind:this={ref}
+ class={cn("px-2 py-1.5 text-sm font-semibold", inset && "pl-8", className)}
+ {...restProps}
+>
+ {@render children?.()}
+</div>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte
new file mode 100644
index 000000000..bcb960db3
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte
@@ -0,0 +1,30 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive, type WithoutChild } from "bits-ui";
+ import Circle from "@lucide/svelte/icons/circle";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children: childrenProp,
+ ...restProps
+ }: WithoutChild<DropdownMenuPrimitive.RadioItemProps> = $props();
+</script>
+
+<DropdownMenuPrimitive.RadioItem
+ bind:ref
+ class={cn(
+ "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
+ className
+ )}
+ {...restProps}
+>
+ {#snippet children({ checked })}
+ <span class="absolute left-2 flex size-3.5 items-center justify-center">
+ {#if checked}
+ <Circle class="size-2 fill-current" />
+ {/if}
+ </span>
+ {@render childrenProp?.({ checked })}
+ {/snippet}
+</DropdownMenuPrimitive.RadioItem>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte
new file mode 100644
index 000000000..32fac4bc5
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: DropdownMenuPrimitive.SeparatorProps = $props();
+</script>
+
+<DropdownMenuPrimitive.Separator
+ bind:ref
+ class={cn("bg-muted -mx-1 my-1 h-px", className)}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte
new file mode 100644
index 000000000..053e2a2c6
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte
@@ -0,0 +1,20 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import { type WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLSpanElement>> = $props();
+</script>
+
+<span
+ bind:this={ref}
+ class={cn("ml-auto text-xs tracking-widest opacity-60", className)}
+ {...restProps}
+>
+ {@render children?.()}
+</span>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte
new file mode 100644
index 000000000..0bb6eea45
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte
@@ -0,0 +1,19 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: DropdownMenuPrimitive.SubContentProps = $props();
+</script>
+
+<DropdownMenuPrimitive.SubContent
+ bind:ref
+ class={cn(
+ "bg-popover text-popover-foreground z-50 min-w-[8rem] rounded-md border p-1 shadow-lg focus:outline-none",
+ className
+ )}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte
new file mode 100644
index 000000000..be175ad31
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte
@@ -0,0 +1,28 @@
+<script lang="ts">
+ import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+ import ChevronRight from "@lucide/svelte/icons/chevron-right";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ inset,
+ children,
+ ...restProps
+ }: DropdownMenuPrimitive.SubTriggerProps & {
+ inset?: boolean;
+ } = $props();
+</script>
+
+<DropdownMenuPrimitive.SubTrigger
+ bind:ref
+ class={cn(
+ "data-[highlighted]:bg-accent data-[state=open]:bg-accent flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
+ inset && "pl-8",
+ className
+ )}
+ {...restProps}
+>
+ {@render children?.()}
+ <ChevronRight class="ml-auto" />
+</DropdownMenuPrimitive.SubTrigger>
diff --git a/src/lib/components/ui/dropdown-menu/index.ts b/src/lib/components/ui/dropdown-menu/index.ts
new file mode 100644
index 000000000..40c450272
--- /dev/null
+++ b/src/lib/components/ui/dropdown-menu/index.ts
@@ -0,0 +1,50 @@
+import { DropdownMenu as DropdownMenuPrimitive } from "bits-ui";
+import CheckboxItem from "./dropdown-menu-checkbox-item.svelte";
+import Content from "./dropdown-menu-content.svelte";
+import GroupHeading from "./dropdown-menu-group-heading.svelte";
+import Item from "./dropdown-menu-item.svelte";
+import Label from "./dropdown-menu-label.svelte";
+import RadioItem from "./dropdown-menu-radio-item.svelte";
+import Separator from "./dropdown-menu-separator.svelte";
+import Shortcut from "./dropdown-menu-shortcut.svelte";
+import SubContent from "./dropdown-menu-sub-content.svelte";
+import SubTrigger from "./dropdown-menu-sub-trigger.svelte";
+
+const Sub = DropdownMenuPrimitive.Sub;
+const Root = DropdownMenuPrimitive.Root;
+const Trigger = DropdownMenuPrimitive.Trigger;
+const Group = DropdownMenuPrimitive.Group;
+const RadioGroup = DropdownMenuPrimitive.RadioGroup;
+
+export {
+ CheckboxItem,
+ Content,
+ Root as DropdownMenu,
+ CheckboxItem as DropdownMenuCheckboxItem,
+ Content as DropdownMenuContent,
+ Group as DropdownMenuGroup,
+ GroupHeading as DropdownMenuGroupHeading,
+ Item as DropdownMenuItem,
+ Label as DropdownMenuLabel,
+ RadioGroup as DropdownMenuRadioGroup,
+ RadioItem as DropdownMenuRadioItem,
+ Separator as DropdownMenuSeparator,
+ Shortcut as DropdownMenuShortcut,
+ Sub as DropdownMenuSub,
+ SubContent as DropdownMenuSubContent,
+ SubTrigger as DropdownMenuSubTrigger,
+ Trigger as DropdownMenuTrigger,
+ Group,
+ GroupHeading,
+ Item,
+ Label,
+ RadioGroup,
+ RadioItem,
+ Root,
+ Separator,
+ Shortcut,
+ Sub,
+ SubContent,
+ SubTrigger,
+ Trigger,
+};
diff --git a/src/lib/components/ui/table/index.ts b/src/lib/components/ui/table/index.ts
new file mode 100644
index 000000000..14695c815
--- /dev/null
+++ b/src/lib/components/ui/table/index.ts
@@ -0,0 +1,28 @@
+import Root from "./table.svelte";
+import Body from "./table-body.svelte";
+import Caption from "./table-caption.svelte";
+import Cell from "./table-cell.svelte";
+import Footer from "./table-footer.svelte";
+import Head from "./table-head.svelte";
+import Header from "./table-header.svelte";
+import Row from "./table-row.svelte";
+
+export {
+ Root,
+ Body,
+ Caption,
+ Cell,
+ Footer,
+ Head,
+ Header,
+ Row,
+ //
+ Root as Table,
+ Body as TableBody,
+ Caption as TableCaption,
+ Cell as TableCell,
+ Footer as TableFooter,
+ Head as TableHead,
+ Header as TableHeader,
+ Row as TableRow,
+};
diff --git a/src/lib/components/ui/table/table-body.svelte b/src/lib/components/ui/table/table-body.svelte
new file mode 100644
index 000000000..6c20c017a
--- /dev/null
+++ b/src/lib/components/ui/table/table-body.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
+</script>
+
+<tbody bind:this={ref} class={cn("[&_tr:last-child]:border-0", className)} {...restProps}>
+ {@render children?.()}
+</tbody>
diff --git a/src/lib/components/ui/table/table-caption.svelte b/src/lib/components/ui/table/table-caption.svelte
new file mode 100644
index 000000000..2b0cba564
--- /dev/null
+++ b/src/lib/components/ui/table/table-caption.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLElement>> = $props();
+</script>
+
+<caption bind:this={ref} class={cn("text-muted-foreground mt-4 text-sm", className)} {...restProps}>
+ {@render children?.()}
+</caption>
diff --git a/src/lib/components/ui/table/table-cell.svelte b/src/lib/components/ui/table/table-cell.svelte
new file mode 100644
index 000000000..053655286
--- /dev/null
+++ b/src/lib/components/ui/table/table-cell.svelte
@@ -0,0 +1,20 @@
+<script lang="ts">
+ import type { HTMLTdAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLTdAttributes> = $props();
+</script>
+
+<td
+ bind:this={ref}
+ class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
+ {...restProps}
+>
+ {@render children?.()}
+</td>
diff --git a/src/lib/components/ui/table/table-footer.svelte b/src/lib/components/ui/table/table-footer.svelte
new file mode 100644
index 000000000..0267c47e0
--- /dev/null
+++ b/src/lib/components/ui/table/table-footer.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
+</script>
+
+<tfoot bind:this={ref} class={cn("bg-muted/50 font-medium", className)} {...restProps}>
+ {@render children?.()}
+</tfoot>
diff --git a/src/lib/components/ui/table/table-head.svelte b/src/lib/components/ui/table/table-head.svelte
new file mode 100644
index 000000000..5300ce62c
--- /dev/null
+++ b/src/lib/components/ui/table/table-head.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import type { HTMLThAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLThAttributes> = $props();
+</script>
+
+<th
+ bind:this={ref}
+ class={cn(
+ "text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",
+ className
+ )}
+ {...restProps}
+>
+ {@render children?.()}
+</th>
diff --git a/src/lib/components/ui/table/table-header.svelte b/src/lib/components/ui/table/table-header.svelte
new file mode 100644
index 000000000..684a57b16
--- /dev/null
+++ b/src/lib/components/ui/table/table-header.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
+</script>
+
+<thead bind:this={ref} class={cn("[&_tr]:border-b", className)} {...restProps}>
+ {@render children?.()}
+</thead>
diff --git a/src/lib/components/ui/table/table-row.svelte b/src/lib/components/ui/table/table-row.svelte
new file mode 100644
index 000000000..9e693bc1e
--- /dev/null
+++ b/src/lib/components/ui/table/table-row.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLTableRowElement>> = $props();
+</script>
+
+<tr
+ bind:this={ref}
+ class={cn(
+ "hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
+ className
+ )}
+ {...restProps}
+>
+ {@render children?.()}
+</tr>
diff --git a/src/lib/components/ui/table/table.svelte b/src/lib/components/ui/table/table.svelte
new file mode 100644
index 000000000..e3a95b632
--- /dev/null
+++ b/src/lib/components/ui/table/table.svelte
@@ -0,0 +1,18 @@
+<script lang="ts">
+ import type { HTMLTableAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLTableAttributes> = $props();
+</script>
+
+<div class="relative w-full overflow-auto">
+ <table bind:this={ref} class={cn("w-full caption-bottom text-sm", className)} {...restProps}>
+ {@render children?.()}
+ </table>
+</div>
diff --git a/src/lib/types/container.ts b/src/lib/types/container.ts
new file mode 100644
index 000000000..952d2fd16
--- /dev/null
+++ b/src/lib/types/container.ts
@@ -0,0 +1,6 @@
+export type Container = {
+ name: string;
+ id: string;
+ image: string;
+ status: "running" | "stopped" | "failed" | "healthy" | "unhealthy";
+};
diff --git a/src/routes/containers/+page.server.ts b/src/routes/containers/+page.server.ts
index 5b23577a4..64d580293 100644
--- a/src/routes/containers/+page.server.ts
+++ b/src/routes/containers/+page.server.ts
@@ -1,4 +1,5 @@
import type { PageServerLoad } from "./$types";
+import type { Container } from "$lib/types/container";
// This will eventually call your Docker API
export const load: PageServerLoad = async ({ fetch }) => {
@@ -6,12 +7,29 @@ export const load: PageServerLoad = async ({ fetch }) => {
// const response = await fetch('/api/docker/containers');
// const containers = await response.json();
+ const containers: Container[] = [
+ {
+ id: "1a2b3c-11111",
+ name: "1a2b3c",
+ status: "running",
+ image: "nginx:latest",
+ },
+ {
+ id: "1a2b3c-22222",
+ name: "1a2b3c",
+ status: "running",
+ image: "nginx:latest",
+ },
+ {
+ id: "1a2b3c-3333",
+ name: "1a2b3c",
+ status: "running",
+ image: "nginx:latest",
+ },
+ ];
+
// For now, return mock data
return {
- containers: [
- { id: "1a2b3c", name: "web", status: "running", image: "nginx:latest" },
- { id: "4d5e6f", name: "db", status: "exited", image: "postgres:15" },
- { id: "7g8h9i", name: "cache", status: "running", image: "redis:alpine" },
- ],
+ containers,
};
};
diff --git a/src/routes/containers/+page.svelte b/src/routes/containers/+page.svelte
index 20f2ecb3f..f54f8af3c 100644
--- a/src/routes/containers/+page.svelte
+++ b/src/routes/containers/+page.svelte
@@ -1,7 +1,9 @@
<script lang="ts">
+ import DataTable from "$lib/components/data-table.svelte";
import * as Card from "$lib/components/ui/card/index.js";
+ import { columns } from "./columns.js";
- export let data;
+ let { data } = $props();
const { containers } = data;
</script>
@@ -18,56 +20,6 @@
<Card.Description>Manage your Docker containers</Card.Description>
</Card.Header>
<Card.Content>
- <table class="w-full">
- <thead>
- <tr class="border-b">
- <th class="text-left py-2">Name</th>
- <th class="text-left py-2">Image</th>
- <th class="text-left py-2">Status</th>
- <th class="text-left py-2">Actions</th>
- </tr>
- </thead>
- <tbody>
- {#each containers as container}
- <tr class="border-b">
- <td class="py-2">
- <a
- href="/containers/{container.id}"
- class="text-primary hover:underline"
- >
- {container.name}
- </a>
- </td>
- <td>{container.image}</td>
- <td>
- <span
- class={container.status === "running"
- ? "text-green-600"
- : "text-gray-500"}
- >
- {container.status}
- </span>
- </td>
- <td class="flex gap-2 py-2">
- {#if container.status === "running"}
- <button
- class="px-2 py-1 bg-secondary text-secondary-foreground text-xs rounded"
- >Stop</button
- >
- <button
- class="px-2 py-1 bg-secondary text-secondary-foreground text-xs rounded"
- >Restart</button
- >
- {:else}
- <button
- class="px-2 py-1 bg-primary text-primary-foreground text-xs rounded"
- >Start</button
- >
- {/if}
- </td>
- </tr>
- {/each}
- </tbody>
- </table>
+ <DataTable data={containers} {columns} />
</Card.Content>
</Card.Root>
diff --git a/src/routes/containers/columns.ts b/src/routes/containers/columns.ts
new file mode 100644
index 000000000..6f6a30ac7
--- /dev/null
+++ b/src/routes/containers/columns.ts
@@ -0,0 +1,30 @@
+import type { Container } from "$lib/types/container";
+import type { ColumnDef } from "@tanstack/table-core";
+import { renderComponent } from "$lib/components/ui/data-table/index.js";
+import DataTableActions from "$lib/components/data-table-actions.svelte";
+
+export const columns: ColumnDef<Container>[] = [
+ {
+ accessorKey: "name",
+ header: "Name",
+ },
+ {
+ accessorKey: "id",
+ header: "ID",
+ },
+ {
+ accessorKey: "image",
+ header: "Image",
+ },
+ {
+ accessorKey: "status",
+ header: "Status",
+ },
+ {
+ id: "actions",
+ cell: ({ row }) => {
+ // You can pass whatever you need from `row.original` to the component
+ return renderComponent(DataTableActions, { id: row.original.id });
+ },
+ },
+];