@fremtind/jkl-datepicker-react
Version:
Jøkul react datepicker component
57 lines (56 loc) • 1.94 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const calendarReducer = (currentState, action) => {
let shownDate;
switch (action.type) {
case "SET_OFFSET":
shownDate = new Date(currentState.selectedDate);
shownDate.setMonth(
currentState.selectedDate.getMonth() + action.newOffset
);
return __spreadProps(__spreadValues({}, currentState), {
offset: action.newOffset,
shownDate
});
case "ADD_OFFSET":
shownDate = new Date(currentState.selectedDate);
shownDate.setMonth(
currentState.selectedDate.getMonth() + currentState.offset + action.addedOffset
);
return __spreadProps(__spreadValues({}, currentState), {
offset: currentState.offset + action.addedOffset,
shownDate
});
case "SET_SELECTED_DATE":
return calendarInitializer(action.newDate);
default:
return currentState;
}
};
const calendarInitializer = (initialDate) => ({
selectedDate: initialDate,
offset: 0,
shownDate: initialDate
});
export {
calendarInitializer,
calendarReducer
};
//# sourceMappingURL=calendarReducer.js.map