Khunndev
Sisyphus
Refine the results dock and group panel with a hero total and polished controls.
bb3304c
Raw History Blame Contribute Delete
4.12 kB
import { cn } from '../lib/utils'
import type { DiameterGroup } from '../lib/types'
import { t } from '../lib/i18n'
import type { Lang } from '../lib/types'
interface Props {
lang: Lang
groups: DiameterGroup[]
counts: Record<number, number>
selectedGroupId: number
onSelectGroup: (id: number) => void
onExpectedChange: (groupId: number, value: number | undefined) => void
}
export function GroupPanel({
lang,
groups,
counts,
selectedGroupId,
onSelectGroup,
onExpectedChange,
}: Props) {
return (
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'groups')}</p>
<div className="ct-card overflow-hidden">
{groups.map((g, idx) => {
const count = counts[g.id] ?? 0
const mismatch = g.expected !== undefined && g.expected !== count
const selected = selectedGroupId === g.id
return (
<div key={g.id}>
{idx > 0 && <div className="ml-4 h-px bg-[var(--hairline)]" />}
<button
type="button"
onClick={() => onSelectGroup(g.id)}
className={cn(
'relative flex min-h-[56px] w-full items-center gap-3 px-4 text-left transition-colors duration-150',
selected ? 'bg-[var(--surface-active)]' : 'active:bg-[var(--surface-2)]',
)}
>
{/* selection accent — group's own colour */}
<span
aria-hidden
className="absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full transition-opacity duration-200"
style={{ background: g.color, opacity: selected ? 1 : 0 }}
/>
<span
className="h-3 w-3 shrink-0 rounded-full ring-1 ring-[var(--hairline)] shadow-[inset_0_0_0_1px_rgba(0,0,0,0.08)]"
style={{ background: g.color }}
/>
<span className="flex-1 text-[15px] font-medium text-[var(--text)]">{g.label}</span>
<div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
{mismatch && (
<span
className="ct-badge ct-badge--warning !gap-1 !px-1.5 !py-0.5 !text-[11px]"
title={t(lang, 'mismatch')}
>
<span className="inline-flex h-1.5 w-1.5 rounded-full bg-[var(--warning)]" />
<span className="tabular-nums" style={{ fontFamily: 'var(--font-mono)' }}>
{g.expected}
</span>
</span>
)}
<input
type="number"
inputMode="numeric"
min={0}
placeholder={t(lang, 'expected')}
className="h-8 w-20 rounded-[var(--r-md)] border border-[var(--hairline-strong)] bg-[var(--surface)] px-2.5 text-center text-sm tabular-nums text-[var(--text)] shadow-[var(--shadow-inset)] placeholder:text-[var(--text-faint)] focus:border-[var(--brand)] focus:shadow-none focus:outline-none focus:ring-2 focus:ring-[var(--brand-ring)]"
style={{ fontFamily: 'var(--font-mono)' }}
value={g.expected ?? ''}
onChange={(e) => {
const v = e.target.value
onExpectedChange(g.id, v === '' ? undefined : Number(v))
}}
/>
</div>
<span
className={cn(
'min-w-[2.5rem] text-right text-2xl font-bold leading-none tabular-nums',
mismatch ? 'text-[var(--warning)]' : 'text-[var(--brand)]',
)}
style={{ fontFamily: 'var(--font-mono)' }}
>
{count}
</span>
</button>
</div>
)
})}
</div>
<p className="mt-1.5 px-1 text-[11px] text-[var(--text-faint)]">{t(lang, 'selectGroup')}</p>
</section>
)
}