Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

3267 строки
106 KiB

  1. import React from 'react';
  2. import propTypes from 'prop-types';
  3. import classnames from 'classnames';
  4. import isDate from 'date-fns/isDate';
  5. import isValidDate from 'date-fns/isValid';
  6. import format from 'date-fns/format';
  7. import addMinutes from 'date-fns/addMinutes';
  8. import addHours from 'date-fns/addHours';
  9. import addDays from 'date-fns/addDays';
  10. import addWeeks from 'date-fns/addWeeks';
  11. import addMonths from 'date-fns/addMonths';
  12. import addYears from 'date-fns/addYears';
  13. import subMinutes from 'date-fns/subMinutes';
  14. import subHours from 'date-fns/subHours';
  15. import subDays from 'date-fns/subDays';
  16. import subWeeks from 'date-fns/subWeeks';
  17. import subMonths from 'date-fns/subMonths';
  18. import subYears from 'date-fns/subYears';
  19. import getSeconds from 'date-fns/getSeconds';
  20. import getMinutes from 'date-fns/getMinutes';
  21. import getHours from 'date-fns/getHours';
  22. import getDay from 'date-fns/getDay';
  23. import getDate from 'date-fns/getDate';
  24. import getMonth from 'date-fns/getMonth';
  25. import getYear from 'date-fns/getYear';
  26. import getTime from 'date-fns/getTime';
  27. import setSeconds from 'date-fns/setSeconds';
  28. import setMinutes from 'date-fns/setMinutes';
  29. import setHours from 'date-fns/setHours';
  30. import setMonth from 'date-fns/setMonth';
  31. import setYear from 'date-fns/setYear';
  32. import min from 'date-fns/min';
  33. import max from 'date-fns/max';
  34. import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
  35. import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
  36. import differenceInCalendarWeeks from 'date-fns/differenceInCalendarWeeks';
  37. import setDayOfYear from 'date-fns/setDayOfYear';
  38. import startOfDay from 'date-fns/startOfDay';
  39. import startOfWeek from 'date-fns/startOfWeek';
  40. import startOfMonth from 'date-fns/startOfMonth';
  41. import startOfYear from 'date-fns/startOfYear';
  42. import endOfWeek from 'date-fns/endOfWeek';
  43. import endOfMonth from 'date-fns/endOfMonth';
  44. import dfIsEqual from 'date-fns/isEqual';
  45. import dfIsSameDay from 'date-fns/isSameDay';
  46. import dfIsSameMonth from 'date-fns/isSameMonth';
  47. import dfIsSameYear from 'date-fns/isSameYear';
  48. import isAfter from 'date-fns/isAfter';
  49. import isBefore from 'date-fns/isBefore';
  50. import isWithinInterval from 'date-fns/isWithinInterval';
  51. import toDate from 'date-fns/toDate';
  52. import parse from 'date-fns/parse';
  53. import parseISO from 'date-fns/parseISO';
  54. import onClickOutside from 'react-onclickoutside';
  55. import { Manager, Popper, Reference } from 'react-popper';
  56. function unwrapExports (x) {
  57. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  58. }
  59. function createCommonjsModule(fn, module) {
  60. return module = { exports: {} }, fn(module, module.exports), module.exports;
  61. }
  62. var longFormatters_1 = createCommonjsModule(function (module, exports) {
  63. Object.defineProperty(exports, "__esModule", {
  64. value: true
  65. });
  66. exports.default = void 0;
  67. function dateLongFormatter(pattern, formatLong) {
  68. switch (pattern) {
  69. case 'P':
  70. return formatLong.date({
  71. width: 'short'
  72. });
  73. case 'PP':
  74. return formatLong.date({
  75. width: 'medium'
  76. });
  77. case 'PPP':
  78. return formatLong.date({
  79. width: 'long'
  80. });
  81. case 'PPPP':
  82. default:
  83. return formatLong.date({
  84. width: 'full'
  85. });
  86. }
  87. }
  88. function timeLongFormatter(pattern, formatLong) {
  89. switch (pattern) {
  90. case 'p':
  91. return formatLong.time({
  92. width: 'short'
  93. });
  94. case 'pp':
  95. return formatLong.time({
  96. width: 'medium'
  97. });
  98. case 'ppp':
  99. return formatLong.time({
  100. width: 'long'
  101. });
  102. case 'pppp':
  103. default:
  104. return formatLong.time({
  105. width: 'full'
  106. });
  107. }
  108. }
  109. function dateTimeLongFormatter(pattern, formatLong) {
  110. var matchResult = pattern.match(/(P+)(p+)?/);
  111. var datePattern = matchResult[1];
  112. var timePattern = matchResult[2];
  113. if (!timePattern) {
  114. return dateLongFormatter(pattern, formatLong);
  115. }
  116. var dateTimeFormat;
  117. switch (datePattern) {
  118. case 'P':
  119. dateTimeFormat = formatLong.dateTime({
  120. width: 'short'
  121. });
  122. break;
  123. case 'PP':
  124. dateTimeFormat = formatLong.dateTime({
  125. width: 'medium'
  126. });
  127. break;
  128. case 'PPP':
  129. dateTimeFormat = formatLong.dateTime({
  130. width: 'long'
  131. });
  132. break;
  133. case 'PPPP':
  134. default:
  135. dateTimeFormat = formatLong.dateTime({
  136. width: 'full'
  137. });
  138. break;
  139. }
  140. return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
  141. }
  142. var longFormatters = {
  143. p: timeLongFormatter,
  144. P: dateTimeLongFormatter
  145. };
  146. var _default = longFormatters;
  147. exports.default = _default;
  148. module.exports = exports.default;
  149. });
  150. var longFormatters = unwrapExports(longFormatters_1);
  151. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  152. return typeof obj;
  153. } : function (obj) {
  154. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  155. };
  156. var classCallCheck = function (instance, Constructor) {
  157. if (!(instance instanceof Constructor)) {
  158. throw new TypeError("Cannot call a class as a function");
  159. }
  160. };
  161. var createClass = function () {
  162. function defineProperties(target, props) {
  163. for (var i = 0; i < props.length; i++) {
  164. var descriptor = props[i];
  165. descriptor.enumerable = descriptor.enumerable || false;
  166. descriptor.configurable = true;
  167. if ("value" in descriptor) descriptor.writable = true;
  168. Object.defineProperty(target, descriptor.key, descriptor);
  169. }
  170. }
  171. return function (Constructor, protoProps, staticProps) {
  172. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  173. if (staticProps) defineProperties(Constructor, staticProps);
  174. return Constructor;
  175. };
  176. }();
  177. var _extends = Object.assign || function (target) {
  178. for (var i = 1; i < arguments.length; i++) {
  179. var source = arguments[i];
  180. for (var key in source) {
  181. if (Object.prototype.hasOwnProperty.call(source, key)) {
  182. target[key] = source[key];
  183. }
  184. }
  185. }
  186. return target;
  187. };
  188. var inherits = function (subClass, superClass) {
  189. if (typeof superClass !== "function" && superClass !== null) {
  190. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  191. }
  192. subClass.prototype = Object.create(superClass && superClass.prototype, {
  193. constructor: {
  194. value: subClass,
  195. enumerable: false,
  196. writable: true,
  197. configurable: true
  198. }
  199. });
  200. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  201. };
  202. var possibleConstructorReturn = function (self, call) {
  203. if (!self) {
  204. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  205. }
  206. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  207. };
  208. // This RegExp catches symbols escaped by quotes, and also
  209. // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
  210. var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
  211. // ** Date Constructors **
  212. function newDate(value) {
  213. var d = value ? typeof value === "string" || value instanceof String ? parseISO(value) : toDate(value) : new Date();
  214. return isValid(d) ? d : null;
  215. }
  216. function parseDate(value, dateFormat, locale, strictParsing) {
  217. var parsedDate = null;
  218. var localeObject = getLocaleObject(locale) || getDefaultLocale();
  219. var strictParsingValueMatch = true;
  220. if (Array.isArray(dateFormat)) {
  221. dateFormat.forEach(function (df) {
  222. var tryParseDate = parse(value, df, new Date(), { locale: localeObject });
  223. if (strictParsing) {
  224. strictParsingValueMatch = isValid(tryParseDate) && value === format(tryParseDate, df, { awareOfUnicodeTokens: true });
  225. }
  226. if (isValid(tryParseDate) && strictParsingValueMatch) {
  227. parsedDate = tryParseDate;
  228. }
  229. });
  230. return parsedDate;
  231. }
  232. parsedDate = parse(value, dateFormat, new Date(), { locale: localeObject });
  233. if (strictParsing) {
  234. strictParsingValueMatch = isValid(parsedDate) && value === format(parsedDate, dateFormat, { awareOfUnicodeTokens: true });
  235. } else if (!isValid(parsedDate)) {
  236. dateFormat = dateFormat.match(longFormattingTokensRegExp).map(function (substring) {
  237. var firstCharacter = substring[0];
  238. if (firstCharacter === "p" || firstCharacter === "P") {
  239. var longFormatter = longFormatters[firstCharacter];
  240. return localeObject ? longFormatter(substring, localeObject.formatLong) : firstCharacter;
  241. }
  242. return substring;
  243. }).join("");
  244. if (value.length > 0) {
  245. parsedDate = parse(value, dateFormat.slice(0, value.length), new Date());
  246. }
  247. if (!isValid(parsedDate)) {
  248. parsedDate = new Date(value);
  249. }
  250. }
  251. return isValid(parsedDate) && strictParsingValueMatch ? parsedDate : null;
  252. }
  253. function isValid(date) {
  254. return isValidDate(date) && isAfter(date, new Date("1/1/1000"));
  255. }
  256. // ** Date Formatting **
  257. function formatDate(date, formatStr, locale) {
  258. if (locale === "en") {
  259. return format(date, formatStr, { awareOfUnicodeTokens: true });
  260. }
  261. var localeObj = getLocaleObject(locale);
  262. if (locale && !localeObj) {
  263. console.warn("A locale object was not found for the provided string [\"" + locale + "\"].");
  264. }
  265. if (!localeObj && !!getDefaultLocale() && !!getLocaleObject(getDefaultLocale())) {
  266. localeObj = getLocaleObject(getDefaultLocale());
  267. }
  268. return format(date, formatStr, {
  269. locale: localeObj ? localeObj : null,
  270. awareOfUnicodeTokens: true
  271. });
  272. }
  273. function safeDateFormat(date, _ref) {
  274. var dateFormat = _ref.dateFormat,
  275. locale = _ref.locale;
  276. return date && formatDate(date, Array.isArray(dateFormat) ? dateFormat[0] : dateFormat, locale) || "";
  277. }
  278. // ** Date Setters **
  279. function setTime(date, _ref2) {
  280. var _ref2$hour = _ref2.hour,
  281. hour = _ref2$hour === undefined ? 0 : _ref2$hour,
  282. _ref2$minute = _ref2.minute,
  283. minute = _ref2$minute === undefined ? 0 : _ref2$minute,
  284. _ref2$second = _ref2.second,
  285. second = _ref2$second === undefined ? 0 : _ref2$second;
  286. return setHours(setMinutes(setSeconds(date, second), minute), hour);
  287. }
  288. function getWeek(date) {
  289. var firstDayOfYear = setDayOfYear(date, 1);
  290. if (!isSameYear(endOfWeek(date), date)) {
  291. return 1;
  292. }
  293. return differenceInCalendarWeeks(date, startOfYear(date)) + 1;
  294. }
  295. function getDayOfWeekCode(day, locale) {
  296. return formatDate(day, "ddd", locale);
  297. }
  298. // *** Start of ***
  299. function getStartOfDay(date) {
  300. return startOfDay(date);
  301. }
  302. function getStartOfWeek(date, locale) {
  303. var localeObj = locale ? getLocaleObject(locale) : getLocaleObject(getDefaultLocale());
  304. return startOfWeek(date, { locale: localeObj });
  305. }
  306. function getStartOfMonth(date) {
  307. return startOfMonth(date);
  308. }
  309. function getStartOfToday() {
  310. return startOfDay(newDate());
  311. }
  312. // *** End of ***
  313. function isSameYear(date1, date2) {
  314. if (date1 && date2) {
  315. return dfIsSameYear(date1, date2);
  316. } else {
  317. return !date1 && !date2;
  318. }
  319. }
  320. function isSameMonth(date1, date2) {
  321. if (date1 && date2) {
  322. return dfIsSameMonth(date1, date2);
  323. } else {
  324. return !date1 && !date2;
  325. }
  326. }
  327. function isSameDay(date1, date2) {
  328. if (date1 && date2) {
  329. return dfIsSameDay(date1, date2);
  330. } else {
  331. return !date1 && !date2;
  332. }
  333. }
  334. function isEqual(date1, date2) {
  335. if (date1 && date2) {
  336. return dfIsEqual(date1, date2);
  337. } else {
  338. return !date1 && !date2;
  339. }
  340. }
  341. function isDayInRange(day, startDate, endDate) {
  342. var valid = void 0;
  343. try {
  344. valid = isWithinInterval(day, { start: startDate, end: endDate });
  345. } catch (err) {
  346. valid = false;
  347. }
  348. return valid;
  349. }
  350. // *** Diffing ***
  351. // ** Date Localization **
  352. function registerLocale(localeName, localeData) {
  353. var scope = typeof window !== "undefined" ? window : global;
  354. if (!scope.__localeData__) {
  355. scope.__localeData__ = {};
  356. }
  357. scope.__localeData__[localeName] = localeData;
  358. }
  359. function setDefaultLocale(localeName) {
  360. var scope = typeof window !== "undefined" ? window : global;
  361. scope.__localeId__ = localeName;
  362. }
  363. function getDefaultLocale() {
  364. var scope = typeof window !== "undefined" ? window : global;
  365. return scope.__localeId__;
  366. }
  367. function getLocaleObject(localeSpec) {
  368. if (typeof localeSpec === "string") {
  369. // Treat it as a locale name registered by registerLocale
  370. var scope = typeof window !== "undefined" ? window : global;
  371. return scope.__localeData__ ? scope.__localeData__[localeSpec] : null;
  372. } else {
  373. // Treat it as a raw date-fns locale object
  374. return localeSpec;
  375. }
  376. }
  377. function getFormattedWeekdayInLocale(date, formatFunc, locale) {
  378. return formatFunc(formatDate(date, "EEEE", locale));
  379. }
  380. function getWeekdayMinInLocale(date, locale) {
  381. return formatDate(date, "EEEEEE", locale);
  382. }
  383. function getWeekdayShortInLocale(date, locale) {
  384. return formatDate(date, "EEE", locale);
  385. }
  386. function getMonthInLocale(month, locale) {
  387. return formatDate(setMonth(newDate(), month), "LLLL", locale);
  388. }
  389. function getMonthShortInLocale(month, locale) {
  390. return formatDate(setMonth(newDate(), month), "LLL", locale);
  391. }
  392. // ** Utils for some components **
  393. function isDayDisabled(day) {
  394. var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  395. minDate = _ref3.minDate,
  396. maxDate = _ref3.maxDate,
  397. excludeDates = _ref3.excludeDates,
  398. includeDates = _ref3.includeDates,
  399. filterDate = _ref3.filterDate;
  400. return isOutOfBounds(day, { minDate: minDate, maxDate: maxDate }) || excludeDates && excludeDates.some(function (excludeDate) {
  401. return isSameDay(day, excludeDate);
  402. }) || includeDates && !includeDates.some(function (includeDate) {
  403. return isSameDay(day, includeDate);
  404. }) || filterDate && !filterDate(newDate(day)) || false;
  405. }
  406. function isMonthDisabled(month) {
  407. var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  408. minDate = _ref4.minDate,
  409. maxDate = _ref4.maxDate,
  410. excludeDates = _ref4.excludeDates,
  411. includeDates = _ref4.includeDates,
  412. filterDate = _ref4.filterDate;
  413. return isOutOfBounds(month, { minDate: minDate, maxDate: maxDate }) || excludeDates && excludeDates.some(function (excludeDate) {
  414. return isSameMonth(month, excludeDate);
  415. }) || includeDates && !includeDates.some(function (includeDate) {
  416. return isSameMonth(month, includeDate);
  417. }) || filterDate && !filterDate(newDate(month)) || false;
  418. }
  419. function isMonthinRange(startDate, endDate, m, day) {
  420. var startDateYear = getYear(startDate);
  421. var startDateMonth = getMonth(startDate);
  422. var endDateYear = getYear(endDate);
  423. var endDateMonth = getMonth(endDate);
  424. var dayYear = getYear(day);
  425. if (startDateYear === endDateYear && startDateYear === dayYear) {
  426. return startDateMonth <= m && m <= endDateMonth;
  427. } else if (startDateYear < endDateYear) {
  428. return dayYear === startDateYear && startDateMonth <= m || dayYear === endDateYear && endDateMonth >= m || dayYear < endDateYear && dayYear > startDateYear;
  429. }
  430. }
  431. function isOutOfBounds(day) {
  432. var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  433. minDate = _ref5.minDate,
  434. maxDate = _ref5.maxDate;
  435. return minDate && differenceInCalendarDays(day, minDate) < 0 || maxDate && differenceInCalendarDays(day, maxDate) > 0;
  436. }
  437. function isTimeDisabled(time, disabledTimes) {
  438. var l = disabledTimes.length;
  439. for (var i = 0; i < l; i++) {
  440. if (getHours(disabledTimes[i]) === getHours(time) && getMinutes(disabledTimes[i]) === getMinutes(time)) {
  441. return true;
  442. }
  443. }
  444. return false;
  445. }
  446. function isTimeInDisabledRange(time, _ref6) {
  447. var minTime = _ref6.minTime,
  448. maxTime = _ref6.maxTime;
  449. if (!minTime || !maxTime) {
  450. throw new Error("Both minTime and maxTime props required");
  451. }
  452. var base = newDate();
  453. var baseTime = setHours(setMinutes(base, getMinutes(time)), getHours(time));
  454. var min$$1 = setHours(setMinutes(base, getMinutes(minTime)), getHours(minTime));
  455. var max$$1 = setHours(setMinutes(base, getMinutes(maxTime)), getHours(maxTime));
  456. var valid = void 0;
  457. try {
  458. valid = !isWithinInterval(baseTime, { start: min$$1, end: max$$1 });
  459. } catch (err) {
  460. valid = false;
  461. }
  462. return valid;
  463. }
  464. function monthDisabledBefore(day) {
  465. var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  466. minDate = _ref7.minDate,
  467. includeDates = _ref7.includeDates;
  468. var previousMonth = subMonths(day, 1);
  469. return minDate && differenceInCalendarMonths(minDate, previousMonth) > 0 || includeDates && includeDates.every(function (includeDate) {
  470. return differenceInCalendarMonths(includeDate, previousMonth) > 0;
  471. }) || false;
  472. }
  473. function monthDisabledAfter(day) {
  474. var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  475. maxDate = _ref8.maxDate,
  476. includeDates = _ref8.includeDates;
  477. var nextMonth = addMonths(day, 1);
  478. return maxDate && differenceInCalendarMonths(nextMonth, maxDate) > 0 || includeDates && includeDates.every(function (includeDate) {
  479. return differenceInCalendarMonths(nextMonth, includeDate) > 0;
  480. }) || false;
  481. }
  482. function getEffectiveMinDate(_ref9) {
  483. var minDate = _ref9.minDate,
  484. includeDates = _ref9.includeDates;
  485. if (includeDates && minDate) {
  486. var minDates = includeDates.filter(function (includeDate) {
  487. return differenceInCalendarDays(includeDate, minDate) >= 0;
  488. });
  489. return min(minDates);
  490. } else if (includeDates) {
  491. return min(includeDates);
  492. } else {
  493. return minDate;
  494. }
  495. }
  496. function getEffectiveMaxDate(_ref10) {
  497. var maxDate = _ref10.maxDate,
  498. includeDates = _ref10.includeDates;
  499. if (includeDates && maxDate) {
  500. var maxDates = includeDates.filter(function (includeDate) {
  501. return differenceInCalendarDays(includeDate, maxDate) <= 0;
  502. });
  503. return max(maxDates);
  504. } else if (includeDates) {
  505. return max(includeDates);
  506. } else {
  507. return maxDate;
  508. }
  509. }
  510. function getHightLightDaysMap() {
  511. var highlightDates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  512. var defaultClassName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "react-datepicker__day--highlighted";
  513. var dateClasses = new Map();
  514. for (var i = 0, len = highlightDates.length; i < len; i++) {
  515. var obj = highlightDates[i];
  516. if (isDate(obj)) {
  517. var key = formatDate(obj, "MM.dd.yyyy");
  518. var classNamesArr = dateClasses.get(key) || [];
  519. if (!classNamesArr.includes(defaultClassName)) {
  520. classNamesArr.push(defaultClassName);
  521. dateClasses.set(key, classNamesArr);
  522. }
  523. } else if ((typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object") {
  524. var keys = Object.keys(obj);
  525. var className = keys[0];
  526. var arrOfDates = obj[keys[0]];
  527. if (typeof className === "string" && arrOfDates.constructor === Array) {
  528. for (var k = 0, _len = arrOfDates.length; k < _len; k++) {
  529. var _key = formatDate(arrOfDates[k], "MM.dd.yyyy");
  530. var _classNamesArr = dateClasses.get(_key) || [];
  531. if (!_classNamesArr.includes(className)) {
  532. _classNamesArr.push(className);
  533. dateClasses.set(_key, _classNamesArr);
  534. }
  535. }
  536. }
  537. }
  538. }
  539. return dateClasses;
  540. }
  541. function timesToInjectAfter(startOfDay$$1, currentTime, currentMultiplier, intervals, injectedTimes) {
  542. var l = injectedTimes.length;
  543. var times = [];
  544. for (var i = 0; i < l; i++) {
  545. var injectedTime = addMinutes(addHours(startOfDay$$1, getHours(injectedTimes[i])), getMinutes(injectedTimes[i]));
  546. var nextTime = addMinutes(startOfDay$$1, (currentMultiplier + 1) * intervals);
  547. if (isAfter(injectedTime, currentTime) && isBefore(injectedTime, nextTime)) {
  548. times.push(injectedTimes[i]);
  549. }
  550. }
  551. return times;
  552. }
  553. function addZero(i) {
  554. return i < 10 ? "0" + i : "" + i;
  555. }
  556. function generateYears(year, noOfYear, minDate, maxDate) {
  557. var list = [];
  558. for (var i = 0; i < 2 * noOfYear + 1; i++) {
  559. var newYear = year + noOfYear - i;
  560. var isInRange = true;
  561. if (minDate) {
  562. isInRange = getYear(minDate) <= newYear;
  563. }
  564. if (maxDate && isInRange) {
  565. isInRange = getYear(maxDate) >= newYear;
  566. }
  567. if (isInRange) {
  568. list.push(newYear);
  569. }
  570. }
  571. return list;
  572. }
  573. var YearDropdownOptions = function (_React$Component) {
  574. inherits(YearDropdownOptions, _React$Component);
  575. function YearDropdownOptions(props) {
  576. classCallCheck(this, YearDropdownOptions);
  577. var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
  578. _this.renderOptions = function () {
  579. var selectedYear = _this.props.year;
  580. var options = _this.state.yearsList.map(function (year) {
  581. return React.createElement(
  582. "div",
  583. {
  584. className: selectedYear === year ? "react-datepicker__year-option react-datepicker__year-option--selected_year" : "react-datepicker__year-option",
  585. key: year,
  586. ref: year,
  587. onClick: _this.onChange.bind(_this, year)
  588. },
  589. selectedYear === year ? React.createElement(
  590. "span",
  591. { className: "react-datepicker__year-option--selected" },
  592. "\u2713"
  593. ) : "",
  594. year
  595. );
  596. });
  597. var minYear = _this.props.minDate ? getYear(_this.props.minDate) : null;
  598. var maxYear = _this.props.maxDate ? getYear(_this.props.maxDate) : null;
  599. if (!maxYear || !_this.state.yearsList.find(function (year) {
  600. return year === maxYear;
  601. })) {
  602. options.unshift(React.createElement(
  603. "div",
  604. {
  605. className: "react-datepicker__year-option",
  606. ref: "upcoming",
  607. key: "upcoming",
  608. onClick: _this.incrementYears
  609. },
  610. React.createElement("a", { className: "react-datepicker__navigation react-datepicker__navigation--years react-datepicker__navigation--years-upcoming" })
  611. ));
  612. }
  613. if (!minYear || !_this.state.yearsList.find(function (year) {
  614. return year === minYear;
  615. })) {
  616. options.push(React.createElement(
  617. "div",
  618. {
  619. className: "react-datepicker__year-option",
  620. ref: "previous",
  621. key: "previous",
  622. onClick: _this.decrementYears
  623. },
  624. React.createElement("a", { className: "react-datepicker__navigation react-datepicker__navigation--years react-datepicker__navigation--years-previous" })
  625. ));
  626. }
  627. return options;
  628. };
  629. _this.onChange = function (year) {
  630. _this.props.onChange(year);
  631. };
  632. _this.handleClickOutside = function () {
  633. _this.props.onCancel();
  634. };
  635. _this.shiftYears = function (amount) {
  636. var years = _this.state.yearsList.map(function (year) {
  637. return year + amount;
  638. });
  639. _this.setState({
  640. yearsList: years
  641. });
  642. };
  643. _this.incrementYears = function () {
  644. return _this.shiftYears(1);
  645. };
  646. _this.decrementYears = function () {
  647. return _this.shiftYears(-1);
  648. };
  649. var yearDropdownItemNumber = props.yearDropdownItemNumber,
  650. scrollableYearDropdown = props.scrollableYearDropdown;
  651. var noOfYear = yearDropdownItemNumber || (scrollableYearDropdown ? 10 : 5);
  652. _this.state = {
  653. yearsList: generateYears(_this.props.year, noOfYear, _this.props.minDate, _this.props.maxDate)
  654. };
  655. return _this;
  656. }
  657. YearDropdownOptions.prototype.render = function render() {
  658. var dropdownClass = classnames({
  659. "react-datepicker__year-dropdown": true,
  660. "react-datepicker__year-dropdown--scrollable": this.props.scrollableYearDropdown
  661. });
  662. return React.createElement(
  663. "div",
  664. { className: dropdownClass },
  665. this.renderOptions()
  666. );
  667. };
  668. return YearDropdownOptions;
  669. }(React.Component);
  670. var WrappedYearDropdownOptions = onClickOutside(YearDropdownOptions);
  671. var YearDropdown = function (_React$Component) {
  672. inherits(YearDropdown, _React$Component);
  673. function YearDropdown() {
  674. var _temp, _this, _ret;
  675. classCallCheck(this, YearDropdown);
  676. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  677. args[_key] = arguments[_key];
  678. }
  679. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  680. dropdownVisible: false
  681. }, _this.renderSelectOptions = function () {
  682. var minYear = _this.props.minDate ? getYear(_this.props.minDate) : 1900;
  683. var maxYear = _this.props.maxDate ? getYear(_this.props.maxDate) : 2100;
  684. var options = [];
  685. for (var i = minYear; i <= maxYear; i++) {
  686. options.push(React.createElement(
  687. "option",
  688. { key: i, value: i },
  689. i
  690. ));
  691. }
  692. return options;
  693. }, _this.onSelectChange = function (e) {
  694. _this.onChange(e.target.value);
  695. }, _this.renderSelectMode = function () {
  696. return React.createElement(
  697. "select",
  698. {
  699. value: _this.props.year,
  700. className: "react-datepicker__year-select",
  701. onChange: _this.onSelectChange
  702. },
  703. _this.renderSelectOptions()
  704. );
  705. }, _this.renderReadView = function (visible) {
  706. return React.createElement(
  707. "div",
  708. {
  709. key: "read",
  710. style: { visibility: visible ? "visible" : "hidden" },
  711. className: "react-datepicker__year-read-view",
  712. onClick: function onClick(event) {
  713. return _this.toggleDropdown(event);
  714. }
  715. },
  716. React.createElement("span", { className: "react-datepicker__year-read-view--down-arrow" }),
  717. React.createElement(
  718. "span",
  719. { className: "react-datepicker__year-read-view--selected-year" },
  720. _this.props.year
  721. )
  722. );
  723. }, _this.renderDropdown = function () {
  724. return React.createElement(WrappedYearDropdownOptions, {
  725. key: "dropdown",
  726. ref: "options",
  727. year: _this.props.year,
  728. onChange: _this.onChange,
  729. onCancel: _this.toggleDropdown,
  730. minDate: _this.props.minDate,
  731. maxDate: _this.props.maxDate,
  732. scrollableYearDropdown: _this.props.scrollableYearDropdown,
  733. yearDropdownItemNumber: _this.props.yearDropdownItemNumber
  734. });
  735. }, _this.renderScrollMode = function () {
  736. var dropdownVisible = _this.state.dropdownVisible;
  737. var result = [_this.renderReadView(!dropdownVisible)];
  738. if (dropdownVisible) {
  739. result.unshift(_this.renderDropdown());
  740. }
  741. return result;
  742. }, _this.onChange = function (year) {
  743. _this.toggleDropdown();
  744. if (year === _this.props.year) return;
  745. _this.props.onChange(year);
  746. }, _this.toggleDropdown = function (event) {
  747. _this.setState({
  748. dropdownVisible: !_this.state.dropdownVisible
  749. }, function () {
  750. if (_this.props.adjustDateOnChange) {
  751. _this.handleYearChange(_this.props.date, event);
  752. }
  753. });
  754. }, _this.handleYearChange = function (date, event) {
  755. _this.onSelect(date, event);
  756. _this.setOpen();
  757. }, _this.onSelect = function (date, event) {
  758. if (_this.props.onSelect) {
  759. _this.props.onSelect(date, event);
  760. }
  761. }, _this.setOpen = function () {
  762. if (_this.props.setOpen) {
  763. _this.props.setOpen(true);
  764. }
  765. }, _temp), possibleConstructorReturn(_this, _ret);
  766. }
  767. YearDropdown.prototype.render = function render() {
  768. var renderedDropdown = void 0;
  769. switch (this.props.dropdownMode) {
  770. case "scroll":
  771. renderedDropdown = this.renderScrollMode();
  772. break;
  773. case "select":
  774. renderedDropdown = this.renderSelectMode();
  775. break;
  776. }
  777. return React.createElement(
  778. "div",
  779. {
  780. className: "react-datepicker__year-dropdown-container react-datepicker__year-dropdown-container--" + this.props.dropdownMode
  781. },
  782. renderedDropdown
  783. );
  784. };
  785. return YearDropdown;
  786. }(React.Component);
  787. var MonthDropdownOptions = function (_React$Component) {
  788. inherits(MonthDropdownOptions, _React$Component);
  789. function MonthDropdownOptions() {
  790. var _temp, _this, _ret;
  791. classCallCheck(this, MonthDropdownOptions);
  792. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  793. args[_key] = arguments[_key];
  794. }
  795. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.renderOptions = function () {
  796. return _this.props.monthNames.map(function (month, i) {
  797. return React.createElement(
  798. "div",
  799. {
  800. className: _this.props.month === i ? "react-datepicker__month-option --selected_month" : "react-datepicker__month-option",
  801. key: month,
  802. ref: month,
  803. onClick: _this.onChange.bind(_this, i)
  804. },
  805. _this.props.month === i ? React.createElement(
  806. "span",
  807. { className: "react-datepicker__month-option--selected" },
  808. "\u2713"
  809. ) : "",
  810. month
  811. );
  812. });
  813. }, _this.onChange = function (month) {
  814. return _this.props.onChange(month);
  815. }, _this.handleClickOutside = function () {
  816. return _this.props.onCancel();
  817. }, _temp), possibleConstructorReturn(_this, _ret);
  818. }
  819. MonthDropdownOptions.prototype.render = function render() {
  820. return React.createElement(
  821. "div",
  822. { className: "react-datepicker__month-dropdown" },
  823. this.renderOptions()
  824. );
  825. };
  826. return MonthDropdownOptions;
  827. }(React.Component);
  828. var WrappedMonthDropdownOptions = onClickOutside(MonthDropdownOptions);
  829. var MonthDropdown = function (_React$Component) {
  830. inherits(MonthDropdown, _React$Component);
  831. function MonthDropdown() {
  832. var _temp, _this, _ret;
  833. classCallCheck(this, MonthDropdown);
  834. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  835. args[_key] = arguments[_key];
  836. }
  837. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  838. dropdownVisible: false
  839. }, _this.renderSelectOptions = function (monthNames) {
  840. return monthNames.map(function (M, i) {
  841. return React.createElement(
  842. "option",
  843. { key: i, value: i },
  844. M
  845. );
  846. });
  847. }, _this.renderSelectMode = function (monthNames) {
  848. return React.createElement(
  849. "select",
  850. {
  851. value: _this.props.month,
  852. className: "react-datepicker__month-select",
  853. onChange: function onChange(e) {
  854. return _this.onChange(e.target.value);
  855. }
  856. },
  857. _this.renderSelectOptions(monthNames)
  858. );
  859. }, _this.renderReadView = function (visible, monthNames) {
  860. return React.createElement(
  861. "div",
  862. {
  863. key: "read",
  864. style: { visibility: visible ? "visible" : "hidden" },
  865. className: "react-datepicker__month-read-view",
  866. onClick: _this.toggleDropdown
  867. },
  868. React.createElement("span", { className: "react-datepicker__month-read-view--down-arrow" }),
  869. React.createElement(
  870. "span",
  871. { className: "react-datepicker__month-read-view--selected-month" },
  872. monthNames[_this.props.month]
  873. )
  874. );
  875. }, _this.renderDropdown = function (monthNames) {
  876. return React.createElement(WrappedMonthDropdownOptions, {
  877. key: "dropdown",
  878. ref: "options",
  879. month: _this.props.month,
  880. monthNames: monthNames,
  881. onChange: _this.onChange,
  882. onCancel: _this.toggleDropdown
  883. });
  884. }, _this.renderScrollMode = function (monthNames) {
  885. var dropdownVisible = _this.state.dropdownVisible;
  886. var result = [_this.renderReadView(!dropdownVisible, monthNames)];
  887. if (dropdownVisible) {
  888. result.unshift(_this.renderDropdown(monthNames));
  889. }
  890. return result;
  891. }, _this.onChange = function (month) {
  892. _this.toggleDropdown();
  893. if (month !== _this.props.month) {
  894. _this.props.onChange(month);
  895. }
  896. }, _this.toggleDropdown = function () {
  897. return _this.setState({
  898. dropdownVisible: !_this.state.dropdownVisible
  899. });
  900. }, _temp), possibleConstructorReturn(_this, _ret);
  901. }
  902. MonthDropdown.prototype.render = function render() {
  903. var _this2 = this;
  904. var monthNames = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(this.props.useShortMonthInDropdown ? function (M) {
  905. return getMonthShortInLocale(M, _this2.props.locale);
  906. } : function (M) {
  907. return getMonthInLocale(M, _this2.props.locale);
  908. });
  909. var renderedDropdown = void 0;
  910. switch (this.props.dropdownMode) {
  911. case "scroll":
  912. renderedDropdown = this.renderScrollMode(monthNames);
  913. break;
  914. case "select":
  915. renderedDropdown = this.renderSelectMode(monthNames);
  916. break;
  917. }
  918. return React.createElement(
  919. "div",
  920. {
  921. className: "react-datepicker__month-dropdown-container react-datepicker__month-dropdown-container--" + this.props.dropdownMode
  922. },
  923. renderedDropdown
  924. );
  925. };
  926. return MonthDropdown;
  927. }(React.Component);
  928. function generateMonthYears(minDate, maxDate) {
  929. var list = [];
  930. var currDate = getStartOfMonth(minDate);
  931. var lastDate = getStartOfMonth(maxDate);
  932. while (!isAfter(currDate, lastDate)) {
  933. list.push(newDate(currDate));
  934. currDate = addMonths(currDate, 1);
  935. }
  936. return list;
  937. }
  938. var MonthYearDropdownOptions = function (_React$Component) {
  939. inherits(MonthYearDropdownOptions, _React$Component);
  940. function MonthYearDropdownOptions(props) {
  941. classCallCheck(this, MonthYearDropdownOptions);
  942. var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
  943. _this.renderOptions = function () {
  944. return _this.state.monthYearsList.map(function (monthYear) {
  945. var monthYearPoint = getTime(monthYear);
  946. var isSameMonthYear = isSameYear(_this.props.date, monthYear) && isSameMonth(_this.props.date, monthYear);
  947. return React.createElement(
  948. "div",
  949. {
  950. className: isSameMonthYear ? "react-datepicker__month-year-option --selected_month-year" : "react-datepicker__month-year-option",
  951. key: monthYearPoint,
  952. ref: monthYearPoint,
  953. onClick: _this.onChange.bind(_this, monthYearPoint)
  954. },
  955. isSameMonthYear ? React.createElement(
  956. "span",
  957. { className: "react-datepicker__month-year-option--selected" },
  958. "\u2713"
  959. ) : "",
  960. formatDate(monthYear, _this.props.dateFormat)
  961. );
  962. });
  963. };
  964. _this.onChange = function (monthYear) {
  965. return _this.props.onChange(monthYear);
  966. };
  967. _this.handleClickOutside = function () {
  968. _this.props.onCancel();
  969. };
  970. _this.state = {
  971. monthYearsList: generateMonthYears(_this.props.minDate, _this.props.maxDate)
  972. };
  973. return _this;
  974. }
  975. MonthYearDropdownOptions.prototype.render = function render() {
  976. var dropdownClass = classnames({
  977. "react-datepicker__month-year-dropdown": true,
  978. "react-datepicker__month-year-dropdown--scrollable": this.props.scrollableMonthYearDropdown
  979. });
  980. return React.createElement(
  981. "div",
  982. { className: dropdownClass },
  983. this.renderOptions()
  984. );
  985. };
  986. return MonthYearDropdownOptions;
  987. }(React.Component);
  988. var WrappedMonthYearDropdownOptions = onClickOutside(MonthYearDropdownOptions);
  989. var MonthYearDropdown = function (_React$Component) {
  990. inherits(MonthYearDropdown, _React$Component);
  991. function MonthYearDropdown() {
  992. var _temp, _this, _ret;
  993. classCallCheck(this, MonthYearDropdown);
  994. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  995. args[_key] = arguments[_key];
  996. }
  997. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  998. dropdownVisible: false
  999. }, _this.renderSelectOptions = function () {
  1000. var currDate = getStartOfMonth(_this.props.minDate);
  1001. var lastDate = getStartOfMonth(_this.props.maxDate);
  1002. var options = [];
  1003. while (!isAfter(currDate, lastDate)) {
  1004. var timepoint = getTime(currDate);
  1005. options.push(React.createElement(
  1006. "option",
  1007. { key: timepoint, value: timepoint },
  1008. formatDate(currDate, _this.props.dateFormat, _this.props.locale)
  1009. ));
  1010. currDate = addMonths(currDate, 1);
  1011. }
  1012. return options;
  1013. }, _this.onSelectChange = function (e) {
  1014. _this.onChange(e.target.value);
  1015. }, _this.renderSelectMode = function () {
  1016. return React.createElement(
  1017. "select",
  1018. {
  1019. value: getTime(getStartOfMonth(_this.props.date)),
  1020. className: "react-datepicker__month-year-select",
  1021. onChange: _this.onSelectChange
  1022. },
  1023. _this.renderSelectOptions()
  1024. );
  1025. }, _this.renderReadView = function (visible) {
  1026. var yearMonth = formatDate(_this.props.date, _this.props.dateFormat, _this.props.locale);
  1027. return React.createElement(
  1028. "div",
  1029. {
  1030. key: "read",
  1031. style: { visibility: visible ? "visible" : "hidden" },
  1032. className: "react-datepicker__month-year-read-view",
  1033. onClick: function onClick(event) {
  1034. return _this.toggleDropdown(event);
  1035. }
  1036. },
  1037. React.createElement("span", { className: "react-datepicker__month-year-read-view--down-arrow" }),
  1038. React.createElement(
  1039. "span",
  1040. { className: "react-datepicker__month-year-read-view--selected-month-year" },
  1041. yearMonth
  1042. )
  1043. );
  1044. }, _this.renderDropdown = function () {
  1045. return React.createElement(WrappedMonthYearDropdownOptions, {
  1046. key: "dropdown",
  1047. ref: "options",
  1048. date: _this.props.date,
  1049. dateFormat: _this.props.dateFormat,
  1050. onChange: _this.onChange,
  1051. onCancel: _this.toggleDropdown,
  1052. minDate: _this.props.minDate,
  1053. maxDate: _this.props.maxDate,
  1054. scrollableMonthYearDropdown: _this.props.scrollableMonthYearDropdown
  1055. });
  1056. }, _this.renderScrollMode = function () {
  1057. var dropdownVisible = _this.state.dropdownVisible;
  1058. var result = [_this.renderReadView(!dropdownVisible)];
  1059. if (dropdownVisible) {
  1060. result.unshift(_this.renderDropdown());
  1061. }
  1062. return result;
  1063. }, _this.onChange = function (monthYearPoint) {
  1064. _this.toggleDropdown();
  1065. var changedDate = newDate(parseInt(monthYearPoint));
  1066. if (isSameYear(_this.props.date, changedDate) && isSameMonth(_this.props.date, changedDate)) {
  1067. return;
  1068. }
  1069. _this.props.onChange(changedDate);
  1070. }, _this.toggleDropdown = function () {
  1071. return _this.setState({
  1072. dropdownVisible: !_this.state.dropdownVisible
  1073. });
  1074. }, _temp), possibleConstructorReturn(_this, _ret);
  1075. }
  1076. MonthYearDropdown.prototype.render = function render() {
  1077. var renderedDropdown = void 0;
  1078. switch (this.props.dropdownMode) {
  1079. case "scroll":
  1080. renderedDropdown = this.renderScrollMode();
  1081. break;
  1082. case "select":
  1083. renderedDropdown = this.renderSelectMode();
  1084. break;
  1085. }
  1086. return React.createElement(
  1087. "div",
  1088. {
  1089. className: "react-datepicker__month-year-dropdown-container react-datepicker__month-year-dropdown-container--" + this.props.dropdownMode
  1090. },
  1091. renderedDropdown
  1092. );
  1093. };
  1094. return MonthYearDropdown;
  1095. }(React.Component);
  1096. var Day = function (_React$Component) {
  1097. inherits(Day, _React$Component);
  1098. function Day() {
  1099. var _temp, _this, _ret;
  1100. classCallCheck(this, Day);
  1101. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1102. args[_key] = arguments[_key];
  1103. }
  1104. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function (event) {
  1105. if (!_this.isDisabled() && _this.props.onClick) {
  1106. _this.props.onClick(event);
  1107. }
  1108. }, _this.handleMouseEnter = function (event) {
  1109. if (!_this.isDisabled() && _this.props.onMouseEnter) {
  1110. _this.props.onMouseEnter(event);
  1111. }
  1112. }, _this.isSameDay = function (other) {
  1113. return isSameDay(_this.props.day, other);
  1114. }, _this.isKeyboardSelected = function () {
  1115. return !_this.props.disabledKeyboardNavigation && !_this.props.inline && !_this.isSameDay(_this.props.selected) && _this.isSameDay(_this.props.preSelection);
  1116. }, _this.isDisabled = function () {
  1117. return isDayDisabled(_this.props.day, _this.props);
  1118. }, _this.getHighLightedClass = function (defaultClassName) {
  1119. var _this$props = _this.props,
  1120. day = _this$props.day,
  1121. highlightDates = _this$props.highlightDates;
  1122. if (!highlightDates) {
  1123. return false;
  1124. }
  1125. // Looking for className in the Map of {'day string, 'className'}
  1126. var dayStr = formatDate(day, "MM.dd.yyyy");
  1127. return highlightDates.get(dayStr);
  1128. }, _this.isInRange = function () {
  1129. var _this$props2 = _this.props,
  1130. day = _this$props2.day,
  1131. startDate = _this$props2.startDate,
  1132. endDate = _this$props2.endDate;
  1133. if (!startDate || !endDate) {
  1134. return false;
  1135. }
  1136. return isDayInRange(day, startDate, endDate);
  1137. }, _this.isInSelectingRange = function () {
  1138. var _this$props3 = _this.props,
  1139. day = _this$props3.day,
  1140. selectsStart = _this$props3.selectsStart,
  1141. selectsEnd = _this$props3.selectsEnd,
  1142. selectingDate = _this$props3.selectingDate,
  1143. startDate = _this$props3.startDate,
  1144. endDate = _this$props3.endDate;
  1145. if (!(selectsStart || selectsEnd) || !selectingDate || _this.isDisabled()) {
  1146. return false;
  1147. }
  1148. if (selectsStart && endDate && (isBefore(selectingDate, endDate) || isEqual(selectingDate, endDate))) {
  1149. return isDayInRange(day, selectingDate, endDate);
  1150. }
  1151. if (selectsEnd && startDate && (isAfter(selectingDate, startDate) || isEqual(selectingDate, startDate))) {
  1152. return isDayInRange(day, startDate, selectingDate);
  1153. }
  1154. return false;
  1155. }, _this.isSelectingRangeStart = function () {
  1156. if (!_this.isInSelectingRange()) {
  1157. return false;
  1158. }
  1159. var _this$props4 = _this.props,
  1160. day = _this$props4.day,
  1161. selectingDate = _this$props4.selectingDate,
  1162. startDate = _this$props4.startDate,
  1163. selectsStart = _this$props4.selectsStart;
  1164. if (selectsStart) {
  1165. return isSameDay(day, selectingDate);
  1166. } else {
  1167. return isSameDay(day, startDate);
  1168. }
  1169. }, _this.isSelectingRangeEnd = function () {
  1170. if (!_this.isInSelectingRange()) {
  1171. return false;
  1172. }
  1173. var _this$props5 = _this.props,
  1174. day = _this$props5.day,
  1175. selectingDate = _this$props5.selectingDate,
  1176. endDate = _this$props5.endDate,
  1177. selectsEnd = _this$props5.selectsEnd;
  1178. if (selectsEnd) {
  1179. return isSameDay(day, selectingDate);
  1180. } else {
  1181. return isSameDay(day, endDate);
  1182. }
  1183. }, _this.isRangeStart = function () {
  1184. var _this$props6 = _this.props,
  1185. day = _this$props6.day,
  1186. startDate = _this$props6.startDate,
  1187. endDate = _this$props6.endDate;
  1188. if (!startDate || !endDate) {
  1189. return false;
  1190. }
  1191. return isSameDay(startDate, day);
  1192. }, _this.isRangeEnd = function () {
  1193. var _this$props7 = _this.props,
  1194. day = _this$props7.day,
  1195. startDate = _this$props7.startDate,
  1196. endDate = _this$props7.endDate;
  1197. if (!startDate || !endDate) {
  1198. return false;
  1199. }
  1200. return isSameDay(endDate, day);
  1201. }, _this.isWeekend = function () {
  1202. var weekday = getDay(_this.props.day);
  1203. return weekday === 0 || weekday === 6;
  1204. }, _this.isOutsideMonth = function () {
  1205. return _this.props.month !== undefined && _this.props.month !== getMonth(_this.props.day);
  1206. }, _this.getClassNames = function (date) {
  1207. var dayClassName = _this.props.dayClassName ? _this.props.dayClassName(date) : undefined;
  1208. return classnames("react-datepicker__day", dayClassName, "react-datepicker__day--" + getDayOfWeekCode(_this.props.day), {
  1209. "react-datepicker__day--disabled": _this.isDisabled(),
  1210. "react-datepicker__day--selected": _this.isSameDay(_this.props.selected),
  1211. "react-datepicker__day--keyboard-selected": _this.isKeyboardSelected(),
  1212. "react-datepicker__day--range-start": _this.isRangeStart(),
  1213. "react-datepicker__day--range-end": _this.isRangeEnd(),
  1214. "react-datepicker__day--in-range": _this.isInRange(),
  1215. "react-datepicker__day--in-selecting-range": _this.isInSelectingRange(),
  1216. "react-datepicker__day--selecting-range-start": _this.isSelectingRangeStart(),
  1217. "react-datepicker__day--selecting-range-end": _this.isSelectingRangeEnd(),
  1218. "react-datepicker__day--today": _this.isSameDay(newDate()),
  1219. "react-datepicker__day--weekend": _this.isWeekend(),
  1220. "react-datepicker__day--outside-month": _this.isOutsideMonth()
  1221. }, _this.getHighLightedClass("react-datepicker__day--highlighted"));
  1222. }, _temp), possibleConstructorReturn(_this, _ret);
  1223. }
  1224. Day.prototype.render = function render() {
  1225. return React.createElement(
  1226. "div",
  1227. {
  1228. className: this.getClassNames(this.props.day),
  1229. onClick: this.handleClick,
  1230. onMouseEnter: this.handleMouseEnter,
  1231. "aria-label": "day-" + getDate(this.props.day),
  1232. role: "option"
  1233. },
  1234. this.props.renderDayContents ? this.props.renderDayContents(getDate(this.props.day), this.props.day) : getDate(this.props.day)
  1235. );
  1236. };
  1237. return Day;
  1238. }(React.Component);
  1239. var WeekNumber = function (_React$Component) {
  1240. inherits(WeekNumber, _React$Component);
  1241. function WeekNumber() {
  1242. var _temp, _this, _ret;
  1243. classCallCheck(this, WeekNumber);
  1244. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1245. args[_key] = arguments[_key];
  1246. }
  1247. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function (event) {
  1248. if (_this.props.onClick) {
  1249. _this.props.onClick(event);
  1250. }
  1251. }, _temp), possibleConstructorReturn(_this, _ret);
  1252. }
  1253. WeekNumber.prototype.render = function render() {
  1254. var weekNumberClasses = {
  1255. "react-datepicker__week-number": true,
  1256. "react-datepicker__week-number--clickable": !!this.props.onClick
  1257. };
  1258. return React.createElement(
  1259. "div",
  1260. {
  1261. className: classnames(weekNumberClasses),
  1262. "aria-label": "week-" + this.props.weekNumber,
  1263. onClick: this.handleClick
  1264. },
  1265. this.props.weekNumber
  1266. );
  1267. };
  1268. return WeekNumber;
  1269. }(React.Component);
  1270. var Week = function (_React$Component) {
  1271. inherits(Week, _React$Component);
  1272. function Week() {
  1273. var _temp, _this, _ret;
  1274. classCallCheck(this, Week);
  1275. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1276. args[_key] = arguments[_key];
  1277. }
  1278. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleDayClick = function (day, event) {
  1279. if (_this.props.onDayClick) {
  1280. _this.props.onDayClick(day, event);
  1281. }
  1282. }, _this.handleDayMouseEnter = function (day) {
  1283. if (_this.props.onDayMouseEnter) {
  1284. _this.props.onDayMouseEnter(day);
  1285. }
  1286. }, _this.handleWeekClick = function (day, weekNumber, event) {
  1287. if (typeof _this.props.onWeekSelect === "function") {
  1288. _this.props.onWeekSelect(day, weekNumber, event);
  1289. }
  1290. if (_this.props.shouldCloseOnSelect) {
  1291. _this.props.setOpen(false);
  1292. }
  1293. }, _this.formatWeekNumber = function (date) {
  1294. if (_this.props.formatWeekNumber) {
  1295. return _this.props.formatWeekNumber(date);
  1296. }
  1297. return getWeek(date);
  1298. }, _this.renderDays = function () {
  1299. var startOfWeek$$1 = getStartOfWeek(_this.props.day, _this.props.locale);
  1300. var days = [];
  1301. var weekNumber = _this.formatWeekNumber(startOfWeek$$1);
  1302. if (_this.props.showWeekNumber) {
  1303. var onClickAction = _this.props.onWeekSelect ? _this.handleWeekClick.bind(_this, startOfWeek$$1, weekNumber) : undefined;
  1304. days.push(React.createElement(WeekNumber, { key: "W", weekNumber: weekNumber, onClick: onClickAction }));
  1305. }
  1306. return days.concat([0, 1, 2, 3, 4, 5, 6].map(function (offset) {
  1307. var day = addDays(startOfWeek$$1, offset);
  1308. return React.createElement(Day, {
  1309. key: offset,
  1310. day: day,
  1311. month: _this.props.month,
  1312. onClick: _this.handleDayClick.bind(_this, day),
  1313. onMouseEnter: _this.handleDayMouseEnter.bind(_this, day),
  1314. minDate: _this.props.minDate,
  1315. maxDate: _this.props.maxDate,
  1316. excludeDates: _this.props.excludeDates,
  1317. includeDates: _this.props.includeDates,
  1318. inline: _this.props.inline,
  1319. highlightDates: _this.props.highlightDates,
  1320. selectingDate: _this.props.selectingDate,
  1321. filterDate: _this.props.filterDate,
  1322. preSelection: _this.props.preSelection,
  1323. selected: _this.props.selected,
  1324. selectsStart: _this.props.selectsStart,
  1325. selectsEnd: _this.props.selectsEnd,
  1326. startDate: _this.props.startDate,
  1327. endDate: _this.props.endDate,
  1328. dayClassName: _this.props.dayClassName,
  1329. renderDayContents: _this.props.renderDayContents,
  1330. disabledKeyboardNavigation: _this.props.disabledKeyboardNavigation
  1331. });
  1332. }));
  1333. }, _temp), possibleConstructorReturn(_this, _ret);
  1334. }
  1335. Week.prototype.render = function render() {
  1336. return React.createElement(
  1337. "div",
  1338. { className: "react-datepicker__week" },
  1339. this.renderDays()
  1340. );
  1341. };
  1342. createClass(Week, null, [{
  1343. key: "defaultProps",
  1344. get: function get$$1() {
  1345. return {
  1346. shouldCloseOnSelect: true
  1347. };
  1348. }
  1349. }]);
  1350. return Week;
  1351. }(React.Component);
  1352. var FIXED_HEIGHT_STANDARD_WEEK_COUNT = 6;
  1353. var Month = function (_React$Component) {
  1354. inherits(Month, _React$Component);
  1355. function Month() {
  1356. var _temp, _this, _ret;
  1357. classCallCheck(this, Month);
  1358. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1359. args[_key] = arguments[_key];
  1360. }
  1361. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleDayClick = function (day, event) {
  1362. if (_this.props.onDayClick) {
  1363. _this.props.onDayClick(day, event, _this.props.orderInDisplay);
  1364. }
  1365. }, _this.handleDayMouseEnter = function (day) {
  1366. if (_this.props.onDayMouseEnter) {
  1367. _this.props.onDayMouseEnter(day);
  1368. }
  1369. }, _this.handleMouseLeave = function () {
  1370. if (_this.props.onMouseLeave) {
  1371. _this.props.onMouseLeave();
  1372. }
  1373. }, _this.isRangeStart = function (m) {
  1374. var _this$props = _this.props,
  1375. day = _this$props.day,
  1376. startDate = _this$props.startDate,
  1377. endDate = _this$props.endDate;
  1378. if (!startDate || !endDate) {
  1379. return false;
  1380. }
  1381. return isSameMonth(setMonth(day, m), startDate);
  1382. }, _this.isRangeEnd = function (m) {
  1383. var _this$props2 = _this.props,
  1384. day = _this$props2.day,
  1385. startDate = _this$props2.startDate,
  1386. endDate = _this$props2.endDate;
  1387. if (!startDate || !endDate) {
  1388. return false;
  1389. }
  1390. return isSameMonth(setMonth(day, m), endDate);
  1391. }, _this.isWeekInMonth = function (startOfWeek$$1) {
  1392. var day = _this.props.day;
  1393. var endOfWeek$$1 = addDays(startOfWeek$$1, 6);
  1394. return isSameMonth(startOfWeek$$1, day) || isSameMonth(endOfWeek$$1, day);
  1395. }, _this.renderWeeks = function () {
  1396. var weeks = [];
  1397. var isFixedHeight = _this.props.fixedHeight;
  1398. var currentWeekStart = getStartOfWeek(getStartOfMonth(_this.props.day), _this.props.locale);
  1399. var i = 0;
  1400. var breakAfterNextPush = false;
  1401. while (true) {
  1402. weeks.push(React.createElement(Week, {
  1403. key: i,
  1404. day: currentWeekStart,
  1405. month: getMonth(_this.props.day),
  1406. onDayClick: _this.handleDayClick,
  1407. onDayMouseEnter: _this.handleDayMouseEnter,
  1408. onWeekSelect: _this.props.onWeekSelect,
  1409. formatWeekNumber: _this.props.formatWeekNumber,
  1410. locale: _this.props.locale,
  1411. minDate: _this.props.minDate,
  1412. maxDate: _this.props.maxDate,
  1413. excludeDates: _this.props.excludeDates,
  1414. includeDates: _this.props.includeDates,
  1415. inline: _this.props.inline,
  1416. highlightDates: _this.props.highlightDates,
  1417. selectingDate: _this.props.selectingDate,
  1418. filterDate: _this.props.filterDate,
  1419. preSelection: _this.props.preSelection,
  1420. selected: _this.props.selected,
  1421. selectsStart: _this.props.selectsStart,
  1422. selectsEnd: _this.props.selectsEnd,
  1423. showWeekNumber: _this.props.showWeekNumbers,
  1424. startDate: _this.props.startDate,
  1425. endDate: _this.props.endDate,
  1426. dayClassName: _this.props.dayClassName,
  1427. setOpen: _this.props.setOpen,
  1428. shouldCloseOnSelect: _this.props.shouldCloseOnSelect,
  1429. disabledKeyboardNavigation: _this.props.disabledKeyboardNavigation,
  1430. renderDayContents: _this.props.renderDayContents
  1431. }));
  1432. if (breakAfterNextPush) break;
  1433. i++;
  1434. currentWeekStart = addWeeks(currentWeekStart, 1);
  1435. // If one of these conditions is true, we will either break on this week
  1436. // or break on the next week
  1437. var isFixedAndFinalWeek = isFixedHeight && i >= FIXED_HEIGHT_STANDARD_WEEK_COUNT;
  1438. var isNonFixedAndOutOfMonth = !isFixedHeight && !_this.isWeekInMonth(currentWeekStart);
  1439. if (isFixedAndFinalWeek || isNonFixedAndOutOfMonth) {
  1440. if (_this.props.peekNextMonth) {
  1441. breakAfterNextPush = true;
  1442. } else {
  1443. break;
  1444. }
  1445. }
  1446. }
  1447. return weeks;
  1448. }, _this.onMonthClick = function (e, m) {
  1449. _this.handleDayClick(getStartOfMonth(setMonth(_this.props.day, m), e));
  1450. }, _this.getMonthClassNames = function (m) {
  1451. var _this$props3 = _this.props,
  1452. day = _this$props3.day,
  1453. startDate = _this$props3.startDate,
  1454. endDate = _this$props3.endDate,
  1455. selected = _this$props3.selected,
  1456. minDate = _this$props3.minDate,
  1457. maxDate = _this$props3.maxDate;
  1458. return classnames("react-datepicker__month-text", "react-datepicker__month-" + m, {
  1459. "react-datepicker__month--disabled": (minDate || maxDate) && isMonthDisabled(setMonth(day, m), _this.props),
  1460. "react-datepicker__month--selected": getMonth(day) === m && getYear(day) === getYear(selected),
  1461. "react-datepicker__month--in-range": isMonthinRange(startDate, endDate, m, day),
  1462. "react-datepicker__month--range-start": _this.isRangeStart(m),
  1463. "react-datepicker__month--range-end": _this.isRangeEnd(m)
  1464. });
  1465. }, _this.renderMonths = function () {
  1466. var months = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]];
  1467. return months.map(function (month, i) {
  1468. return React.createElement(
  1469. "div",
  1470. { className: "react-datepicker__month-wrapper", key: i },
  1471. month.map(function (m, j) {
  1472. return React.createElement(
  1473. "div",
  1474. {
  1475. key: j,
  1476. onClick: function onClick(ev) {
  1477. _this.onMonthClick(ev.target, m);
  1478. },
  1479. className: _this.getMonthClassNames(m)
  1480. },
  1481. getMonthShortInLocale(m, _this.props.locale)
  1482. );
  1483. })
  1484. );
  1485. });
  1486. }, _this.getClassNames = function () {
  1487. var _this$props4 = _this.props,
  1488. selectingDate = _this$props4.selectingDate,
  1489. selectsStart = _this$props4.selectsStart,
  1490. selectsEnd = _this$props4.selectsEnd,
  1491. showMonthYearPicker = _this$props4.showMonthYearPicker;
  1492. return classnames("react-datepicker__month", {
  1493. "react-datepicker__month--selecting-range": selectingDate && (selectsStart || selectsEnd)
  1494. }, { "react-datepicker__monthPicker": showMonthYearPicker });
  1495. }, _temp), possibleConstructorReturn(_this, _ret);
  1496. }
  1497. Month.prototype.render = function render() {
  1498. var showMonthYearPicker = this.props.showMonthYearPicker;
  1499. return React.createElement(
  1500. "div",
  1501. {
  1502. className: this.getClassNames(),
  1503. onMouseLeave: this.handleMouseLeave,
  1504. role: "listbox",
  1505. "aria-label": "month-" + formatDate(this.props.day, "yyyy-MM")
  1506. },
  1507. showMonthYearPicker ? this.renderMonths() : this.renderWeeks()
  1508. );
  1509. };
  1510. return Month;
  1511. }(React.Component);
  1512. var Time = function (_React$Component) {
  1513. inherits(Time, _React$Component);
  1514. function Time() {
  1515. var _temp, _this, _ret;
  1516. classCallCheck(this, Time);
  1517. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1518. args[_key] = arguments[_key];
  1519. }
  1520. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  1521. height: null
  1522. }, _this.handleClick = function (time) {
  1523. if ((_this.props.minTime || _this.props.maxTime) && isTimeInDisabledRange(time, _this.props) || _this.props.excludeTimes && isTimeDisabled(time, _this.props.excludeTimes) || _this.props.includeTimes && !isTimeDisabled(time, _this.props.includeTimes)) {
  1524. return;
  1525. }
  1526. _this.props.onChange(time);
  1527. }, _this.liClasses = function (time, currH, currM) {
  1528. var classes = ["react-datepicker__time-list-item"];
  1529. if (currH === getHours(time) && currM === getMinutes(time)) {
  1530. classes.push("react-datepicker__time-list-item--selected");
  1531. }
  1532. if ((_this.props.minTime || _this.props.maxTime) && isTimeInDisabledRange(time, _this.props) || _this.props.excludeTimes && isTimeDisabled(time, _this.props.excludeTimes) || _this.props.includeTimes && !isTimeDisabled(time, _this.props.includeTimes)) {
  1533. classes.push("react-datepicker__time-list-item--disabled");
  1534. }
  1535. if (_this.props.injectTimes && (getHours(time) * 60 + getMinutes(time)) % _this.props.intervals !== 0) {
  1536. classes.push("react-datepicker__time-list-item--injected");
  1537. }
  1538. return classes.join(" ");
  1539. }, _this.renderTimes = function () {
  1540. var times = [];
  1541. var format$$1 = _this.props.format ? _this.props.format : "p";
  1542. var intervals = _this.props.intervals;
  1543. var activeTime = _this.props.selected ? _this.props.selected : newDate();
  1544. var currH = getHours(activeTime);
  1545. var currM = getMinutes(activeTime);
  1546. var base = getStartOfDay(newDate());
  1547. var multiplier = 1440 / intervals;
  1548. var sortedInjectTimes = _this.props.injectTimes && _this.props.injectTimes.sort(function (a, b) {
  1549. return a - b;
  1550. });
  1551. for (var i = 0; i < multiplier; i++) {
  1552. var currentTime = addMinutes(base, i * intervals);
  1553. times.push(currentTime);
  1554. if (sortedInjectTimes) {
  1555. var timesToInject = timesToInjectAfter(base, currentTime, i, intervals, sortedInjectTimes);
  1556. times = times.concat(timesToInject);
  1557. }
  1558. }
  1559. return times.map(function (time, i) {
  1560. return React.createElement(
  1561. "li",
  1562. {
  1563. key: i,
  1564. onClick: _this.handleClick.bind(_this, time),
  1565. className: _this.liClasses(time, currH, currM),
  1566. ref: function ref(li) {
  1567. if (currH === getHours(time) && currM === getMinutes(time) || currH === getHours(time) && !_this.centerLi) {
  1568. _this.centerLi = li;
  1569. }
  1570. }
  1571. },
  1572. formatDate(time, format$$1, _this.props.locale)
  1573. );
  1574. });
  1575. }, _temp), possibleConstructorReturn(_this, _ret);
  1576. }
  1577. Time.prototype.componentDidMount = function componentDidMount() {
  1578. // code to ensure selected time will always be in focus within time window when it first appears
  1579. this.list.scrollTop = Time.calcCenterPosition(this.props.monthRef ? this.props.monthRef.clientHeight - this.header.clientHeight : this.list.clientHeight, this.centerLi);
  1580. if (this.props.monthRef && this.header) {
  1581. this.setState({
  1582. height: this.props.monthRef.clientHeight - this.header.clientHeight
  1583. });
  1584. }
  1585. };
  1586. Time.prototype.render = function render() {
  1587. var _this2 = this;
  1588. var height = this.state.height;
  1589. return React.createElement(
  1590. "div",
  1591. {
  1592. className: "react-datepicker__time-container " + (this.props.todayButton ? "react-datepicker__time-container--with-today-button" : "")
  1593. },
  1594. React.createElement(
  1595. "div",
  1596. {
  1597. className: "react-datepicker__header react-datepicker__header--time",
  1598. ref: function ref(header) {
  1599. _this2.header = header;
  1600. }
  1601. },
  1602. React.createElement(
  1603. "div",
  1604. { className: "react-datepicker-time__header" },
  1605. this.props.timeCaption
  1606. )
  1607. ),
  1608. React.createElement(
  1609. "div",
  1610. { className: "react-datepicker__time" },
  1611. React.createElement(
  1612. "div",
  1613. { className: "react-datepicker__time-box" },
  1614. React.createElement(
  1615. "ul",
  1616. {
  1617. className: "react-datepicker__time-list",
  1618. ref: function ref(list) {
  1619. _this2.list = list;
  1620. },
  1621. style: height ? { height: height } : {}
  1622. },
  1623. this.renderTimes.bind(this)()
  1624. )
  1625. )
  1626. )
  1627. );
  1628. };
  1629. createClass(Time, null, [{
  1630. key: "defaultProps",
  1631. get: function get$$1() {
  1632. return {
  1633. intervals: 30,
  1634. onTimeChange: function onTimeChange() {},
  1635. todayButton: null,
  1636. timeCaption: "Time"
  1637. };
  1638. }
  1639. }]);
  1640. return Time;
  1641. }(React.Component);
  1642. Time.calcCenterPosition = function (listHeight, centerLiRef) {
  1643. return centerLiRef.offsetTop - (listHeight / 2 - centerLiRef.clientHeight / 2);
  1644. };
  1645. var inputTime = function (_React$Component) {
  1646. inherits(inputTime, _React$Component);
  1647. function inputTime(props) {
  1648. classCallCheck(this, inputTime);
  1649. var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
  1650. _this.onTimeChange = function (time) {
  1651. _this.setState({ time: time });
  1652. var date = new Date();
  1653. date.setHours(time.split(":")[0]);
  1654. date.setMinutes(time.split(":")[1]);
  1655. _this.props.onChange(date);
  1656. };
  1657. _this.state = {
  1658. time: _this.props.timeString
  1659. };
  1660. return _this;
  1661. }
  1662. inputTime.prototype.render = function render() {
  1663. var _this2 = this;
  1664. var time = this.state.time;
  1665. var timeString = this.props.timeString;
  1666. return React.createElement(
  1667. "div",
  1668. { className: "react-datepicker__input-time-container" },
  1669. React.createElement(
  1670. "div",
  1671. { className: "react-datepicker-time__caption" },
  1672. this.props.timeInputLabel
  1673. ),
  1674. React.createElement(
  1675. "div",
  1676. { className: "react-datepicker-time__input-container" },
  1677. React.createElement(
  1678. "div",
  1679. { className: "react-datepicker-time__input" },
  1680. React.createElement("input", {
  1681. type: "time",
  1682. className: "react-datepicker-time__input",
  1683. placeholder: "Time",
  1684. name: "time-input",
  1685. required: true,
  1686. value: time,
  1687. onChange: function onChange(ev) {
  1688. _this2.onTimeChange(ev.target.value || timeString);
  1689. }
  1690. })
  1691. )
  1692. )
  1693. );
  1694. };
  1695. return inputTime;
  1696. }(React.Component);
  1697. function CalendarContainer(_ref) {
  1698. var className = _ref.className,
  1699. children = _ref.children,
  1700. _ref$arrowProps = _ref.arrowProps,
  1701. arrowProps = _ref$arrowProps === undefined ? {} : _ref$arrowProps;
  1702. return React.createElement(
  1703. "div",
  1704. { className: className },
  1705. React.createElement("div", _extends({ className: "react-datepicker__triangle" }, arrowProps)),
  1706. children
  1707. );
  1708. }
  1709. var DROPDOWN_FOCUS_CLASSNAMES = ["react-datepicker__year-select", "react-datepicker__month-select", "react-datepicker__month-year-select"];
  1710. var isDropdownSelect = function isDropdownSelect() {
  1711. var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1712. var classNames = (element.className || "").split(/\s+/);
  1713. return DROPDOWN_FOCUS_CLASSNAMES.some(function (testClassname) {
  1714. return classNames.indexOf(testClassname) >= 0;
  1715. });
  1716. };
  1717. var Calendar = function (_React$Component) {
  1718. inherits(Calendar, _React$Component);
  1719. createClass(Calendar, null, [{
  1720. key: "defaultProps",
  1721. get: function get$$1() {
  1722. return {
  1723. onDropdownFocus: function onDropdownFocus() {},
  1724. monthsShown: 1,
  1725. monthSelectedIn: 0,
  1726. forceShowMonthNavigation: false,
  1727. timeCaption: "Time",
  1728. previousYearButtonLabel: "Previous Year",
  1729. nextYearButtonLabel: "Next Year",
  1730. previousMonthButtonLabel: "Previous Month",
  1731. nextMonthButtonLabel: "Next Month"
  1732. };
  1733. }
  1734. }]);
  1735. function Calendar(props) {
  1736. classCallCheck(this, Calendar);
  1737. var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
  1738. _this.handleClickOutside = function (event) {
  1739. _this.props.onClickOutside(event);
  1740. };
  1741. _this.handleDropdownFocus = function (event) {
  1742. if (isDropdownSelect(event.target)) {
  1743. _this.props.onDropdownFocus();
  1744. }
  1745. };
  1746. _this.getDateInView = function () {
  1747. var _this$props = _this.props,
  1748. preSelection = _this$props.preSelection,
  1749. selected = _this$props.selected,
  1750. openToDate = _this$props.openToDate;
  1751. var minDate = getEffectiveMinDate(_this.props);
  1752. var maxDate = getEffectiveMaxDate(_this.props);
  1753. var current = newDate();
  1754. var initialDate = openToDate || selected || preSelection;
  1755. if (initialDate) {
  1756. return initialDate;
  1757. } else {
  1758. if (minDate && isBefore(current, minDate)) {
  1759. return minDate;
  1760. } else if (maxDate && isAfter(current, maxDate)) {
  1761. return maxDate;
  1762. }
  1763. }
  1764. return current;
  1765. };
  1766. _this.increaseMonth = function () {
  1767. _this.setState({
  1768. date: addMonths(_this.state.date, 1)
  1769. }, function () {
  1770. return _this.handleMonthChange(_this.state.date);
  1771. });
  1772. };
  1773. _this.decreaseMonth = function () {
  1774. _this.setState({
  1775. date: subMonths(_this.state.date, 1)
  1776. }, function () {
  1777. return _this.handleMonthChange(_this.state.date);
  1778. });
  1779. };
  1780. _this.handleDayClick = function (day, event, monthSelectedIn) {
  1781. return _this.props.onSelect(day, event, monthSelectedIn);
  1782. };
  1783. _this.handleDayMouseEnter = function (day) {
  1784. _this.setState({ selectingDate: day });
  1785. _this.props.onDayMouseEnter && _this.props.onDayMouseEnter(day);
  1786. };
  1787. _this.handleMonthMouseLeave = function () {
  1788. _this.setState({ selectingDate: null });
  1789. _this.props.onMonthMouseLeave && _this.props.onMonthMouseLeave();
  1790. };
  1791. _this.handleYearChange = function (date) {
  1792. if (_this.props.onYearChange) {
  1793. _this.props.onYearChange(date);
  1794. }
  1795. };
  1796. _this.handleMonthChange = function (date) {
  1797. if (_this.props.onMonthChange) {
  1798. _this.props.onMonthChange(date);
  1799. }
  1800. if (_this.props.adjustDateOnChange) {
  1801. if (_this.props.onSelect) {
  1802. _this.props.onSelect(date);
  1803. }
  1804. if (_this.props.setOpen) {
  1805. _this.props.setOpen(true);
  1806. }
  1807. }
  1808. };
  1809. _this.handleMonthYearChange = function (date) {
  1810. _this.handleYearChange(date);
  1811. _this.handleMonthChange(date);
  1812. };
  1813. _this.changeYear = function (year) {
  1814. _this.setState({
  1815. date: setYear(_this.state.date, year)
  1816. }, function () {
  1817. return _this.handleYearChange(_this.state.date);
  1818. });
  1819. };
  1820. _this.changeMonth = function (month) {
  1821. _this.setState({
  1822. date: setMonth(_this.state.date, month)
  1823. }, function () {
  1824. return _this.handleMonthChange(_this.state.date);
  1825. });
  1826. };
  1827. _this.changeMonthYear = function (monthYear) {
  1828. _this.setState({
  1829. date: setYear(setMonth(_this.state.date, getMonth(monthYear)), getYear(monthYear))
  1830. }, function () {
  1831. return _this.handleMonthYearChange(_this.state.date);
  1832. });
  1833. };
  1834. _this.header = function () {
  1835. var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.state.date;
  1836. var startOfWeek$$1 = getStartOfWeek(date, _this.props.locale);
  1837. var dayNames = [];
  1838. if (_this.props.showWeekNumbers) {
  1839. dayNames.push(React.createElement(
  1840. "div",
  1841. { key: "W", className: "react-datepicker__day-name" },
  1842. _this.props.weekLabel || "#"
  1843. ));
  1844. }
  1845. return dayNames.concat([0, 1, 2, 3, 4, 5, 6].map(function (offset) {
  1846. var day = addDays(startOfWeek$$1, offset);
  1847. var weekDayName = _this.formatWeekday(day, _this.props.locale);
  1848. return React.createElement(
  1849. "div",
  1850. { key: offset, className: "react-datepicker__day-name" },
  1851. weekDayName
  1852. );
  1853. }));
  1854. };
  1855. _this.formatWeekday = function (day, locale) {
  1856. if (_this.props.formatWeekDay) {
  1857. return getFormattedWeekdayInLocale(day, _this.props.formatWeekDay, locale);
  1858. }
  1859. return _this.props.useWeekdaysShort ? getWeekdayShortInLocale(day, locale) : getWeekdayMinInLocale(day, locale);
  1860. };
  1861. _this.decreaseYear = function () {
  1862. _this.setState({
  1863. date: subYears(_this.state.date, 1)
  1864. }, function () {
  1865. return _this.handleYearChange(_this.state.date);
  1866. });
  1867. };
  1868. _this.renderPreviousButton = function () {
  1869. if (_this.props.renderCustomHeader) {
  1870. return;
  1871. }
  1872. var allPrevDaysDisabled = monthDisabledBefore(_this.state.date, _this.props);
  1873. if (!_this.props.forceShowMonthNavigation && !_this.props.showDisabledMonthNavigation && allPrevDaysDisabled || _this.props.showTimeSelectOnly) {
  1874. return;
  1875. }
  1876. var classes = ["react-datepicker__navigation", "react-datepicker__navigation--previous"];
  1877. var clickHandler = _this.decreaseMonth;
  1878. if (_this.props.showMonthYearPicker) {
  1879. clickHandler = _this.decreaseYear;
  1880. }
  1881. if (allPrevDaysDisabled && _this.props.showDisabledMonthNavigation) {
  1882. classes.push("react-datepicker__navigation--previous--disabled");
  1883. clickHandler = null;
  1884. }
  1885. return React.createElement(
  1886. "button",
  1887. {
  1888. type: "button",
  1889. className: classes.join(" "),
  1890. onClick: clickHandler
  1891. },
  1892. _this.props.showMonthYearPicker ? _this.props.previousYearButtonLabel : _this.props.previousMonthButtonLabel
  1893. );
  1894. };
  1895. _this.increaseYear = function () {
  1896. _this.setState({
  1897. date: addYears(_this.state.date, 1)
  1898. }, function () {
  1899. return _this.handleYearChange(_this.state.date);
  1900. });
  1901. };
  1902. _this.renderNextButton = function () {
  1903. if (_this.props.renderCustomHeader) {
  1904. return;
  1905. }
  1906. var allNextDaysDisabled = monthDisabledAfter(_this.state.date, _this.props);
  1907. if (!_this.props.forceShowMonthNavigation && !_this.props.showDisabledMonthNavigation && allNextDaysDisabled || _this.props.showTimeSelectOnly) {
  1908. return;
  1909. }
  1910. var classes = ["react-datepicker__navigation", "react-datepicker__navigation--next"];
  1911. if (_this.props.showTimeSelect) {
  1912. classes.push("react-datepicker__navigation--next--with-time");
  1913. }
  1914. if (_this.props.todayButton) {
  1915. classes.push("react-datepicker__navigation--next--with-today-button");
  1916. }
  1917. var clickHandler = _this.increaseMonth;
  1918. if (_this.props.showMonthYearPicker) {
  1919. clickHandler = _this.increaseYear;
  1920. }
  1921. if (allNextDaysDisabled && _this.props.showDisabledMonthNavigation) {
  1922. classes.push("react-datepicker__navigation--next--disabled");
  1923. clickHandler = null;
  1924. }
  1925. return React.createElement(
  1926. "button",
  1927. {
  1928. type: "button",
  1929. className: classes.join(" "),
  1930. onClick: clickHandler
  1931. },
  1932. _this.props.showMonthYearPicker ? _this.props.nextYearButtonLabel : _this.props.nextMonthButtonLabel
  1933. );
  1934. };
  1935. _this.renderCurrentMonth = function () {
  1936. var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.state.date;
  1937. var classes = ["react-datepicker__current-month"];
  1938. if (_this.props.showYearDropdown) {
  1939. classes.push("react-datepicker__current-month--hasYearDropdown");
  1940. }
  1941. if (_this.props.showMonthDropdown) {
  1942. classes.push("react-datepicker__current-month--hasMonthDropdown");
  1943. }
  1944. if (_this.props.showMonthYearDropdown) {
  1945. classes.push("react-datepicker__current-month--hasMonthYearDropdown");
  1946. }
  1947. return React.createElement(
  1948. "div",
  1949. { className: classes.join(" ") },
  1950. formatDate(date, _this.props.dateFormat, _this.props.locale)
  1951. );
  1952. };
  1953. _this.renderYearDropdown = function () {
  1954. var overrideHide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1955. if (!_this.props.showYearDropdown || overrideHide) {
  1956. return;
  1957. }
  1958. return React.createElement(YearDropdown, {
  1959. adjustDateOnChange: _this.props.adjustDateOnChange,
  1960. date: _this.state.date,
  1961. onSelect: _this.props.onSelect,
  1962. setOpen: _this.props.setOpen,
  1963. dropdownMode: _this.props.dropdownMode,
  1964. onChange: _this.changeYear,
  1965. minDate: _this.props.minDate,
  1966. maxDate: _this.props.maxDate,
  1967. year: getYear(_this.state.date),
  1968. scrollableYearDropdown: _this.props.scrollableYearDropdown,
  1969. yearDropdownItemNumber: _this.props.yearDropdownItemNumber
  1970. });
  1971. };
  1972. _this.renderMonthDropdown = function () {
  1973. var overrideHide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1974. if (!_this.props.showMonthDropdown || overrideHide) {
  1975. return;
  1976. }
  1977. return React.createElement(MonthDropdown, {
  1978. dropdownMode: _this.props.dropdownMode,
  1979. locale: _this.props.locale,
  1980. onChange: _this.changeMonth,
  1981. month: getMonth(_this.state.date),
  1982. useShortMonthInDropdown: _this.props.useShortMonthInDropdown
  1983. });
  1984. };
  1985. _this.renderMonthYearDropdown = function () {
  1986. var overrideHide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1987. if (!_this.props.showMonthYearDropdown || overrideHide) {
  1988. return;
  1989. }
  1990. return React.createElement(MonthYearDropdown, {
  1991. dropdownMode: _this.props.dropdownMode,
  1992. locale: _this.props.locale,
  1993. dateFormat: _this.props.dateFormat,
  1994. onChange: _this.changeMonthYear,
  1995. minDate: _this.props.minDate,
  1996. maxDate: _this.props.maxDate,
  1997. date: _this.state.date,
  1998. scrollableMonthYearDropdown: _this.props.scrollableMonthYearDropdown
  1999. });
  2000. };
  2001. _this.renderTodayButton = function () {
  2002. if (!_this.props.todayButton || _this.props.showTimeSelectOnly) {
  2003. return;
  2004. }
  2005. return React.createElement(
  2006. "div",
  2007. {
  2008. className: "react-datepicker__today-button",
  2009. onClick: function onClick(e) {
  2010. return _this.props.onSelect(getStartOfToday(), e);
  2011. }
  2012. },
  2013. _this.props.todayButton
  2014. );
  2015. };
  2016. _this.renderDefaultHeader = function (_ref) {
  2017. var monthDate = _ref.monthDate,
  2018. i = _ref.i;
  2019. return React.createElement(
  2020. "div",
  2021. { className: "react-datepicker__header" },
  2022. _this.renderCurrentMonth(monthDate),
  2023. React.createElement(
  2024. "div",
  2025. {
  2026. className: "react-datepicker__header__dropdown react-datepicker__header__dropdown--" + _this.props.dropdownMode,
  2027. onFocus: _this.handleDropdownFocus
  2028. },
  2029. _this.renderMonthDropdown(i !== 0),
  2030. _this.renderMonthYearDropdown(i !== 0),
  2031. _this.renderYearDropdown(i !== 0)
  2032. ),
  2033. React.createElement(
  2034. "div",
  2035. { className: "react-datepicker__day-names" },
  2036. _this.header(monthDate)
  2037. )
  2038. );
  2039. };
  2040. _this.renderCustomHeader = function (_ref2) {
  2041. var monthDate = _ref2.monthDate,
  2042. i = _ref2.i;
  2043. if (i !== 0) {
  2044. return null;
  2045. }
  2046. var prevMonthButtonDisabled = monthDisabledBefore(_this.state.date, _this.props);
  2047. var nextMonthButtonDisabled = monthDisabledAfter(_this.state.date, _this.props);
  2048. return React.createElement(
  2049. "div",
  2050. {
  2051. className: "react-datepicker__header react-datepicker__header--custom",
  2052. onFocus: _this.props.onDropdownFocus
  2053. },
  2054. _this.props.renderCustomHeader(_extends({}, _this.state, {
  2055. changeMonth: _this.changeMonth,
  2056. changeYear: _this.changeYear,
  2057. decreaseMonth: _this.decreaseMonth,
  2058. increaseMonth: _this.increaseMonth,
  2059. prevMonthButtonDisabled: prevMonthButtonDisabled,
  2060. nextMonthButtonDisabled: nextMonthButtonDisabled
  2061. })),
  2062. React.createElement(
  2063. "div",
  2064. { className: "react-datepicker__day-names" },
  2065. _this.header(monthDate)
  2066. )
  2067. );
  2068. };
  2069. _this.renderYearHeader = function () {
  2070. return React.createElement(
  2071. "div",
  2072. { className: "react-datepicker__header react-datepicker-year-header" },
  2073. getYear(_this.state.date)
  2074. );
  2075. };
  2076. _this.renderMonths = function () {
  2077. if (_this.props.showTimeSelectOnly) {
  2078. return;
  2079. }
  2080. var monthList = [];
  2081. for (var i = 0; i < _this.props.monthsShown; ++i) {
  2082. var monthsToAdd = i - _this.props.monthSelectedIn;
  2083. var monthDate = addMonths(_this.state.date, monthsToAdd);
  2084. var monthKey = "month-" + i;
  2085. monthList.push(React.createElement(
  2086. "div",
  2087. {
  2088. key: monthKey,
  2089. ref: function ref(div) {
  2090. _this.monthContainer = div;
  2091. },
  2092. className: "react-datepicker__month-container"
  2093. },
  2094. !_this.props.showMonthYearPicker ? _this.props.renderCustomHeader ? _this.renderCustomHeader({ monthDate: monthDate, i: i }) : _this.renderDefaultHeader({ monthDate: monthDate, i: i }) : _this.renderYearHeader({ monthDate: monthDate, i: i }),
  2095. React.createElement(Month, {
  2096. onChange: _this.changeMonthYear,
  2097. day: monthDate,
  2098. dayClassName: _this.props.dayClassName,
  2099. onDayClick: _this.handleDayClick,
  2100. onDayMouseEnter: _this.handleDayMouseEnter,
  2101. onMouseLeave: _this.handleMonthMouseLeave,
  2102. onWeekSelect: _this.props.onWeekSelect,
  2103. orderInDisplay: i,
  2104. formatWeekNumber: _this.props.formatWeekNumber,
  2105. locale: _this.props.locale,
  2106. minDate: _this.props.minDate,
  2107. maxDate: _this.props.maxDate,
  2108. excludeDates: _this.props.excludeDates,
  2109. highlightDates: _this.props.highlightDates,
  2110. selectingDate: _this.state.selectingDate,
  2111. includeDates: _this.props.includeDates,
  2112. inline: _this.props.inline,
  2113. fixedHeight: _this.props.fixedHeight,
  2114. filterDate: _this.props.filterDate,
  2115. preSelection: _this.props.preSelection,
  2116. selected: _this.props.selected,
  2117. selectsStart: _this.props.selectsStart,
  2118. selectsEnd: _this.props.selectsEnd,
  2119. showWeekNumbers: _this.props.showWeekNumbers,
  2120. startDate: _this.props.startDate,
  2121. endDate: _this.props.endDate,
  2122. peekNextMonth: _this.props.peekNextMonth,
  2123. setOpen: _this.props.setOpen,
  2124. shouldCloseOnSelect: _this.props.shouldCloseOnSelect,
  2125. renderDayContents: _this.props.renderDayContents,
  2126. disabledKeyboardNavigation: _this.props.disabledKeyboardNavigation,
  2127. showMonthYearPicker: _this.props.showMonthYearPicker
  2128. })
  2129. ));
  2130. }
  2131. return monthList;
  2132. };
  2133. _this.renderTimeSection = function () {
  2134. if (_this.props.showTimeSelect && (_this.state.monthContainer || _this.props.showTimeSelectOnly)) {
  2135. return React.createElement(Time, {
  2136. selected: _this.props.selected,
  2137. onChange: _this.props.onTimeChange,
  2138. format: _this.props.timeFormat,
  2139. includeTimes: _this.props.includeTimes,
  2140. intervals: _this.props.timeIntervals,
  2141. minTime: _this.props.minTime,
  2142. maxTime: _this.props.maxTime,
  2143. excludeTimes: _this.props.excludeTimes,
  2144. timeCaption: _this.props.timeCaption,
  2145. todayButton: _this.props.todayButton,
  2146. showMonthDropdown: _this.props.showMonthDropdown,
  2147. showMonthYearDropdown: _this.props.showMonthYearDropdown,
  2148. showYearDropdown: _this.props.showYearDropdown,
  2149. withPortal: _this.props.withPortal,
  2150. monthRef: _this.state.monthContainer,
  2151. injectTimes: _this.props.injectTimes,
  2152. locale: _this.props.locale
  2153. });
  2154. }
  2155. };
  2156. _this.renderInputTimeSection = function () {
  2157. var time = new Date(_this.props.selected);
  2158. var timeString = addZero(time.getHours()) + ":" + addZero(time.getMinutes());
  2159. if (_this.props.showTimeInput) {
  2160. return React.createElement(inputTime, {
  2161. timeString: timeString,
  2162. timeInputLabel: _this.props.timeInputLabel,
  2163. onChange: _this.props.onTimeChange
  2164. });
  2165. }
  2166. };
  2167. _this.state = {
  2168. date: _this.getDateInView(),
  2169. selectingDate: null,
  2170. monthContainer: null
  2171. };
  2172. return _this;
  2173. }
  2174. Calendar.prototype.componentDidMount = function componentDidMount() {
  2175. var _this2 = this;
  2176. // monthContainer height is needed in time component
  2177. // to determine the height for the ul in the time component
  2178. // setState here so height is given after final component
  2179. // layout is rendered
  2180. if (this.props.showTimeSelect) {
  2181. this.assignMonthContainer = function () {
  2182. _this2.setState({ monthContainer: _this2.monthContainer });
  2183. }();
  2184. }
  2185. };
  2186. Calendar.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
  2187. if (this.props.preSelection && !isSameDay(this.props.preSelection, prevProps.preSelection)) {
  2188. this.setState({
  2189. date: this.props.preSelection
  2190. });
  2191. } else if (this.props.openToDate && !isSameDay(this.props.openToDate, prevProps.openToDate)) {
  2192. this.setState({
  2193. date: this.props.openToDate
  2194. });
  2195. }
  2196. };
  2197. Calendar.prototype.render = function render() {
  2198. var Container = this.props.container || CalendarContainer;
  2199. return React.createElement(
  2200. Container,
  2201. {
  2202. className: classnames("react-datepicker", this.props.className, {
  2203. "react-datepicker--time-only": this.props.showTimeSelectOnly
  2204. })
  2205. },
  2206. this.renderPreviousButton(),
  2207. this.renderNextButton(),
  2208. this.renderMonths(),
  2209. this.renderTodayButton(),
  2210. this.renderTimeSection(),
  2211. this.renderInputTimeSection(),
  2212. this.props.children
  2213. );
  2214. };
  2215. return Calendar;
  2216. }(React.Component);
  2217. var PopperComponent = function (_React$Component) {
  2218. inherits(PopperComponent, _React$Component);
  2219. function PopperComponent() {
  2220. classCallCheck(this, PopperComponent);
  2221. return possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  2222. }
  2223. PopperComponent.prototype.render = function render() {
  2224. var _props = this.props,
  2225. className = _props.className,
  2226. hidePopper = _props.hidePopper,
  2227. popperComponent = _props.popperComponent,
  2228. popperModifiers = _props.popperModifiers,
  2229. popperPlacement = _props.popperPlacement,
  2230. popperProps = _props.popperProps,
  2231. targetComponent = _props.targetComponent;
  2232. var popper = void 0;
  2233. if (!hidePopper) {
  2234. var classes = classnames("react-datepicker-popper", className);
  2235. popper = React.createElement(
  2236. Popper,
  2237. _extends({
  2238. modifiers: popperModifiers,
  2239. placement: popperPlacement
  2240. }, popperProps),
  2241. function (_ref) {
  2242. var ref = _ref.ref,
  2243. style = _ref.style,
  2244. placement = _ref.placement,
  2245. arrowProps = _ref.arrowProps;
  2246. return React.createElement(
  2247. "div",
  2248. _extends({ ref: ref, style: style }, {
  2249. className: classes,
  2250. "data-placement": placement
  2251. }),
  2252. React.cloneElement(popperComponent, { arrowProps: arrowProps })
  2253. );
  2254. }
  2255. );
  2256. }
  2257. if (this.props.popperContainer) {
  2258. popper = React.createElement(this.props.popperContainer, {}, popper);
  2259. }
  2260. return React.createElement(
  2261. Manager,
  2262. null,
  2263. React.createElement(
  2264. Reference,
  2265. null,
  2266. function (_ref2) {
  2267. var ref = _ref2.ref;
  2268. return React.createElement(
  2269. "div",
  2270. { ref: ref, className: "react-datepicker-wrapper" },
  2271. targetComponent
  2272. );
  2273. }
  2274. ),
  2275. popper
  2276. );
  2277. };
  2278. createClass(PopperComponent, null, [{
  2279. key: "defaultProps",
  2280. get: function get$$1() {
  2281. return {
  2282. hidePopper: true,
  2283. popperModifiers: {
  2284. preventOverflow: {
  2285. enabled: true,
  2286. escapeWithReference: true,
  2287. boundariesElement: "viewport"
  2288. }
  2289. },
  2290. popperProps: {},
  2291. popperPlacement: "bottom-start"
  2292. };
  2293. }
  2294. }]);
  2295. return PopperComponent;
  2296. }(React.Component);
  2297. var outsideClickIgnoreClass = "react-datepicker-ignore-onclickoutside";
  2298. var WrappedCalendar = onClickOutside(Calendar);
  2299. // Compares dates year+month combinations
  2300. function hasPreSelectionChanged(date1, date2) {
  2301. if (date1 && date2) {
  2302. return getMonth(date1) !== getMonth(date2) || getYear(date1) !== getYear(date2);
  2303. }
  2304. return date1 !== date2;
  2305. }
  2306. /**
  2307. * General datepicker component.
  2308. */
  2309. var INPUT_ERR_1 = "Date input not valid.";
  2310. var DatePicker = function (_React$Component) {
  2311. inherits(DatePicker, _React$Component);
  2312. createClass(DatePicker, null, [{
  2313. key: "defaultProps",
  2314. get: function get$$1() {
  2315. return {
  2316. allowSameDay: false,
  2317. dateFormat: "MM/dd/yyyy",
  2318. dateFormatCalendar: "LLLL yyyy",
  2319. onChange: function onChange() {},
  2320. disabled: false,
  2321. disabledKeyboardNavigation: false,
  2322. dropdownMode: "scroll",
  2323. onFocus: function onFocus() {},
  2324. onBlur: function onBlur() {},
  2325. onKeyDown: function onKeyDown() {},
  2326. onInputClick: function onInputClick() {},
  2327. onSelect: function onSelect() {},
  2328. onClickOutside: function onClickOutside$$1() {},
  2329. onMonthChange: function onMonthChange() {},
  2330. preventOpenOnFocus: false,
  2331. onYearChange: function onYearChange() {},
  2332. onInputError: function onInputError() {},
  2333. monthsShown: 1,
  2334. readOnly: false,
  2335. withPortal: false,
  2336. shouldCloseOnSelect: true,
  2337. showTimeSelect: false,
  2338. showTimeInput: false,
  2339. showMonthYearPicker: false,
  2340. strictParsing: false,
  2341. timeIntervals: 30,
  2342. timeCaption: "Time",
  2343. previousMonthButtonLabel: "Previous Month",
  2344. nextMonthButtonLabel: "Next month",
  2345. timeInputLabel: "Time",
  2346. renderDayContents: function renderDayContents(date) {
  2347. return date;
  2348. },
  2349. inlineFocusSelectedMonth: false
  2350. };
  2351. }
  2352. }]);
  2353. function DatePicker(props) {
  2354. classCallCheck(this, DatePicker);
  2355. var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
  2356. _this.getPreSelection = function () {
  2357. return _this.props.openToDate ? _this.props.openToDate : _this.props.selectsEnd && _this.props.startDate ? _this.props.startDate : _this.props.selectsStart && _this.props.endDate ? _this.props.endDate : newDate();
  2358. };
  2359. _this.calcInitialState = function () {
  2360. var defaultPreSelection = _this.getPreSelection();
  2361. var minDate = getEffectiveMinDate(_this.props);
  2362. var maxDate = getEffectiveMaxDate(_this.props);
  2363. var boundedPreSelection = minDate && isBefore(defaultPreSelection, minDate) ? minDate : maxDate && isAfter(defaultPreSelection, maxDate) ? maxDate : defaultPreSelection;
  2364. return {
  2365. open: _this.props.startOpen || false,
  2366. preventFocus: false,
  2367. preSelection: _this.props.selected ? _this.props.selected : boundedPreSelection,
  2368. // transforming highlighted days (perhaps nested array)
  2369. // to flat Map for faster access in day.jsx
  2370. highlightDates: getHightLightDaysMap(_this.props.highlightDates),
  2371. focused: false
  2372. };
  2373. };
  2374. _this.clearPreventFocusTimeout = function () {
  2375. if (_this.preventFocusTimeout) {
  2376. clearTimeout(_this.preventFocusTimeout);
  2377. }
  2378. };
  2379. _this.setFocus = function () {
  2380. if (_this.input && _this.input.focus) {
  2381. _this.input.focus();
  2382. }
  2383. };
  2384. _this.setBlur = function () {
  2385. if (_this.input && _this.input.blur) {
  2386. _this.input.blur();
  2387. }
  2388. _this.cancelFocusInput();
  2389. };
  2390. _this.setOpen = function (open) {
  2391. var skipSetBlur = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2392. _this.setState({
  2393. open: open,
  2394. preSelection: open && _this.state.open ? _this.state.preSelection : _this.calcInitialState().preSelection,
  2395. lastPreSelectChange: PRESELECT_CHANGE_VIA_NAVIGATE
  2396. }, function () {
  2397. if (!open) {
  2398. _this.setState(function (prev) {
  2399. return {
  2400. focused: skipSetBlur ? prev.focused : false
  2401. };
  2402. }, function () {
  2403. !skipSetBlur && _this.setBlur();
  2404. _this.setState({ inputValue: null });
  2405. });
  2406. }
  2407. });
  2408. };
  2409. _this.inputOk = function () {
  2410. return isDate(_this.state.preSelection);
  2411. };
  2412. _this.isCalendarOpen = function () {
  2413. return _this.props.open === undefined ? _this.state.open && !_this.props.disabled && !_this.props.readOnly : _this.props.open;
  2414. };
  2415. _this.handleFocus = function (event) {
  2416. if (!_this.state.preventFocus) {
  2417. _this.props.onFocus(event);
  2418. if (!_this.props.preventOpenOnFocus && !_this.props.readOnly) {
  2419. _this.setOpen(true);
  2420. }
  2421. }
  2422. _this.setState({ focused: true });
  2423. };
  2424. _this.cancelFocusInput = function () {
  2425. clearTimeout(_this.inputFocusTimeout);
  2426. _this.inputFocusTimeout = null;
  2427. };
  2428. _this.deferFocusInput = function () {
  2429. _this.cancelFocusInput();
  2430. _this.inputFocusTimeout = setTimeout(function () {
  2431. return _this.setFocus();
  2432. }, 1);
  2433. };
  2434. _this.handleDropdownFocus = function () {
  2435. _this.cancelFocusInput();
  2436. };
  2437. _this.handleBlur = function (event) {
  2438. if (_this.state.open && !_this.props.withPortal && !_this.props.showTimeInput) {
  2439. _this.deferFocusInput();
  2440. } else {
  2441. _this.props.onBlur(event);
  2442. }
  2443. _this.setState({ focused: false });
  2444. };
  2445. _this.handleCalendarClickOutside = function (event) {
  2446. if (!_this.props.inline) {
  2447. _this.setOpen(false);
  2448. }
  2449. _this.props.onClickOutside(event);
  2450. if (_this.props.withPortal) {
  2451. event.preventDefault();
  2452. }
  2453. };
  2454. _this.handleChange = function () {
  2455. for (var _len = arguments.length, allArgs = Array(_len), _key = 0; _key < _len; _key++) {
  2456. allArgs[_key] = arguments[_key];
  2457. }
  2458. var event = allArgs[0];
  2459. if (_this.props.onChangeRaw) {
  2460. _this.props.onChangeRaw.apply(_this, allArgs);
  2461. if (typeof event.isDefaultPrevented !== "function" || event.isDefaultPrevented()) {
  2462. return;
  2463. }
  2464. }
  2465. _this.setState({
  2466. inputValue: event.target.value,
  2467. lastPreSelectChange: PRESELECT_CHANGE_VIA_INPUT
  2468. });
  2469. var date = parseDate(event.target.value, _this.props.dateFormat, _this.props.locale, _this.props.strictParsing);
  2470. if (date || !event.target.value) {
  2471. _this.setSelected(date, event, true);
  2472. }
  2473. };
  2474. _this.handleSelect = function (date, event, monthSelectedIn) {
  2475. // Preventing onFocus event to fix issue
  2476. // https://github.com/Hacker0x01/react-datepicker/issues/628
  2477. _this.setState({ preventFocus: true }, function () {
  2478. _this.preventFocusTimeout = setTimeout(function () {
  2479. return _this.setState({ preventFocus: false });
  2480. }, 50);
  2481. return _this.preventFocusTimeout;
  2482. });
  2483. _this.setSelected(date, event, undefined, monthSelectedIn);
  2484. if (!_this.props.shouldCloseOnSelect || _this.props.showTimeSelect) {
  2485. _this.setPreSelection(date);
  2486. } else if (!_this.props.inline) {
  2487. _this.setOpen(false);
  2488. }
  2489. };
  2490. _this.setSelected = function (date, event, keepInput, monthSelectedIn) {
  2491. var changedDate = date;
  2492. if (changedDate !== null && isDayDisabled(changedDate, _this.props)) {
  2493. return;
  2494. }
  2495. if (!isEqual(_this.props.selected, changedDate) || _this.props.allowSameDay) {
  2496. if (changedDate !== null) {
  2497. if (_this.props.selected) {
  2498. var selected = _this.props.selected;
  2499. if (keepInput) selected = newDate(changedDate);
  2500. changedDate = setTime(changedDate, {
  2501. hour: getHours(selected),
  2502. minute: getMinutes(selected),
  2503. second: getSeconds(selected)
  2504. });
  2505. }
  2506. if (!_this.props.inline) {
  2507. _this.setState({
  2508. preSelection: changedDate
  2509. });
  2510. }
  2511. if (_this.props.inline && _this.props.monthsShown > 1 && !_this.props.inlineFocusSelectedMonth) {
  2512. _this.setState({ monthSelectedIn: monthSelectedIn });
  2513. }
  2514. }
  2515. _this.props.onChange(changedDate, event);
  2516. }
  2517. _this.props.onSelect(changedDate, event);
  2518. if (!keepInput) {
  2519. _this.setState({ inputValue: null });
  2520. }
  2521. };
  2522. _this.setPreSelection = function (date) {
  2523. var hasMinDate = typeof _this.props.minDate !== "undefined";
  2524. var hasMaxDate = typeof _this.props.maxDate !== "undefined";
  2525. var isValidDateSelection = true;
  2526. if (date) {
  2527. if (hasMinDate && hasMaxDate) {
  2528. isValidDateSelection = isDayInRange(date, _this.props.minDate, _this.props.maxDate);
  2529. } else if (hasMinDate) {
  2530. isValidDateSelection = isAfter(date, _this.props.minDate);
  2531. } else if (hasMaxDate) {
  2532. isValidDateSelection = isBefore(date, _this.props.maxDate);
  2533. }
  2534. }
  2535. if (isValidDateSelection) {
  2536. _this.setState({
  2537. preSelection: date
  2538. });
  2539. }
  2540. };
  2541. _this.handleTimeChange = function (time) {
  2542. var selected = _this.props.selected ? _this.props.selected : _this.getPreSelection();
  2543. var changedDate = setTime(selected, {
  2544. hour: getHours(time),
  2545. minute: getMinutes(time)
  2546. });
  2547. _this.setState({
  2548. preSelection: changedDate
  2549. });
  2550. _this.props.onChange(changedDate);
  2551. if (_this.props.shouldCloseOnSelect) {
  2552. _this.setOpen(false);
  2553. }
  2554. if (_this.props.showTimeInput) {
  2555. _this.setOpen(true);
  2556. }
  2557. _this.setState({ inputValue: null });
  2558. };
  2559. _this.onInputClick = function () {
  2560. if (!_this.props.disabled && !_this.props.readOnly) {
  2561. _this.setOpen(true);
  2562. }
  2563. _this.props.onInputClick();
  2564. };
  2565. _this.onInputKeyDown = function (event) {
  2566. _this.props.onKeyDown(event);
  2567. var eventKey = event.key;
  2568. if (!_this.state.open && !_this.props.inline && !_this.props.preventOpenOnFocus) {
  2569. if (eventKey === "ArrowDown" || eventKey === "ArrowUp") {
  2570. _this.onInputClick();
  2571. }
  2572. return;
  2573. }
  2574. var copy = newDate(_this.state.preSelection);
  2575. if (eventKey === "Enter") {
  2576. event.preventDefault();
  2577. if (_this.inputOk() && _this.state.lastPreSelectChange === PRESELECT_CHANGE_VIA_NAVIGATE) {
  2578. _this.handleSelect(copy, event);
  2579. !_this.props.shouldCloseOnSelect && _this.setPreSelection(copy);
  2580. } else {
  2581. _this.setOpen(false);
  2582. }
  2583. } else if (eventKey === "Escape") {
  2584. event.preventDefault();
  2585. _this.setOpen(false);
  2586. if (!_this.inputOk()) {
  2587. _this.props.onInputError({ code: 1, msg: INPUT_ERR_1 });
  2588. }
  2589. } else if (eventKey === "Tab") {
  2590. _this.setOpen(false, true);
  2591. } else if (!_this.props.disabledKeyboardNavigation) {
  2592. var newSelection = void 0;
  2593. switch (eventKey) {
  2594. case "ArrowLeft":
  2595. newSelection = subDays(copy, 1);
  2596. break;
  2597. case "ArrowRight":
  2598. newSelection = addDays(copy, 1);
  2599. break;
  2600. case "ArrowUp":
  2601. newSelection = subWeeks(copy, 1);
  2602. break;
  2603. case "ArrowDown":
  2604. newSelection = addWeeks(copy, 1);
  2605. break;
  2606. case "PageUp":
  2607. newSelection = subMonths(copy, 1);
  2608. break;
  2609. case "PageDown":
  2610. newSelection = addMonths(copy, 1);
  2611. break;
  2612. case "Home":
  2613. newSelection = subYears(copy, 1);
  2614. break;
  2615. case "End":
  2616. newSelection = addYears(copy, 1);
  2617. break;
  2618. }
  2619. if (!newSelection) {
  2620. if (_this.props.onInputError) {
  2621. _this.props.onInputError({ code: 1, msg: INPUT_ERR_1 });
  2622. }
  2623. return; // Let the input component handle this keydown
  2624. }
  2625. event.preventDefault();
  2626. _this.setState({ lastPreSelectChange: PRESELECT_CHANGE_VIA_NAVIGATE });
  2627. if (_this.props.adjustDateOnChange) {
  2628. _this.setSelected(newSelection);
  2629. }
  2630. _this.setPreSelection(newSelection);
  2631. }
  2632. };
  2633. _this.onClearClick = function (event) {
  2634. if (event) {
  2635. if (event.preventDefault) {
  2636. event.preventDefault();
  2637. }
  2638. }
  2639. _this.props.onChange(null, event);
  2640. _this.setState({ inputValue: null });
  2641. };
  2642. _this.clear = function () {
  2643. _this.onClearClick();
  2644. };
  2645. _this.renderCalendar = function () {
  2646. if (!_this.props.inline && !_this.isCalendarOpen()) {
  2647. return null;
  2648. }
  2649. return React.createElement(
  2650. WrappedCalendar,
  2651. {
  2652. ref: function ref(elem) {
  2653. _this.calendar = elem;
  2654. },
  2655. locale: _this.props.locale,
  2656. adjustDateOnChange: _this.props.adjustDateOnChange,
  2657. setOpen: _this.setOpen,
  2658. shouldCloseOnSelect: _this.props.shouldCloseOnSelect,
  2659. dateFormat: _this.props.dateFormatCalendar,
  2660. useWeekdaysShort: _this.props.useWeekdaysShort,
  2661. formatWeekDay: _this.props.formatWeekDay,
  2662. dropdownMode: _this.props.dropdownMode,
  2663. selected: _this.props.selected,
  2664. preSelection: _this.state.preSelection,
  2665. onSelect: _this.handleSelect,
  2666. onWeekSelect: _this.props.onWeekSelect,
  2667. openToDate: _this.props.openToDate,
  2668. minDate: _this.props.minDate,
  2669. maxDate: _this.props.maxDate,
  2670. selectsStart: _this.props.selectsStart,
  2671. selectsEnd: _this.props.selectsEnd,
  2672. startDate: _this.props.startDate,
  2673. endDate: _this.props.endDate,
  2674. excludeDates: _this.props.excludeDates,
  2675. filterDate: _this.props.filterDate,
  2676. onClickOutside: _this.handleCalendarClickOutside,
  2677. formatWeekNumber: _this.props.formatWeekNumber,
  2678. highlightDates: _this.state.highlightDates,
  2679. includeDates: _this.props.includeDates,
  2680. includeTimes: _this.props.includeTimes,
  2681. injectTimes: _this.props.injectTimes,
  2682. inline: _this.props.inline,
  2683. peekNextMonth: _this.props.peekNextMonth,
  2684. showMonthDropdown: _this.props.showMonthDropdown,
  2685. useShortMonthInDropdown: _this.props.useShortMonthInDropdown,
  2686. showMonthYearDropdown: _this.props.showMonthYearDropdown,
  2687. showWeekNumbers: _this.props.showWeekNumbers,
  2688. showYearDropdown: _this.props.showYearDropdown,
  2689. withPortal: _this.props.withPortal,
  2690. forceShowMonthNavigation: _this.props.forceShowMonthNavigation,
  2691. showDisabledMonthNavigation: _this.props.showDisabledMonthNavigation,
  2692. scrollableYearDropdown: _this.props.scrollableYearDropdown,
  2693. scrollableMonthYearDropdown: _this.props.scrollableMonthYearDropdown,
  2694. todayButton: _this.props.todayButton,
  2695. weekLabel: _this.props.weekLabel,
  2696. outsideClickIgnoreClass: outsideClickIgnoreClass,
  2697. fixedHeight: _this.props.fixedHeight,
  2698. monthsShown: _this.props.monthsShown,
  2699. monthSelectedIn: _this.state.monthSelectedIn,
  2700. onDropdownFocus: _this.handleDropdownFocus,
  2701. onMonthChange: _this.props.onMonthChange,
  2702. onYearChange: _this.props.onYearChange,
  2703. dayClassName: _this.props.dayClassName,
  2704. showTimeSelect: _this.props.showTimeSelect,
  2705. showTimeSelectOnly: _this.props.showTimeSelectOnly,
  2706. onTimeChange: _this.handleTimeChange,
  2707. timeFormat: _this.props.timeFormat,
  2708. timeIntervals: _this.props.timeIntervals,
  2709. minTime: _this.props.minTime,
  2710. maxTime: _this.props.maxTime,
  2711. excludeTimes: _this.props.excludeTimes,
  2712. timeCaption: _this.props.timeCaption,
  2713. className: _this.props.calendarClassName,
  2714. container: _this.props.calendarContainer,
  2715. yearDropdownItemNumber: _this.props.yearDropdownItemNumber,
  2716. previousMonthButtonLabel: _this.props.previousMonthButtonLabel,
  2717. nextMonthButtonLabel: _this.props.nextMonthButtonLabel,
  2718. timeInputLabel: _this.props.timeInputLabel,
  2719. disabledKeyboardNavigation: _this.props.disabledKeyboardNavigation,
  2720. renderCustomHeader: _this.props.renderCustomHeader,
  2721. popperProps: _this.props.popperProps,
  2722. renderDayContents: _this.props.renderDayContents,
  2723. onDayMouseEnter: _this.props.onDayMouseEnter,
  2724. onMonthMouseLeave: _this.props.onMonthMouseLeave,
  2725. showTimeInput: _this.props.showTimeInput,
  2726. showMonthYearPicker: _this.props.showMonthYearPicker
  2727. },
  2728. _this.props.children
  2729. );
  2730. };
  2731. _this.renderDateInput = function () {
  2732. var _classnames, _React$cloneElement;
  2733. var className = classnames(_this.props.className, (_classnames = {}, _classnames[outsideClickIgnoreClass] = _this.state.open, _classnames));
  2734. var customInput = _this.props.customInput || React.createElement("input", { type: "text" });
  2735. var customInputRef = _this.props.customInputRef || "ref";
  2736. var inputValue = typeof _this.props.value === "string" ? _this.props.value : typeof _this.state.inputValue === "string" ? _this.state.inputValue : safeDateFormat(_this.props.selected, _this.props);
  2737. return React.cloneElement(customInput, (_React$cloneElement = {}, _React$cloneElement[customInputRef] = function (input) {
  2738. _this.input = input;
  2739. }, _React$cloneElement.value = inputValue, _React$cloneElement.onBlur = _this.handleBlur, _React$cloneElement.onChange = _this.handleChange, _React$cloneElement.onClick = _this.onInputClick, _React$cloneElement.onFocus = _this.handleFocus, _React$cloneElement.onKeyDown = _this.onInputKeyDown, _React$cloneElement.id = _this.props.id, _React$cloneElement.name = _this.props.name, _React$cloneElement.autoFocus = _this.props.autoFocus, _React$cloneElement.placeholder = _this.props.placeholderText, _React$cloneElement.disabled = _this.props.disabled, _React$cloneElement.autoComplete = _this.props.autoComplete, _React$cloneElement.className = className, _React$cloneElement.title = _this.props.title, _React$cloneElement.readOnly = _this.props.readOnly, _React$cloneElement.required = _this.props.required, _React$cloneElement.tabIndex = _this.props.tabIndex, _React$cloneElement));
  2740. };
  2741. _this.renderClearButton = function () {
  2742. if (_this.props.isClearable && _this.props.selected != null) {
  2743. return React.createElement("button", {
  2744. type: "button",
  2745. className: "react-datepicker__close-icon",
  2746. onClick: _this.onClearClick,
  2747. title: _this.props.clearButtonTitle,
  2748. tabIndex: -1
  2749. });
  2750. } else {
  2751. return null;
  2752. }
  2753. };
  2754. _this.state = _this.calcInitialState();
  2755. return _this;
  2756. }
  2757. DatePicker.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
  2758. if (prevProps.inline && hasPreSelectionChanged(prevProps.selected, this.props.selected)) {
  2759. this.setPreSelection(this.props.selected);
  2760. }
  2761. if (this.state.monthSelectedIn !== undefined && prevProps.monthsShown !== this.props.monthsShown) {
  2762. this.setState({ monthSelectedIn: 0 });
  2763. }
  2764. if (prevProps.highlightDates !== this.props.highlightDates) {
  2765. this.setState({
  2766. highlightDates: getHightLightDaysMap(this.props.highlightDates)
  2767. });
  2768. }
  2769. if (!prevState.focused && !isEqual(prevProps.selected, this.props.selected)) {
  2770. this.setState({ inputValue: null });
  2771. }
  2772. };
  2773. DatePicker.prototype.componentWillUnmount = function componentWillUnmount() {
  2774. this.clearPreventFocusTimeout();
  2775. };
  2776. DatePicker.prototype.render = function render() {
  2777. var calendar = this.renderCalendar();
  2778. if (this.props.inline && !this.props.withPortal) {
  2779. return calendar;
  2780. }
  2781. if (this.props.withPortal) {
  2782. return React.createElement(
  2783. "div",
  2784. null,
  2785. !this.props.inline ? React.createElement(
  2786. "div",
  2787. { className: "react-datepicker__input-container" },
  2788. this.renderDateInput(),
  2789. this.renderClearButton()
  2790. ) : null,
  2791. this.state.open || this.props.inline ? React.createElement(
  2792. "div",
  2793. { className: "react-datepicker__portal" },
  2794. calendar
  2795. ) : null
  2796. );
  2797. }
  2798. return React.createElement(PopperComponent, {
  2799. className: this.props.popperClassName,
  2800. hidePopper: !this.isCalendarOpen(),
  2801. popperModifiers: this.props.popperModifiers,
  2802. targetComponent: React.createElement(
  2803. "div",
  2804. { className: "react-datepicker__input-container" },
  2805. this.renderDateInput(),
  2806. this.renderClearButton()
  2807. ),
  2808. popperContainer: this.props.popperContainer,
  2809. popperComponent: calendar,
  2810. popperPlacement: this.props.popperPlacement,
  2811. popperProps: this.props.popperProps
  2812. });
  2813. };
  2814. return DatePicker;
  2815. }(React.Component);
  2816. var PRESELECT_CHANGE_VIA_INPUT = "input";
  2817. var PRESELECT_CHANGE_VIA_NAVIGATE = "navigate";
  2818. export { registerLocale, setDefaultLocale, getDefaultLocale, CalendarContainer };
  2819. export default DatePicker;