teqo/src/components/campaign/municipality/MunicipalityVotePositionReadout.tsx
Francisco Solla b210939226 refactor(B193): simplify fixes pós-revisão — mapper único de updates, API de trigger uniforme, grupos de relação extraídos, hardening do sheet host
- Extrai toMunicipalityUpdateViewModel/loadUpdateAuthorNames compartilhados
  (feed + batch da lista); remove avatarClassName morto.
- MunicipalityRelationTriggerProps compartilhado nos 3 wrappers; triggerClassName
  no ExpectedVotesControl; ChipLabel/RelationGroup/CityDash no card.
- Sheet host: cleanup de unmount no overlay (sem drawer órfão), registerFooter
  valida open, branch nulo do handleOpenChange limpa footer; chrome freeze
  documentado.
- A11y/UX: ícone de alerta no rodapé frio (WCAG 1.4.1), iniciais de avatar
  aria-hidden, chip sem_base sem target morto, label da cidade com Tendência,
  aria-label da barra anuncia os 3 cenários, card layout 'colocação · votos'.
- E2E: settleStream no B184 (flake da cópia transitória do streaming), cards
  ancorados por hasText (q= casa prefixos), cor da borda via classe do token.
2026-08-10 11:23:49 -03:00

46 lines
1.6 KiB
TypeScript

import {
formatElectionNumber,
formatPlacementOrdinal,
formatVoteSharePercent,
} from '@/lib/electionFormat'
import type { MunicipalityVoteRankEntry } from '@/lib/municipalityVoteRank'
import { cn } from '@/lib/utils'
export type MunicipalityVotePositionReadoutLayout = 'table' | 'card' | 'search'
export const MunicipalityVotePositionReadout = ({
position,
layout,
className,
}: {
position: MunicipalityVoteRankEntry
layout: MunicipalityVotePositionReadoutLayout
/** B193 — the dense mobile card header right-aligns the card layout. */
className?: string
}) => {
const share = formatVoteSharePercent(position.share)
const rank = formatPlacementOrdinal(position.rank)
// B193 — the dense card reads "colocação · votos" per the wireframe; the
// table keeps "votos · colocação" (desktop untouched by B193).
const metaLine =
layout === 'search'
? formatElectionNumber(position.votes)
: layout === 'card'
? `${rank} · ${formatElectionNumber(position.votes)}`
: `${formatElectionNumber(position.votes)} · ${rank}`
const ariaLabel = `${share} da votação estadual, ${formatElectionNumber(position.votes)} votos, ${rank} de ${formatElectionNumber(position.totalUnits)}`
return (
<div
className={cn(
'flex flex-col gap-0.5 tabular-nums',
layout === 'table' || layout === 'search' ? 'items-end text-right' : 'text-sm',
className,
)}
aria-label={ariaLabel}
>
<span className={cn('font-medium', layout === 'card' && 'text-foreground')}>{share}</span>
<span className="text-xs text-muted-foreground">{metaLine}</span>
</div>
)
}