Skip to content

Instantly share code, notes, and snippets.

@sweatC
Last active May 28, 2020 10:38
Show Gist options
  • Save sweatC/2b1644e0c146b0e5432362e8a3308fab to your computer and use it in GitHub Desktop.
Save sweatC/2b1644e0c146b0e5432362e8a3308fab to your computer and use it in GitHub Desktop.
Calendar component
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Calendar } from 'react-native-calendars';
import { calendarTheme } from '../../assets/styles/elements';
import { buildSelectedDays } from '../../utils/calendar';
const styles = {
calendar: {
marginLeft: 5,
marginRight: 5,
},
};
class ViewDetailsCalendar extends Component {
render() {
const { startingDay, endingDay } = this.props.bookingDates;
return (
<Calendar
current={startingDay}
hideExtraDays={true}
theme={calendarTheme}
markedDates={this.markedDates(startingDay, endingDay)}
markingType={'period'}
style={styles.calendar}
/>
);
}
markedDates(startingDay, endingDay) {
const dayAttributes = {
color: calendarTheme.selectedDayBackgroundColor,
textColor: calendarTheme.selectedDayTextColor
};
return buildSelectedDays({ startingDay, endingDay, dayAttributes });
}
}
ViewDetailsCalendar.propTypes = {
bookingDates: PropTypes.shape({
startingDay: PropTypes.string.isRequired,
endingDay: PropTypes.string.isRequired,
}).isRequired,
};
export default ViewDetailsCalendar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment