Files
archie/ui/src/base/StatTile.vue
T
sam 3d20dde9cb feat(webui): port the shared primitives (Phase 2)
The Preact tree's ui/src/base/ was deleted with the dashboard. This rebuilds
what depended on it, on the shadcn layer rather than as new bespoke markup.

Badge and Card come from the shadcn-vue CLI, so they match the already-vendored
components, and the composed pieces sit on top of them:

- Badge gains the five status variants the pills used, over the palette's status
  tokens. The pill's dot did not come across: the Badge's own shape is the
  affordance, and the same variant now covers a trend indicator, where a dot
  reads as noise.
- base/StatTile.vue uses full Card composition instead of dumping everything
  into one content slot, with base/Sparkline.vue and the goodDirection logic
  that says whether "up" is good news.
- base/Gauge.vue and base/SegmentBar.vue, both of them: the original exported
  two components from one file and budget composition uses the second.
- base/LogRow.vue over lib/log.ts, which holds the LOG_LEVELS wire contract
  (the server matches that CSV server-side, so it is not a display choice).
- lib/status.ts, so status colour has one home: a task state, a gate result, a
  log level and a trend all draw from the same five kinds.

Two deliberate departures:

The icon module is not ported. Its name-to-glyph string lookup is the pattern
shadcn-vue's rules call out as wrong, and nothing consumes the five bespoke
glyphs anyway: the navigation is text with tooltips. Icons come from @lucide/vue
at the call site, and the five become components if a page draws them.

The gauge's aria-label announces the rounded percentage. It announced the raw
one, so a screen reader read 71.38461538461539% where the screen showed 71%
(bead 86au).

Also lands the four modules the checklist marks copy-verbatim, which encode
bugs fixed just before the delete: dashboard/activity-detail, chat/
command-scroll, workflows/workflow-rows and logs/logs-empty.
2026-09-20 19:38:17 +10:00

64 lines
2.2 KiB
Vue

<script setup lang="ts">
import { TrendingDown, TrendingUp } from "@lucide/vue";
import { computed } from "vue";
import { Badge } from "@/components/ui/badge";
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import Sparkline from "./Sparkline.vue";
/**
* A KPI tile: label, big value, trend against a stated comparison window, and
* a sparkline. The comparison line is not decoration -- a number without a
* baseline cannot be acted on, so `compare` is required.
*
* trend > 0 renders as an increase. `goodDirection` says whether that is good,
* because rising latency and rising success rate are not the same news.
*
* The headline value is rendered whatever its type, including 0 and "": a tile
* that showed a label and a comparison line with no number above them read as
* a broken dashboard on every fresh install.
*/
const props = withDefaults(
defineProps<{
label: string;
value: string | number;
unit?: string;
trend?: number | null;
compare: string;
series?: number[];
goodDirection?: "up" | "down";
}>(),
{ series: () => [], goodDirection: "up" },
);
const dir = computed(() => (props.trend == null ? null : props.trend >= 0 ? "up" : "down"));
const good = computed(() => (dir.value == null ? null : dir.value === props.goodDirection));
const trendIcon = computed(() => (dir.value === "up" ? TrendingUp : TrendingDown));
const trendLabel = computed(() => `${Math.abs(props.trend ?? 0).toFixed(1)}%`);
</script>
<template>
<Card>
<CardHeader>
<CardTitle>{{ props.label }}</CardTitle>
<CardDescription v-if="props.compare">{{ props.compare }}</CardDescription>
<CardAction v-if="dir">
<Badge :variant="good ? 'ok' : 'danger'">
<component :is="trendIcon" />
{{ trendLabel }}
</Badge>
</CardAction>
</CardHeader>
<CardContent>
<div class="text-3xl font-semibold tracking-[-0.03em]">
{{ props.value }}<span v-if="props.unit" class="ml-1 text-lg text-fg-muted">{{ props.unit }}</span>
</div>
<Sparkline
v-if="props.series.length > 1"
:series="props.series"
:stroke="good === false ? 'var(--danger)' : 'var(--ok)'"
/>
</CardContent>
</Card>
</template>