Skip to content

Commit 60c204b

Browse files
committed
Day - fix date prop's return type for custom datComponent to avoid breaking change
1 parent 0f8f1a9 commit 60c204b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/calendar/day/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, {useMemo} from 'react';
44

55
import {formatNumbers, isToday} from '../../dateutils';
66
import {getDefaultLocale} from '../../services';
7+
import {xdateToData} from '../../interface';
78
// @ts-expect-error
89
import {SELECT_DATE_SLOT} from '../../testIDs';
910
import {DateData} from '../../types';
@@ -13,7 +14,7 @@ import PeriodDay from './period';
1314

1415
export interface DayProps extends BasicDayProps {
1516
/** Provide custom day rendering component */
16-
dayComponent?: React.ComponentType<DayProps & {date?: DateData}>;
17+
dayComponent?: React.ComponentType<DayProps & {date?: DateData}>; // TODO: change 'date' prop type to string by removing it from overriding BasicDay's 'date' prop (breaking change for V2)
1718
}
1819

1920
const Day = React.memo((props: DayProps) => {
@@ -57,13 +58,16 @@ const Day = React.memo((props: DayProps) => {
5758
return `${_isToday ? today : ''} ${_date?.toString(formatAccessibilityLabel)} ${markingAccessibilityLabel}`;
5859
}, [_date, marking, _isToday]);
5960

60-
const Component = dayComponent || markingType === 'period' ? PeriodDay : BasicDay;
61+
const Component = dayComponent || (markingType === 'period' ? PeriodDay : BasicDay);
62+
const dayComponentProps = dayComponent ? {date: xdateToData(date ? new XDate(date) : new XDate())} : undefined;
6163

6264
return (
65+
//@ts-expect-error
6366
<Component
6467
{...props}
6568
accessibilityLabel={getAccessibilityLabel}
6669
testID={`${SELECT_DATE_SLOT}-${date}`}
70+
{...dayComponentProps}
6771
>
6872
{formatNumbers(_date?.getDate())}
6973
</Component>

0 commit comments

Comments
 (0)