All files / src/components YearChoice.tsx

100% Statements 4/4
100% Branches 2/2
100% Functions 3/3
100% Lines 4/4

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                                14x               26x 26x           3x                      
// A choice of years as toggle buttons, newest first, as on the rent
// payments and charges pages.
import Button from '@mui/material/Button'
import Stack from '@mui/material/Stack'
import { TOUCH_TARGET } from '#/theme/theme'
 
interface Props {
  /** The group's accessible name. */
  label: string
  years: readonly number[]
  /** The year shown. */
  year: number
  onYear: (year: number) => void
}
 
export function YearChoice(props: Props) {
  return (
    <Stack
      role="group"
      aria-label={props.label}
      direction="row"
      sx={{ gap: 1, flexWrap: 'wrap' }}
    >
      {props.years.map((option) => {
        const pressed = option === props.year
        return (
          <Button
            key={option}
            variant={pressed ? 'contained' : 'outlined'}
            aria-pressed={pressed}
            onClick={() => {
              props.onYear(option)
            }}
            sx={{ borderRadius: 999, minHeight: TOUCH_TARGET, px: 2.25 }}
          >
            {String(option)}
          </Button>
        )
      })}
    </Stack>
  )
}