ui fixers in 10/16
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"use client"
|
||||
|
||||
import { formatSerialRanges, toSerialRanges } from "@/lib/serial-ranges"
|
||||
|
||||
/**
|
||||
* Serial / warranty numbers shown as From – To ranges instead of one row per unit. A single
|
||||
* run reads inline ("10 serial numbers: SN-001 – SN-010"); several runs expand behind a toggle.
|
||||
*/
|
||||
export function SerialRanges({ label, values }: { label: string; values: string[] }) {
|
||||
const ranges = toSerialRanges(values)
|
||||
if (ranges.length === 0) return null
|
||||
const total = ranges.reduce((n, r) => n + r.count, 0)
|
||||
const heading = `${total} ${label}${total === 1 ? "" : "s"}`
|
||||
|
||||
if (ranges.length <= 2) {
|
||||
return (
|
||||
<p className="break-all">
|
||||
{heading}: <span className="font-mono font-medium text-foreground">{formatSerialRanges(ranges)}</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<details>
|
||||
<summary className="cursor-pointer select-none">
|
||||
{heading} in {ranges.length} ranges: <span className="font-mono text-foreground">{formatSerialRanges(ranges)}</span>
|
||||
</summary>
|
||||
<ul className="mt-1 flex max-h-48 flex-col gap-0.5 overflow-y-auto font-mono">
|
||||
{ranges.map((r) => (
|
||||
<li key={r.from} className="flex justify-between gap-4">
|
||||
<span className="break-all text-foreground">{r.count === 1 ? r.from : `${r.from} – ${r.to}`}</span>
|
||||
<span className="shrink-0 tabular-nums">×{r.count}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user