UNPKG

react-native-easy-calendar

Version:

Customizable, easy-to-use, performant calendar components for React Native

47 lines (42 loc) 1.87 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { useMemo } from 'react'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import BaseCalendarWrappedInProviders from './Providers'; dayjs.extend(utc); // OPTIMIZATION DONE // INFO: Only prop that causes rerender is selectedDate // Possibly also disabledDates if end-user doesn't memoize // A thin wrapper to limit the props that can be passed to the BaseCalendar component const DateSelectionCalendar = ({ onSelectDate, disabledDates, selectedDate, initVisibleDate, allowYearView = true, ...others }) => { const dateProperties = useMemo(() => { const disabledDateProperties = disabledDates === null || disabledDates === void 0 ? void 0 : disabledDates.reduce((disabled, date) => { disabled[date] = { isDisabled: true }; return disabled; }, {}); const selectedDateProperties = { [dayjs(selectedDate).local().format('YYYY-MM-DD')]: { isSelected: true } }; // Not possible for a date to be both disabled and selected, so overwriting is OK return { ...disabledDateProperties, ...selectedDateProperties }; }, [selectedDate, disabledDates]); // TODO: Wrap onSelectDate in non-arrow function? return /*#__PURE__*/React.createElement(BaseCalendarWrappedInProviders, _extends({ allowYearView: allowYearView, onPressDay: onSelectDate, initVisibleDate: initVisibleDate || selectedDate, dateProperties: dateProperties }, others)); }; export default DateSelectionCalendar; //# sourceMappingURL=DateSelectionCalendar.js.map