item.tsx 1000 B

12345678910111213141516171819202122232425262728293031
  1. import React, { type FC } from 'react'
  2. import type { CalendarItemProps } from '../types'
  3. import cn from '@/utils/classnames'
  4. import dayjs from '../utils/dayjs'
  5. const Item: FC<CalendarItemProps> = ({
  6. day,
  7. selectedDate,
  8. onClick,
  9. }) => {
  10. const { date, isCurrentMonth } = day
  11. const isSelected = selectedDate?.isSame(date, 'date')
  12. const isToday = date.isSame(dayjs(), 'date')
  13. return (
  14. <button
  15. onClick={() => onClick(date)}
  16. className={cn(
  17. 'relative px-1 py-2 rounded-lg flex items-center justify-center system-sm-medium',
  18. isCurrentMonth ? 'text-text-secondary' : 'text-text-quaternary hover:text-text-secondary',
  19. isSelected ? 'text-components-button-primary-text system-sm-medium bg-components-button-primary-bg' : 'hover:bg-state-base-hover',
  20. )}
  21. >
  22. {date.date()}
  23. {isToday && <div className='absolute bottom-1 mx-auto w-1 h-1 rounded-full bg-components-button-primary-bg' />}
  24. </button>
  25. )
  26. }
  27. export default React.memo(Item)