You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.tsx 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. minuteFilter,
  8. handleSelectHour,
  9. handleSelectMinute,
  10. handleSelectPeriod,
  11. }) => {
  12. const { hourOptions, minuteOptions, periodOptions } = useTimeOptions()
  13. return (
  14. <div className='grid grid-cols-3 gap-x-1 p-2'>
  15. {/* Hour */}
  16. <ul className='no-scrollbar flex h-[208px] flex-col gap-y-0.5 overflow-y-auto pb-[184px]'>
  17. {
  18. hourOptions.map((hour) => {
  19. const isSelected = selectedTime?.format('hh') === hour
  20. return (
  21. <OptionListItem
  22. key={hour}
  23. isSelected={isSelected}
  24. onClick={handleSelectHour.bind(null, hour)}
  25. >
  26. {hour}
  27. </OptionListItem>
  28. )
  29. })
  30. }
  31. </ul>
  32. {/* Minute */}
  33. <ul className='no-scrollbar flex h-[208px] flex-col gap-y-0.5 overflow-y-auto pb-[184px]'>
  34. {
  35. (minuteFilter ? minuteFilter(minuteOptions) : minuteOptions).map((minute) => {
  36. const isSelected = selectedTime?.format('mm') === minute
  37. return (
  38. <OptionListItem
  39. key={minute}
  40. isSelected={isSelected}
  41. onClick={handleSelectMinute.bind(null, minute)}
  42. >
  43. {minute}
  44. </OptionListItem>
  45. )
  46. })
  47. }
  48. </ul>
  49. {/* Period */}
  50. <ul className='no-scrollbar flex h-[208px] flex-col gap-y-0.5 overflow-y-auto pb-[184px]'>
  51. {
  52. periodOptions.map((period) => {
  53. const isSelected = selectedTime?.format('A') === period
  54. return (
  55. <OptionListItem
  56. key={period}
  57. isSelected={isSelected}
  58. onClick={handleSelectPeriod.bind(null, period)}
  59. noAutoScroll // if choose PM which would hide(scrolled) AM that may make user confused that there's no am.
  60. >
  61. {period}
  62. </OptionListItem>
  63. )
  64. })
  65. }
  66. </ul>
  67. </div>
  68. )
  69. }
  70. export default React.memo(Options)