11import { isInRange } from '../utils/dateUtil' ;
22import { GenerateConfig } from '../generate' ;
33import { RangeValue , NullableDateType } from '../interface' ;
4+ import { getValue } from '../utils/miscUtil' ;
45
56export default function useCellClassName < DateType > ( {
67 cellPrefixCls,
78 generateConfig,
89 rangedValue,
910 hoverRangedValue,
11+ isInView,
1012 isSameCell,
13+ offsetCell,
1114 today,
1215 value,
1316} : {
@@ -17,41 +20,60 @@ export default function useCellClassName<DateType>({
1720 current : NullableDateType < DateType > ,
1821 target : NullableDateType < DateType > ,
1922 ) => boolean ;
23+ offsetCell : ( date : DateType , offset : number ) => DateType ;
24+ isInView : ( date : DateType ) => boolean ;
2025 rangedValue ?: RangeValue < DateType > ;
2126 hoverRangedValue ?: RangeValue < DateType > ;
2227 today ?: NullableDateType < DateType > ;
2328 value ?: NullableDateType < DateType > ;
2429} ) {
2530 function getClassName ( currentDate : DateType ) {
31+ const prevDate = offsetCell ( currentDate , - 1 ) ;
32+ const nextDate = offsetCell ( currentDate , 1 ) ;
33+ const isRangeHovered = isInRange (
34+ generateConfig ,
35+ getValue ( hoverRangedValue , 0 ) ,
36+ getValue ( hoverRangedValue , 1 ) ,
37+ currentDate ,
38+ ) ;
39+
40+ function isRangeStart ( date : DateType ) {
41+ return isSameCell ( getValue ( rangedValue , 0 ) , date ) ;
42+ }
43+ function isRangeEnd ( date : DateType ) {
44+ return isSameCell ( getValue ( rangedValue , 1 ) , date ) ;
45+ }
46+ const isHoverStart = isSameCell ( getValue ( hoverRangedValue , 0 ) , currentDate ) ;
47+ const isHoverEnd = isSameCell ( getValue ( hoverRangedValue , 1 ) , currentDate ) ;
48+
2649 return {
50+ // In view
51+ [ `${ cellPrefixCls } -in-view` ] : isInView ( currentDate ) ,
52+
53+ // Range
2754 [ `${ cellPrefixCls } -in-range` ] : isInRange < DateType > (
2855 generateConfig ,
29- rangedValue && rangedValue [ 0 ] ,
30- rangedValue && rangedValue [ 1 ] ,
31- currentDate ,
32- ) ,
33- [ `${ cellPrefixCls } -range-start` ] : isSameCell (
34- rangedValue && rangedValue [ 0 ] ,
35- currentDate ,
36- ) ,
37- [ `${ cellPrefixCls } -range-end` ] : isSameCell (
38- rangedValue && rangedValue [ 1 ] ,
39- currentDate ,
40- ) ,
41- [ `${ cellPrefixCls } -range-hover` ] : isInRange (
42- generateConfig ,
43- hoverRangedValue && hoverRangedValue [ 0 ] ,
44- hoverRangedValue && hoverRangedValue [ 1 ] ,
45- currentDate ,
46- ) ,
47- [ `${ cellPrefixCls } -range-hover-start` ] : isSameCell (
48- hoverRangedValue && hoverRangedValue [ 0 ] ,
49- currentDate ,
50- ) ,
51- [ `${ cellPrefixCls } -range-hover-end` ] : isSameCell (
52- hoverRangedValue && hoverRangedValue [ 1 ] ,
56+ getValue ( rangedValue , 0 ) ,
57+ getValue ( rangedValue , 1 ) ,
5358 currentDate ,
5459 ) ,
60+ [ `${ cellPrefixCls } -range-start` ] : isRangeStart ( currentDate ) ,
61+ [ `${ cellPrefixCls } -range-end` ] : isRangeEnd ( currentDate ) ,
62+
63+ // Range Hover
64+ [ `${ cellPrefixCls } -range-hover` ] : isRangeHovered ,
65+ [ `${ cellPrefixCls } -range-hover-start` ] : isHoverStart ,
66+ [ `${ cellPrefixCls } -range-hover-end` ] : isHoverEnd ,
67+
68+ // Range Edge
69+ [ `${ cellPrefixCls } -range-hover-edge-start` ] :
70+ ( isRangeHovered || isHoverEnd ) &&
71+ ( ! isInView ( prevDate ) || isRangeEnd ( prevDate ) ) ,
72+ [ `${ cellPrefixCls } -range-hover-edge-end` ] :
73+ ( isRangeHovered || isHoverStart ) &&
74+ ( ! isInView ( nextDate ) || isRangeStart ( nextDate ) ) ,
75+
76+ // Others
5577 [ `${ cellPrefixCls } -today` ] : isSameCell ( today , currentDate ) ,
5678 [ `${ cellPrefixCls } -selected` ] : isSameCell ( value , currentDate ) ,
5779 } ;
0 commit comments