Skip to content

Commit

Permalink
feature: support for custom header component- issue wix#745
Browse files Browse the repository at this point in the history
  • Loading branch information
varunkumar2 committed Feb 22, 2019
1 parent 548e5fa commit 037f4f6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ class Calendar extends Component {
// Handler which gets executed when press arrow icon left. It receive a callback can go back month
onPressArrowLeft: PropTypes.func,
// Handler which gets executed when press arrow icon left. It receive a callback can go next month
onPressArrowRight: PropTypes.func
onPressArrowRight: PropTypes.func,
// Provide custom calendar header rendering component
calendarHeaderComponent: PropTypes.any,
// data which is passed to calendar header, useful only when implementing custom calendar header
headerData: PropTypes.object
};

constructor(props) {
Expand Down Expand Up @@ -237,6 +241,14 @@ class Calendar extends Component {
return (<View style={this.style.week} key={id}>{week}</View>);
}

getCalendarHeaderComponent() {
if (this.props.calendarHeaderComponent) {
return this.props.calendarHeaderComponent;
}

return CalendarHeader;
}

render() {
const days = dateutils.page(this.state.currentMonth, this.props.firstDay);
const weeks = [];
Expand All @@ -252,6 +264,8 @@ class Calendar extends Component {
indicator = true;
}
}
const CalendarHeader = this.getCalendarHeaderComponent();

return (
<View style={[this.style.container, this.props.style]}>
<CalendarHeader
Expand All @@ -267,6 +281,7 @@ class Calendar extends Component {
weekNumbers={this.props.showWeekNumbers}
onPressArrowLeft={this.props.onPressArrowLeft}
onPressArrowRight={this.props.onPressArrowRight}
headerData={this.props.headerData}
/>
<View style={this.style.monthView}>{weeks}</View>
</View>);
Expand Down

0 comments on commit 037f4f6

Please sign in to comment.