Skip to content

Commit 77eacf5

Browse files
committed
replacing day prop with date prop
1 parent fd5ea37 commit 77eacf5

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

src/calendar/day/index.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import omit from 'lodash/omit';
21
import PropTypes from 'prop-types';
32
import XDate from 'xdate';
43
import React, {useMemo} from 'react';
@@ -12,21 +11,17 @@ import BasicDay, {BasicDayProps} from './basic';
1211
import PeriodDay from './period';
1312

1413

15-
const basicDayPropsTypes = omit(BasicDay.propTypes, 'date');
16-
17-
export interface DayProps extends Omit<BasicDayProps, 'date'> {
18-
/** The day to render */
19-
day?: string;
14+
export interface DayProps extends BasicDayProps {
2015
/** Provide custom day rendering component */
2116
dayComponent?: React.ComponentType<DayProps & {date?: DateData}>;
2217
}
2318

2419
const Day = (props: DayProps) => {
25-
const {day, marking, dayComponent, markingType} = props;
26-
const _day = day ? new XDate(day) : undefined;
27-
const _isToday = _day ? isToday(_day) : undefined;
20+
const {date, marking, dayComponent, markingType} = props;
21+
const _date = date ? new XDate(date) : undefined;
22+
const _isToday = _date ? isToday(_date) : undefined;
2823

29-
const markingLabel = useMemo(() => {
24+
const markingAccessibilityLabel = useMemo(() => {
3025
let label = '';
3126

3227
if (marking) {
@@ -59,31 +54,25 @@ const Day = (props: DayProps) => {
5954
const today = getDefaultLocale().today || 'today';
6055
const formatAccessibilityLabel = getDefaultLocale().formatAccessibilityLabel || 'dddd d MMMM yyyy';
6156

62-
return `${_isToday ? today : ''} ${_day?.toString(formatAccessibilityLabel)} ${markingLabel}`;
63-
}, [_day, marking, _isToday]);
64-
65-
const dayProps = useMemo(() => {
66-
return omit(props, 'day');
67-
}, [_day]);
57+
return `${_isToday ? today : ''} ${_date?.toString(formatAccessibilityLabel)} ${markingAccessibilityLabel}`;
58+
}, [_date, marking, _isToday]);
6859

6960
const Component = dayComponent || markingType === 'period' ? PeriodDay : BasicDay;
7061

7162
return (
7263
<Component
73-
{...dayProps}
74-
date={day}
64+
{...props}
7565
accessibilityLabel={getAccessibilityLabel}
76-
testID={`${SELECT_DATE_SLOT}-${day}`}
66+
testID={`${SELECT_DATE_SLOT}-${date}`}
7767
>
78-
{formatNumbers(_day?.getDate())}
68+
{formatNumbers(_date?.getDate())}
7969
</Component>
8070
);
8171
};
8272

8373
export default Day;
8474
Day.displayName = 'Day';
8575
Day.propTypes = {
86-
...basicDayPropsTypes,
87-
day: PropTypes.string,
76+
...BasicDay.propTypes,
8877
dayComponent: PropTypes.any
8978
};

src/calendar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Calendar extends Component<CalendarProps, State> {
229229
<View style={this.style.dayContainer} key={id}>
230230
<Day
231231
{...dayProps}
232-
day={toMarkingFormat(day)}
232+
date={toMarkingFormat(day)}
233233
state={getState(day, this.state.currentMonth, this.props)}
234234
marking={markedDates?.[toMarkingFormat(day)]}
235235
onPress={this.pressDay}

src/expandableCalendar/week.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Week extends PureComponent<WeekProps> {
4949
<View style={this.style.dayContainer} key={id}>
5050
<Day
5151
{...dayProps}
52-
day={toMarkingFormat(day)}
52+
date={toMarkingFormat(day)}
5353
state={getState(day, currXdate, this.props)}
5454
marking={markedDates?.[toMarkingFormat(day)]}
5555
onPress={this.props.onDayPress}

0 commit comments

Comments
 (0)