Skip to content

Modern Docker Management, Designed for Everyone

fix: use new status badge instead of custom-badge

Kyle Mendell90303a64a749
diff --git a/src/lib/components/badges/custom-badge.svelte b/src/lib/components/badges/custom-badge.svelte
deleted file mode 100644
index 3a13b2eef..000000000
--- a/src/lib/components/badges/custom-badge.svelte
+++ /dev/null
@@ -1,226 +0,0 @@
-<script lang="ts">
- import type { Icon as IconType } from "@lucide/svelte";
-
- let {
- variant = "default",
- text = "",
- bgColor = undefined,
- textColor = undefined,
- size = "default",
- rounded = true,
- className = "",
- icon = undefined,
- iconClass = "w-3.5 h-3.5 mr-1",
- statusVariant = undefined,
- }: {
- variant?: "default" | "secondary" | "destructive" | "outline" | "status";
- text: string;
- bgColor?: string;
- textColor?: string;
- size?: "default" | "sm" | "lg";
- rounded?: boolean;
- className?: string;
- icon?: typeof IconType;
- iconClass?: string;
- statusVariant?: "green" | "amber" | "red" | "blue" | "gray" | "purple";
- } = $props();
-
- // Map variant to style variables
- function getVariantStyles() {
- const variants = {
- default: {
- bg: "var(--primary)",
- color: "var(--primary-foreground)",
- border: "var(--primary)",
- },
- secondary: {
- bg: "var(--secondary)",
- color: "var(--secondary-foreground)",
- border: "var(--secondary)",
- },
- destructive: {
- bg: "var(--destructive)",
- color: "var(--destructive-foreground)",
- border: "var(--destructive)",
- },
- outline: {
- bg: "transparent",
- color: "var(--foreground)",
- border: "var(--border)",
- },
- status: {
- bg: "transparent",
- color: "var(--foreground)",
- border: "transparent",
- },
- };
-
- return variants[variant];
- }
-
- // Extended color map for all badge types
- function getCustomStyles() {
- const colorMap: Record<string, string> = {
- // Backgrounds
- "amber-100": "rgb(254 243 199)",
- "green-100": "rgb(220 252 231)",
- "red-100": "rgb(254 226 226)",
- "blue-100": "rgb(219 234 254)",
- "gray-100": "rgb(243 244 246)",
- "purple-100": "rgb(237 233 254)",
- "indigo-100": "rgb(224 231 255)",
-
- // Text colors (darker variants)
- "amber-900": "rgb(120 53 15)",
- "green-900": "rgb(20 83 45)",
- "red-900": "rgb(127 29 29)",
- "blue-900": "rgb(30 58 138)",
- "gray-900": "rgb(17 24 39)",
- "purple-900": "rgb(88 28 135)",
- "indigo-900": "rgb(49 46 129)",
-
- // Basic colors
- black: "rgb(0 0 0)",
- white: "rgb(255 255 255)",
-
- // Status colors
- running: "rgb(34 197 94)", // green-500
- partially: "rgb(245 158 11)", // amber-500
- stopped: "rgb(156 163 175)", // gray-400
- error: "rgb(239 68 68)", // red-500
- };
-
- const style = {
- bg: bgColor && bgColor in colorMap ? colorMap[bgColor] : undefined,
- color:
- textColor && textColor in colorMap ? colorMap[textColor] : undefined,
- border: bgColor && bgColor in colorMap ? colorMap[bgColor] : undefined,
- };
-
- return style;
- }
-
- // Add status presets for common status badges
- function applyStatusPreset(): {
- bg?: string;
- color?: string;
- border?: string;
- } {
- if (variant !== "status") return {};
-
- // Define color schemes for each status variant
- const variantStyles = {
- green: {
- bg: "rgba(34, 197, 94, 0.2)",
- color: "rgb(63, 185, 80)",
- border: "rgba(34, 197, 94, 0.2)",
- },
- amber: {
- bg: "rgba(234, 179, 8, 0.2)",
- color: "rgb(210, 153, 34)",
- border: "rgba(234, 179, 8, 0.2)",
- },
- red: {
- bg: "rgba(239, 68, 68, 0.15)",
- color: "rgb(185, 28, 28)",
- border: "rgba(239, 68, 68, 0.15)",
- },
- blue: {
- bg: "rgba(59, 130, 246, 0.15)",
- color: "rgb(37, 99, 235)",
- border: "rgba(59, 130, 246, 0.15)",
- },
- gray: {
- bg: "rgba(156, 163, 175, 0.15)",
- color: "rgb(75, 85, 99)",
- border: "rgba(156, 163, 175, 0.15)",
- },
- purple: {
- bg: "rgba(139, 92, 246, 0.15)",
- color: "rgb(107, 33, 168)",
- border: "rgba(139, 92, 246, 0.15)",
- },
- };
-
- // Map common status texts to variants for backward compatibility
- const statusToVariantMap: Record<string, keyof typeof variantStyles> = {
- running: "green",
- "in use": "green",
- managed: "green",
- unused: "amber",
- partially: "amber",
- "partially running": "amber",
- restarting: "amber",
- warning: "amber",
- error: "red",
- exited: "red",
- dead: "red",
- failed: "red",
- pending: "blue",
- creating: "blue",
- stopped: "gray",
- paused: "gray",
- external: "purple",
- };
-
- // If direct status variant is provided, use it
- if (statusVariant && statusVariant in variantStyles) {
- return variantStyles[statusVariant];
- }
-
- // Otherwise try to infer from text (backward compatibility)
- if (text) {
- const lowerText = text.toLowerCase();
-
- // Check for exact matches in our map
- if (lowerText in statusToVariantMap) {
- return variantStyles[statusToVariantMap[lowerText]];
- }
-
- // Check for partial matches
- for (const [key, variant] of Object.entries(statusToVariantMap)) {
- if (lowerText.includes(key)) {
- return variantStyles[variant];
- }
- }
- }
-
- // Default to blue if no match found
- return variantStyles.blue;
- }
-
- // Combine variant and custom styles
- const baseStyles = $derived(getVariantStyles());
- const customStyles = $derived(getCustomStyles());
- const statusStyles = $derived(applyStatusPreset());
-
- const style = $derived(
- [
- `background-color: ${customStyles.bg || statusStyles.bg || baseStyles.bg};`,
- `color: ${customStyles.color || statusStyles.color || baseStyles.color};`,
- `border: 1px solid ${customStyles.border || statusStyles.border || baseStyles.border};`,
- ].join(" ")
- );
-
- // Size classes
- const sizeClass = $derived(
- size === "sm"
- ? "text-xs py-0 px-2"
- : size === "lg"
- ? "text-sm py-1 px-3"
- : "text-xs py-0.5 px-2.5"
- );
-
- const roundedClass = $derived(rounded ? "rounded-full" : "rounded-md");
-</script>
-
-<span
- class={`inline-flex items-center font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${sizeClass} ${roundedClass} ${className}`}
- {style}
->
- {#if icon}
- {@const Icon = icon}
- <Icon class={iconClass} />
- {/if}
- {text}
-</span>
diff --git a/src/lib/components/badges/status-badge.svelte b/src/lib/components/badges/status-badge.svelte
new file mode 100644
index 000000000..33eb40fdd
--- /dev/null
+++ b/src/lib/components/badges/status-badge.svelte
@@ -0,0 +1,44 @@
+<script lang="ts">
+ interface Props {
+ text: string;
+ // Updated variant list
+ variant?: "red" | "purple" | "green" | "blue" | "gray" | "amber";
+ }
+
+ let { text, variant = "gray" }: Props = $props();
+
+ // Updated variant classes based on provided RGBA values and Tailwind colors (dark mode removed)
+ let variantClasses = $derived(
+ {
+ // red: bg: rgba(239, 68, 68, 0.15), color: rgb(185, 28, 28), border: rgba(239, 68, 68, 0.15)
+ // Closest Tailwind: bg-red-500/15, text-red-700, border-red-700
+ red: "bg-red-500/15 text-red-700 border border-red-700/20",
+
+ // purple: bg: rgba(139, 92, 246, 0.15), color: rgb(107, 33, 168), border: rgba(139, 92, 246, 0.15)
+ // Closest Tailwind: bg-purple-500/15, text-purple-700, border-purple-700
+ purple: "bg-purple-500/15 text-purple-700 border border-purple-700/20",
+
+ // green: bg: rgba(34, 197, 94, 0.2), color: rgb(63, 185, 80), border: rgba(34, 197, 94, 0.2)
+ // Closest Tailwind: bg-green-500/20, text-green-600, border-green-600
+ green: "bg-green-500/20 text-green-600 border border-green-600/20",
+
+ // blue: bg: rgba(59, 130, 246, 0.15), color: rgb(37, 99, 235), border: rgba(59, 130, 246, 0.15)
+ // Closest Tailwind: bg-blue-500/15, text-blue-700, border-blue-700
+ blue: "bg-blue-500/15 text-blue-700 border border-blue-700/20",
+
+ // gray: bg: rgba(156, 163, 175, 0.15), color: rgb(75, 85, 99), border: rgba(156, 163, 175, 0.15)
+ // Closest Tailwind: bg-gray-400/15, text-gray-600, border-gray-600
+ gray: "bg-gray-400/15 text-gray-600 border border-gray-600-20",
+
+ // amber: bg: rgba(234, 179, 8, 0.2), color: rgb(210, 153, 34), border: rgba(234, 179, 8, 0.2)
+ // Closest Tailwind: bg-amber-500/20, text-amber-600, border-amber-600
+ amber: "bg-amber-500/20 text-amber-600 border border-amber-600/20",
+ }[variant]
+ );
+</script>
+
+<span
+ class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {variantClasses}"
+>
+ {text}
+</span>
diff --git a/src/lib/components/badges/unused-text-badge.svelte b/src/lib/components/badges/unused-text-badge.svelte
index 5f3d63d5b..4e9b6f6b9 100644
--- a/src/lib/components/badges/unused-text-badge.svelte
+++ b/src/lib/components/badges/unused-text-badge.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
- import CustomBadge from "$lib/components/badges/custom-badge.svelte";
+ import StatusBadge from "./status-badge.svelte";
export let name: string;
export let inUse: boolean | undefined;
@@ -8,6 +8,6 @@
<div class="flex items-center gap-2">
<span class="truncate">{name}</span>
{#if !inUse}
- <CustomBadge variant="status" text="Unused" className="ml-2" />
+ <StatusBadge text="Unused" variant="amber" />
{/if}
</div>
diff --git a/src/lib/components/navbar.svelte b/src/lib/components/navbar.svelte
index b608a9909..a982cfe5a 100644
--- a/src/lib/components/navbar.svelte
+++ b/src/lib/components/navbar.svelte
@@ -17,7 +17,6 @@
import { page } from "$app/stores";
import { fly } from "svelte/transition";
import { Button } from "$lib/components/ui/button/index.js";
- import { Badge } from "$lib/components/ui/badge/index.js";
import { Separator } from "$lib/components/ui/separator/index.js";
import { cn } from "$lib/utils";
import { browser } from "$app/environment";
@@ -45,7 +44,6 @@
href: string;
label: string;
icon: typeof IconType;
- badge?: string;
};
// State for mobile sidebar
@@ -198,15 +196,9 @@
</div>
{#if !isCollapsed}
- {#if item.badge}
- <Badge variant="outline" class="text-xs">{item.badge}</Badge>
- {:else if isActive}
+ {#if isActive}
<ChevronRight size={16} class="text-primary opacity-60" />
{/if}
- {:else if item.badge}
- <Badge variant="outline" class="text-xs mt-1 px-1.5"
- >{item.badge}</Badge
- >
{/if}
</a>
{/each}
diff --git a/src/lib/types/statuses.ts b/src/lib/types/statuses.ts
index 3f9642e1b..312b68536 100644
--- a/src/lib/types/statuses.ts
+++ b/src/lib/types/statuses.ts
@@ -1,26 +1,13 @@
-export const statusConfig = {
- running: {
- bgColor: "rgba(34, 197, 94, 0.2)",
- textColor: "rgb(21, 128, 61)",
- },
- created: {
- bgColor: "rgba(59, 130, 246, 0.15)",
- textColor: "rgb(37, 99, 235)",
- },
- restarting: {
- bgColor: "rgba(245, 158, 11, 0.15)",
- textColor: "rgb(180, 83, 9)",
- },
- exited: {
- bgColor: "rgba(156, 163, 175, 0.15)",
- textColor: "rgb(75, 85, 99)",
- },
- paused: {
- bgColor: "rgba(156, 163, 175, 0.15)",
- textColor: "rgb(75, 85, 99)",
- },
- dead: {
- bgColor: "rgba(239, 68, 68, 0.15)",
- textColor: "rgb(185, 28, 28)",
- },
+export const statusVariantMap: Record<
+ string,
+ "red" | "purple" | "green" | "blue" | "gray" | "amber"
+> = {
+ running: "green",
+ deployed: "green",
+ stopped: "red",
+ failed: "red",
+ pending: "amber",
+ creating: "blue",
+ updating: "blue",
+ deleting: "purple",
};
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index f73f5b52e..2f59459a0 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -36,22 +36,6 @@ export const capitalizeFirstLetter = (text: string) => {
return text.charAt(0).toUpperCase() + text.slice(1);
};
-export function getStatusColor(status: string): { bg: string; text: string } {
- const statusLower = status.toLowerCase();
-
- if (statusLower === "running") {
- return { bg: "green-100", text: "green-900" };
- } else if (statusLower === "created" || statusLower === "restarting") {
- return { bg: "blue-100", text: "blue-900" };
- } else if (statusLower === "paused") {
- return { bg: "amber-100", text: "amber-900" };
- } else if (statusLower === "exited" || statusLower === "dead") {
- return { bg: "red-100", text: "red-900" };
- } else {
- return { bg: "gray-100", text: "gray-900" }; // Default for unknown status
- }
-}
-
export function formatDate(dateString: string | undefined | null): string {
if (!dateString) return "Unknown";
try {
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index c8491a28f..0e2bec90d 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -19,6 +19,7 @@
import { Progress } from "$lib/components/ui/progress/index.js";
import { Badge } from "$lib/components/ui/badge/index.js";
import { formatBytes } from "$lib/utils";
+ import StatusBadge from "$lib/components/badges/status-badge.svelte";
let { data }: { data: PageData } = $props();
const { dockerInfo, containers, images, error } = data;
@@ -73,9 +74,10 @@
<div class="flex items-center justify-between mb-4">
<h2 class="text-lg font-semibold tracking-tight">Engine Overview</h2>
{#if dockerInfo}
- <Badge variant="outline" class="text-xs font-normal">
- v{dockerInfo.ServerVersion || "Unknown"}
- </Badge>
+ <StatusBadge
+ variant="gray"
+ text="v{dockerInfo.ServerVersion || 'Unknown'}"
+ />
{/if}
</div>
@@ -182,7 +184,7 @@
>
<PlayCircle class="h-4 w-4 mr-2" />
Start All Stopped
- <Badge variant="secondary" class="ml-2">{stoppedContainers}</Badge>
+ <StatusBadge variant="amber" text={stoppedContainers.toString()} />
</Button>
<p class="text-xs text-muted-foreground mt-2">
Start all stopped containers
@@ -197,7 +199,7 @@
>
<StopCircle class="h-4 w-4 mr-2" />
Stop All Running
- <Badge variant="outline" class="ml-2">{runningContainers}</Badge>
+ <StatusBadge variant="amber" text={runningContainers.toString()} />
</Button>
<p class="text-xs text-muted-foreground mt-2">
Stop all running containers
diff --git a/src/routes/columns.ts b/src/routes/columns.ts
index b47472a07..7df63fb0f 100644
--- a/src/routes/columns.ts
+++ b/src/routes/columns.ts
@@ -4,10 +4,10 @@ import type {
ServiceImage,
} from "$lib/services/docker-service";
import { formatBytes } from "$lib/utils";
-import CustomBadge from "$lib/components/badges/custom-badge.svelte";
import { capitalizeFirstLetter } from "$lib/utils";
-import { statusConfig } from "$lib/types/statuses";
+import { statusVariantMap } from "$lib/types/statuses";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
+import StatusBadge from "$lib/components/badges/status-badge.svelte";
// Column definitions for the dashboard containers table
export const dashboardContainerColumns: ColumnDef<ServiceContainer>[] = [
@@ -25,18 +25,12 @@ export const dashboardContainerColumns: ColumnDef<ServiceContainer>[] = [
accessorKey: "state",
header: "Status",
cell: ({ row }) => {
- const config = statusConfig[
- row.getValue("state") as keyof typeof statusConfig
- ] || {
- bgColor: "blue-100",
- textColor: "blue-900",
- };
+ const variant =
+ statusVariantMap[row.original.state.toLowerCase()] || "gray";
- return renderComponent(CustomBadge, {
- variant: "status",
- rounded: true,
- text: capitalizeFirstLetter(row.getValue("state") as string),
- ...config,
+ return renderComponent(StatusBadge, {
+ variant: variant,
+ text: capitalizeFirstLetter(row.original.state),
});
},
},
diff --git a/src/routes/containers/[id]/+page.svelte b/src/routes/containers/[id]/+page.svelte
index 62438c201..c1bdb1ec9 100644
--- a/src/routes/containers/[id]/+page.svelte
+++ b/src/routes/containers/[id]/+page.svelte
@@ -18,13 +18,7 @@
import { Separator } from "$lib/components/ui/separator/index.js";
import { Badge } from "$lib/components/ui/badge/index.js";
import ActionButtons from "$lib/components/action-buttons.svelte";
- import CustomBadge from "$lib/components/badges/custom-badge.svelte";
- import {
- capitalizeFirstLetter,
- getStatusColor,
- formatDate,
- formatLogLine,
- } from "$lib/utils";
+ import { formatDate, formatLogLine } from "$lib/utils";
let { data, form }: { data: PageData; form: ActionData } = $props();
let { container, logs } = $derived(data);
diff --git a/src/routes/containers/columns.ts b/src/routes/containers/columns.ts
index abf48b5cc..e014e65be 100644
--- a/src/routes/containers/columns.ts
+++ b/src/routes/containers/columns.ts
@@ -3,10 +3,10 @@ import type { ColumnDef } from "@tanstack/table-core";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
import DataTableActions from "./ContainerActions.svelte";
import { capitalizeFirstLetter } from "$lib/utils";
-import { statusConfig } from "$lib/types/statuses";
-import CustomBadge from "$lib/components/badges/custom-badge.svelte";
import IdCell from "./components/IdCell.svelte";
import CellName from "./components/NameCell.svelte";
+import StatusBadge from "$lib/components/badges/status-badge.svelte";
+import { statusVariantMap } from "$lib/types/statuses";
export const columns: ColumnDef<ServiceContainer>[] = [
{
@@ -35,18 +35,12 @@ export const columns: ColumnDef<ServiceContainer>[] = [
accessorKey: "state",
header: "Status",
cell: ({ row }) => {
- const config = statusConfig[
- row.getValue("state") as keyof typeof statusConfig
- ] || {
- bgColor: "blue-100",
- textColor: "blue-900",
- };
+ const variant =
+ statusVariantMap[row.original.state.toLowerCase()] || "gray";
- return renderComponent(CustomBadge, {
- variant: "status",
- rounded: true,
- text: capitalizeFirstLetter(row.getValue("state") as string),
- ...config,
+ return renderComponent(StatusBadge, {
+ variant: variant,
+ text: capitalizeFirstLetter(row.original.state),
});
},
},
diff --git a/src/routes/stacks/[stackId]/+page.svelte b/src/routes/stacks/[stackId]/+page.svelte
index 168eabe51..18c00fab2 100644
--- a/src/routes/stacks/[stackId]/+page.svelte
+++ b/src/routes/stacks/[stackId]/+page.svelte
@@ -19,8 +19,9 @@
import YamlEditor from "$lib/components/yaml-editor.svelte";
import { onMount } from "svelte";
import ActionButtons from "$lib/components/action-buttons.svelte";
- import CustomBadge from "$lib/components/badges/custom-badge.svelte";
- import { capitalizeFirstLetter, getStatusColor } from "$lib/utils";
+ import StatusBadge from "$lib/components/badges/status-badge.svelte";
+ import { statusVariantMap } from "$lib/types/statuses";
+ import { capitalizeFirstLetter } from "$lib/utils";
let { data, form }: { data: PageData; form: ActionData } = $props();
let { stack } = $derived(data);
@@ -272,6 +273,9 @@
<div class="space-y-2">
{#if stack.services && stack.services.length > 0}
{#each stack.services as service}
+ {@const status = service.state?.Status || "unknown"}
+ {@const variant =
+ statusVariantMap[status.toLowerCase()] || "gray"}
<a
href={service.id ? `/containers/${service.id}` : undefined}
class={`flex items-center justify-between p-3 border rounded-md ${
@@ -292,17 +296,7 @@
</div>
</div>
<div class="flex items-center gap-2">
- <CustomBadge
- variant="status"
- text={capitalizeFirstLetter(
- service.state?.Status || "unknown"
- )}
- bgColor={getStatusColor(service.state?.Status || "unknown")
- .bg}
- textColor={getStatusColor(
- service.state?.Status || "unknown"
- ).text}
- />
+ <StatusBadge {variant} text={capitalizeFirstLetter(status)} />
{#if service.id}
<div class="text-xs text-blue-500 ml-2">
<span class="hidden sm:inline">View details</span>
diff --git a/src/routes/stacks/columns.ts b/src/routes/stacks/columns.ts
index fd91c79e6..1a657338e 100644
--- a/src/routes/stacks/columns.ts
+++ b/src/routes/stacks/columns.ts
@@ -4,9 +4,9 @@ import { renderComponent } from "$lib/components/ui/data-table/index.js";
import StackActions from "./StackActions.svelte";
import StackNameCell from "./StackNameCell.svelte";
import StackDateCell from "./StackDateCell.svelte";
-import CustomBadge from "$lib/components/badges/custom-badge.svelte";
+import StatusBadge from "$lib/components/badges/status-badge.svelte";
import { capitalizeFirstLetter } from "$lib/utils";
-import { statusConfig } from "$lib/types/statuses";
+import { statusVariantMap } from "$lib/types/statuses";
export const columns: ColumnDef<Stack>[] = [
{
@@ -27,18 +27,12 @@ export const columns: ColumnDef<Stack>[] = [
accessorKey: "status",
header: "Status",
cell: ({ row }) => {
- const status = row.getValue("status");
+ const status = row.getValue("status") as string;
+ const variant = statusVariantMap[status.toLowerCase()] || "gray";
- const config = statusConfig[status as keyof typeof statusConfig] || {
- bgColor: "blue-100",
- textColor: "blue-900",
- };
-
- return renderComponent(CustomBadge, {
- variant: "status",
- rounded: true,
- text: capitalizeFirstLetter(status as string),
- ...config,
+ return renderComponent(StatusBadge, {
+ variant: variant,
+ text: capitalizeFirstLetter(status),
});
},
},
@@ -56,11 +50,8 @@ export const columns: ColumnDef<Stack>[] = [
accessorKey: "isExternal",
cell: ({ row }) => {
const isExternal = row.getValue("isExternal");
- return renderComponent(CustomBadge, {
- variant: "outline",
- rounded: true,
- bgColor: isExternal ? "amber-100" : "indigo-100",
- textColor: isExternal ? "amber-900" : "indigo-900",
+ return renderComponent(StatusBadge, {
+ variant: isExternal ? "amber" : "green",
text: isExternal ? "External" : "Managed",
});
},
diff --git a/src/routes/volumes/columns.ts b/src/routes/volumes/columns.ts
index 9089d7505..8cb883491 100644
--- a/src/routes/volumes/columns.ts
+++ b/src/routes/volumes/columns.ts
@@ -2,7 +2,6 @@ import type { ColumnDef } from "@tanstack/table-core";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
import VolumeActions from "./VolumeActions.svelte";
import MountpointCell from "./MountpointCell.svelte";
-import CustomBadge from "$lib/components/badges/custom-badge.svelte";
import type { ServiceVolume } from "$lib/services/docker-service";
import UnusedTextBadge from "$lib/components/badges/unused-text-badge.svelte";