UNPKG

@josmangarsal/pragmatic-scheduler

Version:
73 lines (72 loc) 3.71 kB
"use strict"; 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 __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SchedulerDateControls = void 0; var jsx_runtime_1 = require("@emotion/react/jsx-runtime"); var react_1 = require("react"); var material_1 = require("@mui/material"); var DesktopDatePicker_1 = require("@mui/x-date-pickers/DesktopDatePicker"); var date_fns_1 = require("date-fns"); var ArrowForwardIos_1 = __importDefault(require("@mui/icons-material/ArrowForwardIos")); var ArrowBackIos_1 = __importDefault(require("@mui/icons-material/ArrowBackIos")); var SchedulerDateControls = function (_a) { var activeDate = _a.activeDate, setActiveDate = _a.setActiveDate, _b = _a.buttonText, buttonText = _b === void 0 ? 'TODAY' : _b, _c = _a.moveByDays, moveByDays = _c === void 0 ? 1 : _c; var _d = __read((0, react_1.useState)(false), 2), open = _d[0], setOpen = _d[1]; var handleChange = function (newValue) { if (newValue) { setActiveDate(newValue); } }; var handleClose = function () { setOpen(false); }; var handleOpen = function () { setOpen(true); }; var handleGoForward = function () { // if dates are in use, extend them if the move is greater than to setActiveDate(function (d) { return (0, date_fns_1.addDays)(d, moveByDays); }); }; var handleGoBack = function () { // if dates are in use, extend them if the move is greater than from setActiveDate(function (d) { return (0, date_fns_1.addDays)(d, -1 * moveByDays); }); }; return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ onClick: handleGoBack }, { children: (0, jsx_runtime_1.jsx)(ArrowBackIos_1.default, {}) })), (0, jsx_runtime_1.jsx)(DesktopDatePicker_1.DesktopDatePicker, { open: open, label: "Date desktop", format: "dd/MM/yyyy", value: activeDate, onClose: handleClose, onChange: handleChange, slots: { textField: function (params) { return ((0, jsx_runtime_1.jsx)(material_1.Button, __assign({ ref: params.InputProps.ref, sx: { marginX: 0.625 }, variant: "outlined", onClick: handleOpen }, { children: buttonText }))); }, }, slotProps: { actionBar: { actions: ['today', 'cancel'] }, popper: { placement: 'bottom-end' }, } }), (0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ onClick: handleGoForward }, { children: (0, jsx_runtime_1.jsx)(ArrowForwardIos_1.default, {}) }))] })); }; exports.SchedulerDateControls = SchedulerDateControls;