mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 08:53:11 +00:00
- Allow horizontal bleed on home-actions retraction shell (overflow-y-hidden instead of overflow-hidden) so -mx-4 is not clipped by the chrome wrapper. - Hide HomeSummaryDelta chip and period caption when delta is 0 or null; add shouldShowHomeSummaryDelta helper and unit pins. Closes #150 Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { formatElectionNumber } from '@/lib/electionFormat'
|
|
|
|
/** B57 — client-safe contract for the Início hero delta (window + copy). */
|
|
export const HOME_SUMMARY_DELTA_WINDOW_DAYS = 7
|
|
|
|
export const homeSummaryDeltaPeriodLabel = `nos últimos ${HOME_SUMMARY_DELTA_WINDOW_DAYS} dias`
|
|
|
|
export type HomeSummaryDeltaDirection = 'up' | 'down' | 'flat' | 'unavailable'
|
|
|
|
export const resolveHomeSummaryDeltaDirection = (
|
|
delta: number | null,
|
|
): HomeSummaryDeltaDirection => {
|
|
if (delta === null) return 'unavailable'
|
|
if (delta === 0) return 'flat'
|
|
return delta > 0 ? 'up' : 'down'
|
|
}
|
|
|
|
/** B111 — render the Δ chip only when there was movement in the window. */
|
|
export const shouldShowHomeSummaryDelta = (delta: number | null): boolean =>
|
|
delta !== null && delta !== 0
|
|
|
|
/** Absolute magnitude for display; null when unavailable; "0" when flat. */
|
|
export const formatHomeSummaryDeltaMagnitude = (delta: number | null): string | null => {
|
|
if (delta === null) return null
|
|
if (delta === 0) return formatElectionNumber(0)
|
|
return formatElectionNumber(Math.abs(delta))
|
|
}
|
|
|
|
export const homeSummaryDeltaAriaLabel = (delta: number | null): string => {
|
|
const period = homeSummaryDeltaPeriodLabel
|
|
if (delta === null) return `Variação ${period} indisponível`
|
|
if (delta === 0) return `Sem variação ${period}`
|
|
const formatted = formatElectionNumber(Math.abs(delta))
|
|
return delta > 0
|
|
? `Aumento de ${formatted} votos ${period}`
|
|
: `Queda de ${formatted} votos ${period}`
|
|
}
|