Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 70x 44x 130x 32x 70x 70x 70x 174x 44x 70x 27x 44x 70x | <template>
<div class="flex flex-col gap-1.5">
<span v-if="!legend && parts.length > 0" class="sr-only">{{ summary }}</span>
<div v-if="parts.length > 0" class="flex h-1 gap-0.5 bg-muted" aria-hidden="true">
<span
v-for="part in visible"
:key="part.label"
class="h-full"
:class="part.fill"
:style="{ width: `${(part.value / total) * 100}%` }"
/>
</div>
<p v-if="legend && parts.length > 0" class="flex flex-wrap gap-x-3 text-xs text-muted">
<span v-for="part in parts" :key="part.label">
<span class="font-mono text-highlighted">{{ part.value }}</span>
{{ part.label }}
</span>
</p>
</div>
</template>
<script setup lang="ts">
import type { SplitPart } from "~/types/SplitPart";
interface Props {
parts: SplitPart[];
legend?: boolean;
}
const { parts, legend = true } = defineProps<Props>();
const FILL = {
ink: "bg-inverted",
soft: "bg-accented",
good: "tone-good bg-current",
warn: "tone-warn bg-current",
bad: "tone-bad bg-current",
} as const;
const visible = computed(() =>
parts
.filter((part) => part.value > 0)
.map((part) => ({ ...part, fill: FILL[part.tone ?? "ink"] })),
);
const total = computed(() =>
Math.max(
1,
visible.value.reduce((sum, part) => sum + part.value, 0),
),
);
const summary = computed(() => parts.map((part) => `${part.value} ${part.label}`).join(", "));
</script>
|