Skip to content

Commit 2542da6

Browse files
authored
Merge pull request #1748 from wix/fix/ExpandableCalendarContextType
Fix ExpandableCalendar Context type
2 parents e2472e5 + 72d31a1 commit 2542da6

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

src/expandableCalendar/Context/Presenter.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import XDate from 'xdate';
22

33
import {sameMonth, isToday} from '../../dateutils';
44
import {xdateToData, toMarkingFormat} from '../../interface';
5-
import {UpdateSource} from '../../types';
5+
import {UpdateSources} from '../commons';
66
import {CalendarContextProviderProps} from './Provider';
77

8-
98
const commons = require('../commons');
109
const TOP_POSITION = 65;
1110

@@ -46,7 +45,13 @@ class Presenter {
4645
return icon;
4746
};
4847

49-
setDate = (props: CalendarContextProviderProps, date: string, newDate: string, updateState: (buttonIcon: number) => void, updateSource: UpdateSource) => {
48+
setDate = (
49+
props: CalendarContextProviderProps,
50+
date: string,
51+
newDate: string,
52+
updateState: (buttonIcon: number) => void,
53+
updateSource: UpdateSources
54+
) => {
5055
const isSameMonth = sameMonth(new XDate(date), new XDate(newDate));
5156
const buttonIcon = this.getButtonIcon(date, props.showTodayButton);
5257

@@ -59,7 +64,12 @@ class Presenter {
5964
}
6065
};
6166

62-
setDisabled = (showTodayButton: boolean, newDisabledValue: boolean, oldDisabledValue: boolean, updateState: (disabled: boolean) => void) => {
67+
setDisabled = (
68+
showTodayButton: boolean,
69+
newDisabledValue: boolean,
70+
oldDisabledValue: boolean,
71+
updateState: (disabled: boolean) => void
72+
) => {
6373
if (!showTodayButton || newDisabledValue === oldDisabledValue) {
6474
return;
6575
}

src/expandableCalendar/Context/Provider.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ import React, {Component} from 'react';
55
import {StyleSheet, Animated, TouchableOpacity, View, StyleProp, ViewStyle} from 'react-native';
66

77
import {toMarkingFormat} from '../../interface';
8-
import {Theme, UpdateSource, DateData} from '../../types';
8+
import {Theme, DateData} from '../../types';
99
import styleConstructor from '../style';
1010
import CalendarContext from '.';
1111
import Presenter from './Presenter';
12+
import {UpdateSources} from '../commons';
1213

13-
14-
const commons = require('../commons');
15-
const updateSources = commons.UpdateSources;
1614
const TOP_POSITION = 65;
1715

1816
interface Props {
1917
/** Initial date in 'yyyy-MM-dd' format. Default = now */
2018
date: string;
2119
/** Callback for date change event */
22-
onDateChanged?: (date: string, updateSource: UpdateSource) => void;
20+
onDateChanged?: (date: string, updateSource: UpdateSources) => void;
2321
/** Callback for month change event */
24-
onMonthChange?: (date: DateData, updateSource: UpdateSource) => void;
22+
onMonthChange?: (date: DateData, updateSource: UpdateSources) => void;
2523
/** Whether to show the today button */
2624
showTodayButton?: boolean;
2725
/** Today button's top position */
@@ -62,11 +60,10 @@ class CalendarProvider extends Component<Props> {
6260
style = styleConstructor(this.props.theme);
6361
presenter = new Presenter();
6462

65-
6663
state = {
6764
prevDate: this.getDate(this.props.date),
6865
date: this.getDate(this.props.date),
69-
updateSource: updateSources.CALENDAR_INIT,
66+
updateSource: UpdateSources.CALENDAR_INIT,
7067
buttonY: new Animated.Value(this.props.todayBottomMargin ? -this.props.todayBottomMargin : -TOP_POSITION),
7168
buttonIcon: this.presenter.getButtonIcon(this.getDate(this.props.date), this.props.showTodayButton),
7269
disabled: false,
@@ -75,7 +72,7 @@ class CalendarProvider extends Component<Props> {
7572

7673
componentDidUpdate(prevProps: Props) {
7774
if (this.props.date && prevProps.date !== this.props.date) {
78-
this.setDate(this.props.date, updateSources.PROP_UPDATE);
75+
this.setDate(this.props.date, UpdateSources.PROP_UPDATE);
7976
}
8077
}
8178

@@ -93,7 +90,7 @@ class CalendarProvider extends Component<Props> {
9390
};
9491
};
9592

96-
setDate = (date: string, updateSource: UpdateSource) => {
93+
setDate = (date: string, updateSource: UpdateSources) => {
9794
const {setDate} = this.presenter;
9895

9996
const updateState = (buttonIcon: number) => {
@@ -143,7 +140,7 @@ class CalendarProvider extends Component<Props> {
143140

144141
onTodayPress = () => {
145142
const today = this.presenter.getTodayDate();
146-
this.setDate(today, updateSources.TODAY_PRESS);
143+
this.setDate(today, UpdateSources.TODAY_PRESS);
147144
};
148145

149146
renderTodayButton() {
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
import React from 'react';
2+
import {UpdateSources} from '../commons';
3+
interface CalendarContextProps {
4+
date: string;
5+
prevDate: string;
6+
setDate: (date: string, source: UpdateSources) => void;
7+
updateSource: UpdateSources;
8+
setDisabled: (disable: boolean) => void;
9+
}
210

3-
const CalendarContext = React.createContext({});
11+
// @ts-expect-error
12+
const CalendarContext = React.createContext<CalendarContextProps>({});
413
export default CalendarContext;

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import {ViewStyle, TextStyle, StyleProp} from 'react-native';
2-
import {UpdateSources} from './expandableCalendar/commons';
32

43
export type MarkingTypes = 'dot' | 'multi-dot' | 'period' | 'multi-period' | 'custom';
54
export type DayState = 'selected' | 'disabled' | 'inactive' | 'today' | '';
65
export type Direction = 'left' | 'right';
7-
export type UpdateSource = keyof typeof UpdateSources;
86
export type DateData = {
97
year: number;
108
month: number;

0 commit comments

Comments
 (0)