33 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-19 10:56:18 +08:00
import React, { type FC } from 'react'
import type { CalendarItemProps } from '../types'
import cn from '@/utils/classnames'
import dayjs from '../utils/dayjs'
2025-02-19 10:56:18 +08:00
const Item: FC<CalendarItemProps> = ({
day,
selectedDate,
onClick,
isDisabled,
2025-02-19 10:56:18 +08:00
}) => {
const { date, isCurrentMonth } = day
const isSelected = selectedDate?.isSame(date, 'date')
const isToday = date.isSame(dayjs(), 'date')
return (
<button type="button"
onClick={() => !isDisabled && onClick(date)}
2025-02-19 10:56:18 +08:00
className={cn(
'system-sm-medium relative flex items-center justify-center rounded-lg px-1 py-2',
2025-02-19 10:56:18 +08:00
isCurrentMonth ? 'text-text-secondary' : 'text-text-quaternary hover:text-text-secondary',
isSelected ? 'system-sm-medium bg-components-button-primary-bg text-components-button-primary-text' : 'hover:bg-state-base-hover',
isDisabled && 'cursor-not-allowed text-text-quaternary hover:bg-transparent',
2025-02-19 10:56:18 +08:00
)}
>
{date.date()}
{isToday && <div className='absolute bottom-1 mx-auto h-1 w-1 rounded-full bg-components-button-primary-bg' />}
2025-02-19 10:56:18 +08:00
</button>
)
}
export default React.memo(Item)