lucid-ui
Version:
A UI component library from AppNexus.
134 lines • 8.62 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/prop-types"));
var react_day_picker_1 = __importDefault(require("react-day-picker"));
var style_helpers_1 = require("../../util/style-helpers");
var DateUtils = react_day_picker_1.default.DateUtils;
var cx = style_helpers_1.lucidClassNames.bind('&-CalendarMonth');
var bool = prop_types_1.default.bool, instanceOf = prop_types_1.default.instanceOf, number = prop_types_1.default.number, oneOf = prop_types_1.default.oneOf, string = prop_types_1.default.string;
var CalendarMonth = /** @class */ (function (_super) {
__extends(CalendarMonth, _super);
function CalendarMonth() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.modifierRange = function (day) {
var _a = _this.props, cursor = _a.cursor, from = _a.from, to = _a.to, selectMode = _a.selectMode;
if (cursor) {
if (selectMode === 'day') {
return DateUtils.isSameDay(day, new Date(cursor));
}
else if (from || to) {
return DateUtils.isDayInRange(day, {
from: new Date(selectMode === 'to' ? from : to),
to: new Date(cursor),
});
}
return DateUtils.isSameDay(day, new Date(cursor));
}
if (from && to) {
return DateUtils.isDayInRange(day, {
from: new Date(from),
to: new Date(to),
});
}
return false;
};
_this.modifierFrom = function (day) {
var from = _this.props.from;
return DateUtils.isSameDay(day, new Date(from));
};
_this.modifierTo = function (day) {
var to = _this.props.to;
return DateUtils.isSameDay(day, new Date(to));
};
return _this;
}
CalendarMonth.prototype.shouldComponentUpdate = function () {
return this.props.shouldComponentUpdate;
};
CalendarMonth.prototype.render = function () {
var _a = this.props, className = _a.className, monthOffset = _a.monthOffset, initialMonth = _a.initialMonth, passThroughs = __rest(_a, ["className", "monthOffset", "initialMonth"]);
// It can be tricky to increment months using JavaScript dates, this should
// handle the edge cases.
// http://stackoverflow.com/questions/499838/javascript-date-next-month
var monthDate = new Date(initialMonth.getFullYear(), initialMonth.getMonth() + monthOffset, 1);
return (
/**typescript boundary with this component is tricky to get right with the way passthrough works
* the component is being rewritten in typescript. Going to punt on this for now
* https://github.com/gpbl/react-day-picker/issues/942
*/
//@ts-ignore
react_1.default.createElement(react_day_picker_1.default, __assign({ key: monthOffset, className: cx('&', className), initialMonth: monthDate, canChangeMonth: false, weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] }, passThroughs, { modifiers: __assign({ range: this.modifierRange, from: this.modifierFrom, to: this.modifierTo }, passThroughs.modifiers) })));
};
CalendarMonth._isPrivate = true;
CalendarMonth.displayName = 'CalendarMonth';
CalendarMonth.peek = {
description: "\n\t\t\tA single calendar month based on `react-day-picker`.\n\t\t",
categories: ['helpers'],
};
CalendarMonth.propTypes = {
className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"]))),
monthOffset: number(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tThe offset of the rendered month, where 0 is the `initialMonth`.\n\t\t\tNegative values will show previous months.\n\t\t"], ["\n\t\t\tThe offset of the rendered month, where 0 is the \\`initialMonth\\`.\n\t\t\tNegative values will show previous months.\n\t\t"]))),
initialMonth: instanceOf(Date)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tSets the month of the calendar. The 0 value for the `monthOffset` prop\n\t\t\trefers to this month.\n\t\t"], ["\n\t\t\tSets the month of the calendar. The 0 value for the \\`monthOffset\\` prop\n\t\t\trefers to this month.\n\t\t"]))),
cursor: instanceOf(Date)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tSet the cursor to target date. Primarily used to preview expected ranges\n\t\t\twhen the cursor is on a target date.\n\t\t"], ["\n\t\t\tSet the cursor to target date. Primarily used to preview expected ranges\n\t\t\twhen the cursor is on a target date.\n\t\t"]))),
from: instanceOf(Date)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tSets the start date in a date range.\n\t\t"], ["\n\t\t\tSets the start date in a date range.\n\t\t"]))),
to: instanceOf(Date)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tSets the end date in a date range.\n\t\t"], ["\n\t\t\tSets the end date in a date range.\n\t\t"]))),
selectMode: oneOf(['day', 'from', 'to'])(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tThe next selection that is expected. Primarily used to preview expected\n\t\t\tranges when the cursor is on a target date.\n\t\t"], ["\n\t\t\tThe next selection that is expected. Primarily used to preview expected\n\t\t\tranges when the cursor is on a target date.\n\t\t"]))),
shouldComponentUpdate: bool(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tUsed to skip re-rendering of this component when true. Primarily used for\n\t\t\tCalendarMonths which are rendered out of view.\n\t\t"], ["\n\t\t\tUsed to skip re-rendering of this component when true. Primarily used for\n\t\t\tCalendarMonths which are rendered out of view.\n\t\t"]))),
};
CalendarMonth.defaultProps = {
monthOffset: 0,
initialMonth: new Date(),
cursor: null,
from: null,
to: null,
selectMode: 'day',
shouldComponentUpdate: true,
};
return CalendarMonth;
}(react_1.default.Component));
exports.default = CalendarMonth;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
//# sourceMappingURL=CalendarMonth.js.map