options.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { type FC } from 'react'
  2. import type { YearAndMonthPickerOptionsProps } from '../types'
  3. import { useMonths, useYearOptions } from '../hooks'
  4. import OptionListItem from '../common/option-list-item'
  5. const Options: FC<YearAndMonthPickerOptionsProps> = ({
  6. selectedMonth,
  7. selectedYear,
  8. handleMonthSelect,
  9. handleYearSelect,
  10. }) => {
  11. const months = useMonths()
  12. const yearOptions = useYearOptions()
  13. return (
  14. <div className='grid grid-cols-2 gap-x-1 p-2'>
  15. {/* Month Picker */}
  16. <ul className='flex flex-col gap-y-0.5 h-[208px] overflow-y-auto no-scrollbar pb-[184px]'>
  17. {
  18. months.map((month, index) => {
  19. const isSelected = selectedMonth === index
  20. return (
  21. <OptionListItem
  22. key={month}
  23. isSelected={isSelected}
  24. onClick={handleMonthSelect.bind(null, index)}
  25. >
  26. {month}
  27. </OptionListItem>
  28. )
  29. })
  30. }
  31. </ul>
  32. {/* Year Picker */}
  33. <ul className='flex flex-col gap-y-0.5 h-[208px] overflow-y-auto no-scrollbar pb-[184px]'>
  34. {
  35. yearOptions.map((year) => {
  36. const isSelected = selectedYear === year
  37. return (
  38. <OptionListItem
  39. key={year}
  40. isSelected={isSelected}
  41. onClick={handleYearSelect.bind(null, year)}
  42. >
  43. {year}
  44. </OptionListItem>
  45. )
  46. })
  47. }
  48. </ul>
  49. </div>
  50. )
  51. }
  52. export default React.memo(Options)