UNPKG

react-calendar

Version:

Ultimate calendar for your React app.

87 lines (76 loc) 3.81 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); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import PropTypes from 'prop-types'; import Days from './MonthView/Days'; import Weekdays from './MonthView/Weekdays'; import WeekNumbers from './MonthView/WeekNumbers'; import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const'; import { isCalendarType } from './shared/propTypes'; function getCalendarTypeFromLocale(locale) { return Object.keys(CALENDAR_TYPE_LOCALES).find(function (calendarType) { return CALENDAR_TYPE_LOCALES[calendarType].includes(locale); }) || CALENDAR_TYPES.ISO_8601; } export default function MonthView(props) { var activeStartDate = props.activeStartDate, locale = props.locale, onMouseLeave = props.onMouseLeave, showFixedNumberOfWeeks = props.showFixedNumberOfWeeks; var _props$calendarType = props.calendarType, calendarType = _props$calendarType === void 0 ? getCalendarTypeFromLocale(locale) : _props$calendarType, formatShortWeekday = props.formatShortWeekday, onClickWeekNumber = props.onClickWeekNumber, showWeekNumbers = props.showWeekNumbers, childProps = _objectWithoutProperties(props, ["calendarType", "formatShortWeekday", "onClickWeekNumber", "showWeekNumbers"]); function renderWeekdays() { return React.createElement(Weekdays, { calendarType: calendarType, formatShortWeekday: formatShortWeekday, locale: locale, onMouseLeave: onMouseLeave }); } function renderWeekNumbers() { if (!showWeekNumbers) { return null; } return React.createElement(WeekNumbers, { activeStartDate: activeStartDate, calendarType: calendarType, onClickWeekNumber: onClickWeekNumber, onMouseLeave: onMouseLeave, showFixedNumberOfWeeks: showFixedNumberOfWeeks }); } function renderDays() { return React.createElement(Days, _extends({ calendarType: calendarType }, childProps)); } var className = 'react-calendar__month-view'; return React.createElement("div", { className: [className, showWeekNumbers ? "".concat(className, "--weekNumbers") : ''].join(' ') }, React.createElement("div", { style: { display: 'flex', alignItems: 'flex-end' } }, renderWeekNumbers(), React.createElement("div", { style: { flexGrow: 1, width: '100%' } }, renderWeekdays(), renderDays()))); } MonthView.propTypes = { activeStartDate: PropTypes.instanceOf(Date).isRequired, calendarType: isCalendarType, formatShortWeekday: PropTypes.func, locale: PropTypes.string, onClickWeekNumber: PropTypes.func, onMouseLeave: PropTypes.func, showFixedNumberOfWeeks: PropTypes.bool, showWeekNumbers: PropTypes.bool };