options.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { type FC } from 'react'
  2. import { useTimeOptions } from '../hooks'
  3. import type { TimeOptionsProps } from '../types'
  4. import OptionListItem from '../common/option-list-item'
  5. const Options: FC<TimeOptionsProps> = ({
  6. selectedTime,
  7. handleSelectHour,
  8. handleSelectMinute,
  9. handleSelectPeriod,
  10. }) => {
  11. const { hourOptions, minuteOptions, periodOptions } = useTimeOptions()
  12. return (
  13. <div className='grid grid-cols-3 gap-x-1 p-2'>
  14. {/* Hour */}
  15. <ul className='flex flex-col gap-y-0.5 h-[208px] overflow-y-auto no-scrollbar pb-[184px]'>
  16. {
  17. hourOptions.map((hour) => {
  18. const isSelected = selectedTime?.format('hh') === hour
  19. return (
  20. <OptionListItem
  21. key={hour}
  22. isSelected={isSelected}
  23. onClick={handleSelectHour.bind(null, hour)}
  24. >
  25. {hour}
  26. </OptionListItem>
  27. )
  28. })
  29. }
  30. </ul>
  31. {/* Minute */}
  32. <ul className='flex flex-col gap-y-0.5 h-[208px] overflow-y-auto no-scrollbar pb-[184px]'>
  33. {
  34. minuteOptions.map((minute) => {
  35. const isSelected = selectedTime?.format('mm') === minute
  36. return (
  37. <OptionListItem
  38. key={minute}
  39. isSelected={isSelected}
  40. onClick={handleSelectMinute.bind(null, minute)}
  41. >
  42. {minute}
  43. </OptionListItem>
  44. )
  45. })
  46. }
  47. </ul>
  48. {/* Period */}
  49. <ul className='flex flex-col gap-y-0.5 h-[208px] overflow-y-auto no-scrollbar pb-[184px]'>
  50. {
  51. periodOptions.map((period) => {
  52. const isSelected = selectedTime?.format('A') === period
  53. return (
  54. <OptionListItem
  55. key={period}
  56. isSelected={isSelected}
  57. onClick={handleSelectPeriod.bind(null, period)}
  58. >
  59. {period}
  60. </OptionListItem>
  61. )
  62. })
  63. }
  64. </ul>
  65. </div>
  66. )
  67. }
  68. export default React.memo(Options)