UNPKG

material-duration-picker

Version:

React Material component for durations inspired by Material-UI Pickers

63 lines (62 loc) 3.58 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DurationPicker = void 0; var React = __importStar(require("react")); var react_1 = require("react"); var core_1 = require("@material-ui/core"); var utils_1 = require("./utils"); var durationDialog_1 = require("./durationDialog"); var DurationPicker = function (_a) { var DurationDialogProps = _a.DurationDialogProps, value = _a.value, onValueChange = _a.onValueChange, formatDuration = _a.formatDuration, _b = _a.views, views = _b === void 0 ? ['hours', 'minutes'] : _b, disableEditDialog = _a.disableEditDialog, _c = _a.DurationDialogComp, DurationDialogComp = _c === void 0 ? durationDialog_1.DurationDialog : _c, _d = _a.TextFieldComp, TextFieldComp = _d === void 0 ? core_1.TextField : _d, props = __rest(_a, ["DurationDialogProps", "value", "onValueChange", "formatDuration", "views", "disableEditDialog", "DurationDialogComp", "TextFieldComp"]); var _e = react_1.useState(false), open = _e[0], setOpen = _e[1]; var duration = utils_1.timeToDuration(value); return React.createElement(React.Fragment, null, React.createElement(TextFieldComp, __assign({ onClick: function () { !disableEditDialog && setOpen(true); }, value: formatDuration(duration) }, props, { InputLabelProps: __assign({ shrink: open || undefined }, props.InputLabelProps), inputProps: __assign({ readOnly: true }, props === null || props === void 0 ? void 0 : props.inputProps) })), !disableEditDialog && (React.createElement(DurationDialogComp, __assign({ time: value, open: open, onDismiss: function () { return setOpen(false); }, onAccept: function (time) { onValueChange(time); }, views: views, formatDuration: formatDuration }, DurationDialogProps)))); }; exports.DurationPicker = DurationPicker;