material-ui-pickers
Version:
React components, that implements material design pickers for material-ui v1
1,749 lines (1,538 loc) • 117 kB
JavaScript
import { __extends, __assign, __rest } from 'tslib';
import React__default, { createContext, createElement, Component, PureComponent, Fragment, cloneElement, forwardRef } from 'react';
import { oneOfType, object, string, number, instanceOf, oneOf, func, element, arrayOf, bool, any, shape, node } from 'prop-types';
import IconButton from '@material-ui/core/IconButton';
import InputAdornment from '@material-ui/core/InputAdornment';
import TextField from '@material-ui/core/TextField';
import SvgIcon from '@material-ui/core/SvgIcon';
import MaskedInput from 'react-text-mask';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import { createStyles, withStyles } from '@material-ui/core/styles';
import clsx from 'clsx';
import EventListener from 'react-event-listener';
import createStyles$1 from '@material-ui/core/styles/createStyles';
import withStyles$1 from '@material-ui/core/styles/withStyles';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
import { findDOMNode } from 'react-dom';
import Popover from '@material-ui/core/Popover';
import Paper from '@material-ui/core/Paper';
import Tab from '@material-ui/core/Tab';
import Tabs from '@material-ui/core/Tabs';
var findClosestEnabledDate = function (_a) {
var date = _a.date,
utils = _a.utils,
minDate = _a.minDate,
maxDate = _a.maxDate,
disableFuture = _a.disableFuture,
disablePast = _a.disablePast,
shouldDisableDate = _a.shouldDisableDate;
var today = utils.startOfDay(utils.date());
minDate = minDate && utils.date(minDate);
maxDate = maxDate && utils.date(maxDate);
if (disablePast && utils.isBefore(minDate, today)) {
minDate = today;
}
if (disableFuture && utils.isAfter(maxDate, today)) {
maxDate = today;
}
var forward = date;
var backward = date;
if (utils.isBefore(date, minDate)) {
forward = utils.date(minDate);
backward = null;
}
if (utils.isAfter(date, maxDate)) {
if (backward) {
backward = utils.date(maxDate);
}
forward = null;
}
while (forward || backward) {
if (forward && utils.isAfter(forward, maxDate)) {
forward = null;
}
if (backward && utils.isBefore(backward, minDate)) {
backward = null;
}
if (forward) {
if (!shouldDisableDate(forward)) {
return forward;
}
forward = utils.addDays(forward, 1);
}
if (backward) {
if (!shouldDisableDate(backward)) {
return backward;
}
backward = utils.addDays(backward, -1);
}
}
return null;
};
var isYearOnlyView = function (views) {
return views.length === 1 && views[0] === 'year';
};
var isYearAndMonthViews = function (views) {
return views.length === 2 && views.includes('month') && views.includes('year');
};
var getFormatByViews = function (views, utils) {
if (isYearOnlyView(views)) {
return utils.yearFormat;
}
if (isYearAndMonthViews(views)) {
return utils.yearMonthFormat;
}
return utils.dateFormat;
};
var date = oneOfType([object, string, number, instanceOf(Date)]);
var datePickerView = oneOf(['year', 'month', 'day']);
var DomainPropTypes = {
date: date,
datePickerView: datePickerView
};
var MuiPickersContext = createContext(null); // TODO remove in v3.0
var MuiPickersContextConsumer = MuiPickersContext.Consumer;
var MuiPickersUtilsProvider =
/*@__PURE__*/
function (_super) {
__extends(MuiPickersUtilsProvider, _super);
function MuiPickersUtilsProvider() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
utils: null
};
return _this;
}
MuiPickersUtilsProvider.getDerivedStateFromProps = function (_a) {
var Utils = _a.utils,
locale = _a.locale,
moment = _a.moment;
return {
utils: new Utils({
locale: locale,
moment: moment
})
};
};
MuiPickersUtilsProvider.prototype.render = function () {
return createElement(MuiPickersContext.Provider, {
value: this.state.utils,
children: this.props.children
});
};
process.env.NODE_ENV !== "production" ? MuiPickersUtilsProvider.propTypes = {
utils: func.isRequired,
locale: oneOfType([object, string]),
children: oneOfType([element.isRequired, arrayOf(element.isRequired)]).isRequired,
moment: func
} : void 0;
return MuiPickersUtilsProvider;
}(Component);
var checkUtils = function (utils) {
if (!utils) {
// tslint:disable-next-line
throw new Error('Can not find utils in context. You either a) forgot to wrap your component tree in MuiPickersUtilsProvider; or b) mixed named and direct file imports. Recommendation: use named imports from the module index.');
}
};
var withUtils = function () {
return function (Component) {
var WithUtils = function (props) {
return createElement(MuiPickersContext.Consumer, null, function (utils) {
checkUtils(utils);
return createElement(Component, __assign({
utils: utils
}, props));
});
};
WithUtils.displayName = "WithUtils(" + (Component.displayName || Component.name) + ")";
return WithUtils;
};
};
var getInitialDate = function (_a) {
var utils = _a.utils,
value = _a.value,
initialFocusedDate = _a.initialFocusedDate;
var initialDate = value || initialFocusedDate || utils.date();
var date = utils.date(initialDate);
return date && utils.isValid(date) ? date : utils.date();
};
var BasePicker =
/*@__PURE__*/
function (_super) {
__extends(BasePicker, _super);
function BasePicker() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
date: getInitialDate(_this.props),
isAccepted: false
};
_this.changeDate = function (date, callback) {
return _this.setState({
date: date
}, callback);
};
_this.handleAcceptedChange = function (isAccepted, callback) {
return _this.setState({
isAccepted: isAccepted
}, callback);
};
_this.handleClear = function () {
return _this.props.onChange(null);
};
_this.handleAccept = function () {
return _this.props.onChange(_this.state.date);
};
_this.handleSetTodayDate = function () {
return _this.handleChange(_this.props.utils.date(), false);
};
_this.handleTextFieldChange = function (date) {
var _a = _this.props,
onChange = _a.onChange,
utils = _a.utils,
mergePreviousDateOnChange = _a.mergePreviousDateOnChange;
if (mergePreviousDateOnChange) {
date = utils.mergeDateAndTime(_this.state.date, date);
}
if (date === null) {
onChange(null);
} else {
_this.changeDate(date, function () {
return onChange(date);
});
}
};
_this.pick12hOr24hFormat = function (default12hFormat, default24hFormat) {
var _a = _this.props,
format = _a.format,
ampm = _a.ampm;
if (format) {
return format;
}
return ampm ? default12hFormat : default24hFormat;
};
_this.handleChange = function (newDate, isFinish) {
if (isFinish === void 0) {
isFinish = true;
}
var _a = _this.props,
autoOk = _a.autoOk,
onChange = _a.onChange;
_this.changeDate(newDate, function () {
if (isFinish && autoOk) {
onChange(newDate); // pass down accept true, and make it false in the next tick
_this.handleAcceptedChange(true, function () {
return _this.handleAcceptedChange(false);
});
}
});
};
_this.handleDismiss = function () {
_this.setState({
date: getInitialDate(_this.props)
});
};
return _this;
}
BasePicker.prototype.componentDidUpdate = function (prevProps) {
var _a = this.props,
utils = _a.utils,
value = _a.value,
initialFocusedDate = _a.initialFocusedDate;
if (prevProps.value !== value || prevProps.utils.locale !== utils.locale || prevProps.initialFocusedDate !== initialFocusedDate) {
this.changeDate(getInitialDate(this.props));
}
};
BasePicker.prototype.render = function () {
return this.props.children(__assign({}, this.state, {
utils: this.props.utils,
changeDate: this.changeDate,
handleAcceptedChange: this.handleAcceptedChange,
handleClear: this.handleClear,
handleAccept: this.handleAccept,
handleDismiss: this.handleDismiss,
handleSetTodayDate: this.handleSetTodayDate,
handleTextFieldChange: this.handleTextFieldChange,
pick12hOr24hFormat: this.pick12hOr24hFormat,
handleChange: this.handleChange
}));
};
process.env.NODE_ENV !== "production" ? BasePicker.propTypes = {
value: DomainPropTypes.date,
onChange: func.isRequired,
autoOk: bool,
initialFocusedDate: any
} : void 0;
BasePicker.defaultProps = {
value: new Date(),
autoOK: false,
ampm: true
};
return BasePicker;
}(Component);
var BasePicker$1 = withUtils()(BasePicker);
var getDisplayDate = function (_a) {
var utils = _a.utils,
value = _a.value,
format = _a.format,
invalidLabel = _a.invalidLabel,
emptyLabel = _a.emptyLabel,
labelFunc = _a.labelFunc;
var isEmpty = value === null;
var date = utils.date(value);
if (labelFunc) {
return labelFunc(isEmpty ? null : date, invalidLabel);
}
if (isEmpty) {
return emptyLabel;
}
return utils.isValid(date) ? utils.format(date, format) : invalidLabel;
};
var getError = function (value, props) {
var utils = props.utils,
maxDate = props.maxDate,
minDate = props.minDate,
disablePast = props.disablePast,
disableFuture = props.disableFuture,
maxDateMessage = props.maxDateMessage,
minDateMessage = props.minDateMessage,
invalidDateMessage = props.invalidDateMessage; // if null - do not show error
if (utils.isNull(value)) {
return '';
}
if (!utils.isValid(value)) {
return invalidDateMessage;
}
if (maxDate && utils.isAfter(value, utils.endOfDay(utils.date(maxDate))) || disableFuture && utils.isAfter(value, utils.endOfDay(utils.date()))) {
return maxDateMessage;
}
if (minDate && utils.isBefore(value, utils.startOfDay(utils.date(minDate))) || disablePast && utils.isBefore(value, utils.startOfDay(utils.date()))) {
return minDateMessage;
}
return '';
};
var KeyboardIcon = function (props) {
return React__default.createElement(SvgIcon, __assign({}, props), React__default.createElement("path", {
d: "M17 12h-5v5h5v-5zM16 1v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-1V1h-2zm3 18H5V8h14v11z"
}), React__default.createElement("path", {
fill: "none",
d: "M0 0h24v24H0z"
}));
};
var Input =
/*@__PURE__*/
function (_super) {
__extends(Input, _super);
function Input() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.createInputRef = function (ref) {
var inputRef = _this.props.inputRef;
if (inputRef && typeof inputRef === 'function') {
// @ts-ignore inputElement exists in Masked input. Issue in typings
inputRef(ref ? ref.inputElement : null);
}
};
return _this;
}
Input.prototype.render = function () {
var _a = this.props,
inputRef = _a.inputRef,
keepCharPositions = _a.keepCharPositions,
rest = __rest(_a, ["inputRef", "keepCharPositions"]);
return this.props.mask ? createElement(MaskedInput, __assign({}, rest, {
ref: this.createInputRef,
keepCharPositions: keepCharPositions
})) : createElement("input", __assign({}, rest, {
ref: inputRef
}));
};
process.env.NODE_ENV !== "production" ? Input.propTypes = {
mask: any,
inputRef: func.isRequired
} : void 0;
return Input;
}(PureComponent);
var DateTextField =
/*@__PURE__*/
function (_super) {
__extends(DateTextField, _super);
function DateTextField() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = DateTextField.getStateFromProps(_this.props);
_this.commitUpdates = function (value) {
var _a = _this.props,
onChange = _a.onChange,
clearable = _a.clearable,
onClear = _a.onClear,
utils = _a.utils,
format = _a.format,
onError = _a.onError;
if (value === '') {
if (_this.props.value === null) {
_this.setState(DateTextField.getStateFromProps(_this.props));
} else if (clearable && onClear) {
onClear();
}
return;
}
var oldValue = utils.date(_this.state.value);
var newValue = utils.parse(value, format);
var error = getError(newValue, _this.props);
_this.setState({
error: error,
displayValue: value,
value: error ? newValue : oldValue
}, function () {
if (!error && !utils.isEqual(newValue, oldValue)) {
onChange(newValue);
}
if (error && onError) {
onError(newValue, error);
}
});
};
_this.handleBlur = function (e) {
if (_this.props.keyboard) {
e.preventDefault();
e.stopPropagation();
_this.commitUpdates(e.target.value);
if (_this.props.onBlur) {
_this.props.onBlur(e);
}
}
};
_this.handleChange = function (e) {
var _a = _this.props,
utils = _a.utils,
format = _a.format,
onInputChange = _a.onInputChange;
var parsedValue = utils.parse(e.target.value, format);
if (onInputChange) {
onInputChange(e);
}
_this.setState({
displayValue: e.target.value,
error: getError(parsedValue, _this.props)
});
};
_this.handleFocus = function (e) {
e.stopPropagation();
e.preventDefault();
if (!_this.props.keyboard) {
_this.openPicker(e);
}
};
_this.handleKeyPress = function (e) {
if (e.key === 'Enter') {
if (!_this.props.disableOpenOnEnter) {
_this.openPicker(e);
} else {
// @ts-ignore TODO check me
_this.commitUpdates(e.target.value);
}
}
};
_this.openPicker = function (e) {
var _a = _this.props,
disabled = _a.disabled,
onClick = _a.onClick;
if (!disabled) {
onClick(e);
}
};
return _this;
}
DateTextField.prototype.componentDidUpdate = function (prevProps) {
var utils = this.props.utils;
if (!utils.isEqual(utils.date(this.props.value), utils.date(prevProps.value)) || prevProps.format !== this.props.format || prevProps.maxDate !== this.props.maxDate || prevProps.minDate !== this.props.minDate || prevProps.emptyLabel !== this.props.emptyLabel || prevProps.labelFunc !== this.props.labelFunc || prevProps.utils !== this.props.utils) {
this.setState(DateTextField.getStateFromProps(this.props));
}
};
DateTextField.prototype.render = function () {
var _a = this.props,
adornmentPosition = _a.adornmentPosition,
clearable = _a.clearable,
disabled = _a.disabled,
disableFuture = _a.disableFuture,
disableOpenOnEnter = _a.disableOpenOnEnter,
disablePast = _a.disablePast,
emptyLabel = _a.emptyLabel,
format = _a.format,
InputAdornmentProps = _a.InputAdornmentProps,
InputProps = _a.InputProps,
invalidDateMessage = _a.invalidDateMessage,
invalidLabel = _a.invalidLabel,
keyboard = _a.keyboard,
KeyboardButtonProps = _a.KeyboardButtonProps,
keyboardIcon = _a.keyboardIcon,
labelFunc = _a.labelFunc,
mask = _a.mask,
maxDate = _a.maxDate,
maxDateMessage = _a.maxDateMessage,
minDate = _a.minDate,
minDateMessage = _a.minDateMessage,
onBlur = _a.onBlur,
onClear = _a.onClear,
onClick = _a.onClick,
pipe = _a.pipe,
keepCharPositions = _a.keepCharPositions,
TextFieldComponent = _a.TextFieldComponent,
utils = _a.utils,
value = _a.value,
onInputChange = _a.onInputChange,
other = __rest(_a, ["adornmentPosition", "clearable", "disabled", "disableFuture", "disableOpenOnEnter", "disablePast", "emptyLabel", "format", "InputAdornmentProps", "InputProps", "invalidDateMessage", "invalidLabel", "keyboard", "KeyboardButtonProps", "keyboardIcon", "labelFunc", "mask", "maxDate", "maxDateMessage", "minDate", "minDateMessage", "onBlur", "onClear", "onClick", "pipe", "keepCharPositions", "TextFieldComponent", "utils", "value", "onInputChange"]);
var _b = this.state,
displayValue = _b.displayValue,
error = _b.error;
var localInputProps = {
inputComponent: Input,
inputProps: {
mask: !keyboard ? null : mask,
pipe: !keyboard ? null : pipe,
keepCharPositions: !keyboard ? undefined : keepCharPositions,
readOnly: !keyboard
}
};
if (keyboard) {
localInputProps[adornmentPosition + "Adornment"] = createElement(InputAdornment, __assign({
position: adornmentPosition
}, InputAdornmentProps), createElement(IconButton, __assign({
disabled: disabled,
onClick: this.openPicker
}, KeyboardButtonProps), keyboardIcon));
}
var Component = TextFieldComponent;
var inputProps = __assign({}, localInputProps, InputProps);
return createElement(Component, __assign({
onClick: this.handleFocus,
error: !!error,
helperText: error,
onKeyPress: this.handleKeyPress,
onBlur: this.handleBlur,
disabled: disabled,
value: displayValue
}, other, {
onError: undefined,
onChange: this.handleChange,
InputProps: inputProps
}));
};
process.env.NODE_ENV !== "production" ? DateTextField.propTypes = {
value: oneOfType([object, string, number, instanceOf(Date)]),
minDate: DomainPropTypes.date,
maxDate: DomainPropTypes.date,
disablePast: bool,
disableFuture: bool,
format: string,
onBlur: func,
onChange: func.isRequired,
onClear: func,
onClick: func.isRequired,
clearable: bool,
utils: object.isRequired,
InputProps: shape({}),
mask: any,
minDateMessage: node,
maxDateMessage: node,
invalidLabel: string,
emptyLabel: string,
labelFunc: func,
keyboard: bool,
keyboardIcon: node,
disableOpenOnEnter: bool,
invalidDateMessage: node,
TextFieldComponent: oneOfType([string, func, node]),
InputAdornmentProps: object,
KeyboardButtonProps: object,
adornmentPosition: oneOf(['start', 'end']),
onError: func,
onInputChange: func,
pipe: func,
keepCharPositions: bool
} : void 0;
DateTextField.defaultProps = {
disabled: false,
invalidLabel: 'Unknown',
emptyLabel: '',
keyboard: false,
keyboardIcon: createElement(KeyboardIcon, null),
disableOpenOnEnter: false,
invalidDateMessage: 'Invalid Date Format',
clearable: false,
disablePast: false,
disableFuture: false,
minDate: new Date('1900-01-01'),
maxDate: new Date('2100-01-01'),
minDateMessage: 'Date should not be before minimal date',
maxDateMessage: 'Date should not be after maximal date',
TextFieldComponent: TextField,
InputAdornmentProps: {},
KeyboardButtonProps: {},
adornmentPosition: 'end',
keepCharPositions: false
};
DateTextField.getStateFromProps = function (props) {
return {
value: props.value,
displayValue: getDisplayDate(props),
error: getError(props.utils.date(props.value), props)
};
};
return DateTextField;
}(PureComponent);
var DateTextField$1 = withUtils()(DateTextField);
var DIALOG_WIDTH = 310;
var DIALOG_WIDTH_WIDER = 325;
var ModalDialog = function (_a) {
var children = _a.children,
classes = _a.classes,
onKeyDownInner = _a.onKeyDownInner,
onAccept = _a.onAccept,
onDismiss = _a.onDismiss,
onClear = _a.onClear,
onSetToday = _a.onSetToday,
okLabel = _a.okLabel,
cancelLabel = _a.cancelLabel,
clearLabel = _a.clearLabel,
todayLabel = _a.todayLabel,
clearable = _a.clearable,
showTodayButton = _a.showTodayButton,
showTabs = _a.showTabs,
wider = _a.wider,
other = __rest(_a, ["children", "classes", "onKeyDownInner", "onAccept", "onDismiss", "onClear", "onSetToday", "okLabel", "cancelLabel", "clearLabel", "todayLabel", "clearable", "showTodayButton", "showTabs", "wider"]);
var _b, _c, _d;
return createElement(Dialog, __assign({
role: "dialog",
onClose: onDismiss,
classes: {
paper: clsx(classes.dialogRoot, (_b = {}, _b[classes.dialogRootWider] = wider, _b[classes.dialogWithTabs] = showTabs, _b))
}
}, other), createElement(EventListener, {
target: "window",
onKeyDown: onKeyDownInner
}), createElement(DialogContent, {
children: children,
className: clsx(classes.dialog, (_c = {}, _c[classes.dialogWithTabs] = showTabs, _c))
}), createElement(DialogActions, {
classes: {
root: clearable || showTodayButton ? classes.dialogActions : undefined,
action: clsx(classes.dialogAction, (_d = {}, _d[classes.clearableDialogAction] = clearable, _d[classes.todayDialogAction] = !clearable && showTodayButton, _d))
}
}, clearable && createElement(Button, {
color: "primary",
onClick: onClear
}, clearLabel), !clearable && showTodayButton && createElement(Button, {
color: "primary",
onClick: onSetToday
}, todayLabel), createElement(Button, {
color: "primary",
onClick: onDismiss
}, cancelLabel), createElement(Button, {
color: "primary",
onClick: onAccept
}, okLabel)));
};
ModalDialog.displayName = 'ModalDialog';
var dialogHeight = 405;
var dialogHeightWithTabs = 455;
var styles = createStyles({
dialogRoot: {
minWidth: DIALOG_WIDTH,
minHeight: dialogHeight
},
dialogRootWider: {
minWidth: DIALOG_WIDTH_WIDER
},
dialog: {
minHeight: dialogHeight,
overflow: 'hidden',
'&:first-child': {
padding: 0
}
},
dialogWithTabs: {
minHeight: dialogHeightWithTabs
},
dialogActions: {
// set justifyContent to default value to fix IE11 layout bug
// see https://github.com/dmtrKovalenko/material-ui-pickers/pull/267
justifyContent: 'flex-start'
},
clearableDialogAction: {
'&:first-child': {
marginRight: 'auto'
}
},
todayDialogAction: {
'&:first-child': {
marginRight: 'auto'
}
},
dialogAction: {// empty but may be needed for override
}
});
var ModalDialog$1 = withStyles(styles, {
name: 'MuiPickersModal'
})(ModalDialog);
var ModalWrapper =
/*@__PURE__*/
function (_super) {
__extends(ModalWrapper, _super);
function ModalWrapper() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
open: false
};
_this.handleKeyDown = function (event) {
switch (event.key) {
case 'Enter':
_this.handleAccept();
break;
default:
// if key is not handled, stop execution
return;
} // if event was handled prevent other side effects
event.preventDefault();
};
_this.handleSetTodayDate = function () {
if (_this.props.onSetToday) {
_this.props.onSetToday();
}
};
_this.open = function () {
_this.setState({
open: true
});
if (_this.props.onOpen) {
_this.props.onOpen();
}
};
_this.close = function () {
_this.setState({
open: false
});
if (_this.props.onClose) {
_this.props.onClose();
}
};
_this.handleAccept = function () {
_this.close();
if (_this.props.onAccept) {
_this.props.onAccept();
}
};
_this.handleDismiss = function () {
_this.close();
if (_this.props.onDismiss) {
_this.props.onDismiss();
}
};
_this.handleClear = function () {
_this.close();
if (_this.props.onClear) {
_this.props.onClear();
}
};
return _this;
}
ModalWrapper.getDerivedStateFromProps = function (nextProps) {
// only if accept = true close the dialog
if (nextProps.isAccepted) {
if (nextProps.onClose) {
nextProps.onClose();
}
return {
open: false
};
}
return null;
};
ModalWrapper.prototype.render = function () {
var _a = this.props,
value = _a.value,
format = _a.format,
children = _a.children,
onAccept = _a.onAccept,
onDismiss = _a.onDismiss,
invalidLabel = _a.invalidLabel,
labelFunc = _a.labelFunc,
okLabel = _a.okLabel,
cancelLabel = _a.cancelLabel,
clearLabel = _a.clearLabel,
clearable = _a.clearable,
todayLabel = _a.todayLabel,
showTodayButton = _a.showTodayButton,
onOpen = _a.onOpen,
onClose = _a.onClose,
onSetToday = _a.onSetToday,
isAccepted = _a.isAccepted,
DialogProps = _a.DialogProps,
showTabs = _a.showTabs,
wider = _a.wider,
other = __rest(_a, ["value", "format", "children", "onAccept", "onDismiss", "invalidLabel", "labelFunc", "okLabel", "cancelLabel", "clearLabel", "clearable", "todayLabel", "showTodayButton", "onOpen", "onClose", "onSetToday", "isAccepted", "DialogProps", "showTabs", "wider"]);
return createElement(Fragment, null, createElement(DateTextField$1, __assign({
value: value,
format: format,
onClick: this.open,
invalidLabel: invalidLabel,
labelFunc: labelFunc,
clearable: clearable
}, other)), createElement(ModalDialog$1, __assign({
wider: wider,
showTabs: showTabs,
open: this.state.open,
onKeyDownInner: this.handleKeyDown,
onClear: this.handleClear,
onAccept: this.handleAccept,
onDismiss: this.handleDismiss,
onSetToday: this.handleSetTodayDate,
clearLabel: clearLabel,
todayLabel: todayLabel,
okLabel: okLabel,
cancelLabel: cancelLabel,
clearable: clearable,
showTodayButton: showTodayButton,
children: children
}, DialogProps)));
};
process.env.NODE_ENV !== "production" ? ModalWrapper.propTypes = {
okLabel: node,
cancelLabel: node,
clearLabel: node,
clearable: bool,
todayLabel: node,
showTodayButton: bool,
onOpen: func,
DialogProps: object,
onClose: func
} : void 0;
ModalWrapper.defaultProps = {
value: new Date(),
okLabel: 'OK',
cancelLabel: 'Cancel',
clearLabel: 'Clear',
todayLabel: 'Today',
clearable: false,
showTodayButton: false,
isAccepted: false
};
return ModalWrapper;
}(PureComponent);
var PickerToolbar = function (_a) {
var children = _a.children,
_b = _a.className,
className = _b === void 0 ? null : _b,
classes = _a.classes,
other = __rest(_a, ["children", "className", "classes"]);
return createElement(Toolbar, __assign({
className: clsx(classes.toolbar, className)
}, other), children);
};
process.env.NODE_ENV !== "production" ? PickerToolbar.propTypes = {
children: arrayOf(node).isRequired,
className: string,
classes: any.isRequired,
innerRef: any
} : void 0;
PickerToolbar.defaultProps = {
className: ''
};
var styles$1 = function (theme) {
return createStyles$1({
toolbar: {
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'center',
height: 100,
backgroundColor: theme.palette.type === 'light' ? theme.palette.primary.main : theme.palette.background.default
}
});
};
var PickerToolbar$1 = withStyles$1(styles$1, {
name: 'MuiPickersToolbar'
})(PickerToolbar);
var ToolbarButton = function (_a) {
var classes = _a.classes,
selected = _a.selected,
label = _a.label,
_b = _a.className,
className = _b === void 0 ? null : _b,
other = __rest(_a, ["classes", "selected", "label", "className"]);
var _c;
return createElement(Typography, __assign({
className: clsx(classes.toolbarBtn, className, (_c = {}, _c[classes.toolbarBtnSelected] = selected, _c))
}, other), label);
};
process.env.NODE_ENV !== "production" ? ToolbarButton.propTypes = {
selected: bool.isRequired,
label: string.isRequired,
classes: any.isRequired,
className: string,
innerRef: any
} : void 0;
ToolbarButton.defaultProps = {
className: ''
};
var styles$2 = function (theme) {
return {
toolbarBtn: {
cursor: 'pointer',
color: 'rgba(255, 255, 255, 0.54)'
},
toolbarBtnSelected: {
color: theme.palette.common.white
}
};
};
var ToolbarButton$1 = withStyles$1(styles$2, {
name: 'MuiPickersToolbarButton'
})(ToolbarButton);
var ArrowLeftIcon = function (props) {
return React__default.createElement(SvgIcon, __assign({}, props), React__default.createElement("path", {
d: "M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"
}), React__default.createElement("path", {
fill: "none",
d: "M0 0h24v24H0V0z"
}));
};
var ArrowRightIcon = function (props) {
return React__default.createElement(SvgIcon, __assign({}, props), React__default.createElement("path", {
d: "M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"
}), React__default.createElement("path", {
fill: "none",
d: "M0 0h24v24H0V0z"
}));
};
var animationDuration = 350;
var styles$3 = function (theme) {
var slideTransition = theme.transitions.create('transform', {
duration: animationDuration,
easing: 'cubic-bezier(0.35, 0.8, 0.4, 1)'
});
return createStyles$1({
transitionContainer: {
display: 'block',
position: 'relative',
'& > *': {
position: 'absolute',
top: 0,
right: 0,
left: 0
}
},
'slideEnter-left': {
willChange: 'transform',
transform: 'translate(100%)'
},
'slideEnter-right': {
willChange: 'transform',
transform: 'translate(-100%)'
},
slideEnterActive: {
transform: 'translate(0%)',
transition: slideTransition
},
slideExit: {
transform: 'translate(0%)'
},
'slideExitActiveLeft-left': {
willChange: 'transform',
transform: 'translate(-200%)',
transition: slideTransition
},
'slideExitActiveLeft-right': {
willChange: 'transform',
transform: 'translate(200%)',
transition: slideTransition
}
});
};
var SlideTransition = function (_a) {
var classes = _a.classes,
_b = _a.className,
className = _b === void 0 ? null : _b,
children = _a.children,
transKey = _a.transKey,
slideDirection = _a.slideDirection;
var transitionClasses = {
enter: classes['slideEnter-' + slideDirection],
enterActive: classes.slideEnterActive,
exit: classes.slideExit,
exitActive: classes['slideExitActiveLeft-' + slideDirection]
};
return createElement(TransitionGroup, {
className: clsx(classes.transitionContainer, className),
childFactory: function (element) {
return cloneElement(element, {
classNames: transitionClasses
});
}
}, createElement(CSSTransition, {
key: transKey + slideDirection,
mountOnEnter: true,
unmountOnExit: true,
timeout: animationDuration,
children: children,
classNames: transitionClasses
}));
};
process.env.NODE_ENV !== "production" ? SlideTransition.propTypes = {
children: node.isRequired,
className: string,
slideDirection: oneOf(['left', 'right']).isRequired,
transKey: string.isRequired,
innerRef: any
} : void 0;
var SlideTransition$1 = withStyles$1(styles$3, {
name: 'MuiPickersSlideTransition'
})(SlideTransition);
var CalendarHeader = function (_a) {
var classes = _a.classes,
theme = _a.theme,
currentMonth = _a.currentMonth,
onMonthChange = _a.onMonthChange,
leftArrowIcon = _a.leftArrowIcon,
rightArrowIcon = _a.rightArrowIcon,
disablePrevMonth = _a.disablePrevMonth,
disableNextMonth = _a.disableNextMonth,
utils = _a.utils,
slideDirection = _a.slideDirection;
var rtl = theme.direction === 'rtl';
var selectNextMonth = function () {
return onMonthChange(utils.getNextMonth(currentMonth), 'left');
};
var selectPreviousMonth = function () {
return onMonthChange(utils.getPreviousMonth(currentMonth), 'right');
};
return createElement("div", null, createElement("div", {
className: classes.switchHeader
}, createElement(IconButton, {
disabled: disablePrevMonth,
onClick: selectPreviousMonth,
className: classes.iconButton
}, rtl ? rightArrowIcon : leftArrowIcon), createElement(SlideTransition$1, {
slideDirection: slideDirection,
transKey: currentMonth.toString(),
className: classes.transitionContainer
}, createElement(Typography, {
align: "center",
variant: "body1"
}, utils.getCalendarHeaderText(currentMonth))), createElement(IconButton, {
disabled: disableNextMonth,
onClick: selectNextMonth,
className: classes.iconButton
}, rtl ? leftArrowIcon : rightArrowIcon)), createElement("div", {
className: classes.daysHeader
}, utils.getWeekdays().map(function (day, index) {
return createElement(Typography, {
key: index,
variant: "caption",
className: classes.dayLabel
}, day);
})));
};
process.env.NODE_ENV !== "production" ? CalendarHeader.propTypes = {
currentMonth: object.isRequired,
onMonthChange: func.isRequired,
leftArrowIcon: node,
rightArrowIcon: node,
disablePrevMonth: bool,
disableNextMonth: bool,
slideDirection: oneOf(['right', 'left']).isRequired,
innerRef: any
} : void 0;
CalendarHeader.displayName = 'CalendarHeader';
CalendarHeader.defaultProps = {
leftArrowIcon: createElement(ArrowLeftIcon, null),
rightArrowIcon: createElement(ArrowRightIcon, null),
disablePrevMonth: false,
disableNextMonth: false
};
var styles$4 = function (theme) {
return createStyles$1({
switchHeader: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: theme.spacing.unit / 2,
marginBottom: theme.spacing.unit
},
transitionContainer: {
width: '100%',
height: 20
},
iconButton: {
zIndex: 2,
backgroundColor: theme.palette.background.paper,
'& > *': {
// label
backgroundColor: theme.palette.background.paper,
'& > *': {
// icon
zIndex: 1,
overflow: 'visible'
}
}
},
daysHeader: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
maxHeight: 16
},
dayLabel: {
width: 36,
margin: '0 2px',
textAlign: 'center',
color: theme.palette.text.hint
}
});
};
var CalendarHeader$1 = withUtils()(withStyles$1(styles$4, {
withTheme: true,
name: 'MuiPickersCalendarHeader'
})(CalendarHeader));
var Day =
/*@__PURE__*/
function (_super) {
__extends(Day, _super);
function Day() {
return _super !== null && _super.apply(this, arguments) || this;
}
Day.prototype.render = function () {
var _a;
var _b = this.props,
children = _b.children,
classes = _b.classes,
disabled = _b.disabled,
hidden = _b.hidden,
current = _b.current,
selected = _b.selected,
other = __rest(_b, ["children", "classes", "disabled", "hidden", "current", "selected"]);
var className = clsx(classes.day, (_a = {}, _a[classes.hidden] = hidden, _a[classes.current] = current, _a[classes.isSelected] = selected, _a[classes.isDisabled] = disabled, _a));
return createElement(IconButton, __assign({
className: className,
tabIndex: hidden || disabled ? -1 : 0
}, other), children);
};
process.env.NODE_ENV !== "production" ? Day.propTypes = {
children: node.isRequired,
classes: object.isRequired,
current: bool,
disabled: bool,
hidden: bool,
selected: bool,
innerRef: any
} : void 0;
Day.defaultProps = {
disabled: false,
hidden: false,
current: false,
selected: false
};
return Day;
}(PureComponent);
var styles$5 = function (theme) {
return createStyles$1({
day: {
width: 36,
height: 36,
fontSize: theme.typography.caption.fontSize,
margin: '0 2px',
color: theme.palette.text.primary,
fontWeight: theme.typography.fontWeightMedium,
padding: 0
},
hidden: {
opacity: 0,
pointerEvents: 'none'
},
current: {
color: theme.palette.primary.main,
fontWeight: 600
},
isSelected: {
color: theme.palette.common.white,
backgroundColor: theme.palette.primary.main,
fontWeight: theme.typography.fontWeightMedium,
'&:hover': {
backgroundColor: theme.palette.primary.main
}
},
isDisabled: {
pointerEvents: 'none',
color: theme.palette.text.hint
}
});
};
var Day$1 = withStyles$1(styles$5, {
name: 'MuiPickersDay'
})(Day);
var DayWrapper =
/*@__PURE__*/
function (_super) {
__extends(DayWrapper, _super);
function DayWrapper() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handleClick = function () {
_this.props.onSelect(_this.props.value);
};
return _this;
}
DayWrapper.prototype.render = function () {
var _a = this.props,
children = _a.children,
value = _a.value,
dayInCurrentMonth = _a.dayInCurrentMonth,
disabled = _a.disabled,
onSelect = _a.onSelect,
other = __rest(_a, ["children", "value", "dayInCurrentMonth", "disabled", "onSelect"]);
return createElement("div", __assign({
onClick: dayInCurrentMonth && !disabled ? this.handleClick : undefined,
onKeyPress: dayInCurrentMonth && !disabled ? this.handleClick : undefined,
role: "presentation"
}, other), children);
};
process.env.NODE_ENV !== "production" ? DayWrapper.propTypes = {
children: node.isRequired,
dayInCurrentMonth: bool,
disabled: bool,
onSelect: func.isRequired,
value: any.isRequired
} : void 0;
DayWrapper.defaultProps = {
dayInCurrentMonth: true,
disabled: false
};
return DayWrapper;
}(PureComponent);
var Calendar =
/*@__PURE__*/
function (_super) {
__extends(Calendar, _super);
function Calendar() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
slideDirection: 'left',
currentMonth: _this.props.utils.startOfMonth(_this.props.date)
};
_this.onDateSelect = function (day, isFinish) {
if (isFinish === void 0) {
isFinish = true;
}
var _a = _this.props,
date = _a.date,
utils = _a.utils;
_this.props.onChange(utils.mergeDateAndTime(day, date), isFinish);
};
_this.handleChangeMonth = function (newMonth, slideDirection) {
if (_this.props.onMonthChange) {
_this.props.onMonthChange(newMonth);
}
_this.setState({
currentMonth: newMonth,
slideDirection: slideDirection
});
};
_this.validateMinMaxDate = function (day) {
var _a = _this.props,
minDate = _a.minDate,
maxDate = _a.maxDate,
utils = _a.utils,
disableFuture = _a.disableFuture,
disablePast = _a.disablePast;
var now = utils.date();
return Boolean(disableFuture && utils.isAfterDay(day, now) || disablePast && utils.isBeforeDay(day, now) || minDate && utils.isBeforeDay(day, utils.date(minDate)) || maxDate && utils.isAfterDay(day, utils.date(maxDate)));
};
_this.shouldDisablePrevMonth = function () {
var _a = _this.props,
utils = _a.utils,
disablePast = _a.disablePast,
minDate = _a.minDate;
var now = utils.date();
var firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : utils.date(minDate));
return !utils.isBefore(firstEnabledMonth, _this.state.currentMonth);
};
_this.shouldDisableNextMonth = function () {
var _a = _this.props,
utils = _a.utils,
disableFuture = _a.disableFuture,
maxDate = _a.maxDate;
var now = utils.date();
var lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : utils.date(maxDate));
return !utils.isAfter(lastEnabledMonth, _this.state.currentMonth);
};
_this.shouldDisableDate = function (day) {
var shouldDisableDate = _this.props.shouldDisableDate;
return _this.validateMinMaxDate(day) || Boolean(shouldDisableDate && shouldDisableDate(day));
};
_this.moveToDay = function (day) {
if (day && !_this.shouldDisableDate(day)) {
_this.onDateSelect(day, false);
}
};
_this.handleKeyDown = function (event) {
var _a = _this.props,
theme = _a.theme,
date = _a.date,
utils = _a.utils;
switch (event.key) {
case 'ArrowUp':
_this.moveToDay(utils.addDays(date, -7));
break;
case 'ArrowDown':
_this.moveToDay(utils.addDays(date, 7));
break;
case 'ArrowLeft':
theme.direction === 'ltr' ? _this.moveToDay(utils.addDays(date, -1)) : _this.moveToDay(utils.addDays(date, 1));
break;
case 'ArrowRight':
theme.direction === 'ltr' ? _this.moveToDay(utils.addDays(date, 1)) : _this.moveToDay(utils.addDays(date, -1));
break;
default:
// if key is not handled, stop execution
return;
} // if event was handled prevent other side effects (e.g. page scroll)
event.preventDefault();
};
_this.renderWeeks = function () {
var _a = _this.props,
utils = _a.utils,
classes = _a.classes;
var weeks = utils.getWeekArray(_this.state.currentMonth);
return weeks.map(function (week) {
return createElement("div", {
key: "week-" + week[0].toString(),
className: classes.week
}, _this.renderDays(week));
});
};
_this.renderDays = function (week) {
var _a = _this.props,
date = _a.date,
renderDay = _a.renderDay,
utils = _a.utils;
var now = utils.date();
var selectedDate = utils.startOfDay(date);
var currentMonthNumber = utils.getMonth(_this.state.currentMonth);
return week.map(function (day) {
var disabled = _this.shouldDisableDate(day);
var isDayInCurrentMonth = utils.getMonth(day) === currentMonthNumber;
var dayComponent = createElement(Day$1, {
disabled: disabled,
current: utils.isSameDay(day, now),
hidden: !isDayInCurrentMonth,
selected: utils.isSameDay(selectedDate, day)
}, utils.getDayText(day));
if (renderDay) {
dayComponent = renderDay(day, selectedDate, isDayInCurrentMonth, dayComponent);
}
return createElement(DayWrapper, {
value: day,
key: day.toString(),
disabled: disabled,
dayInCurrentMonth: isDayInCurrentMonth,
onSelect: _this.onDateSelect
}, dayComponent);
});
};
return _this;
}
Calendar.getDerivedStateFromProps = function (nextProps, state) {
var utils = nextProps.utils,
nextDate = nextProps.date;
if (!utils.isEqual(nextDate, state.lastDate)) {
var nextMonth = utils.getMonth(nextDate);
var lastMonth = utils.getMonth(state.lastDate || nextDate);
return {
lastDate: nextDate,
currentMonth: nextProps.utils.startOfMonth(nextDate),
// prettier-ignore
slideDirection: nextMonth === lastMonth ? state.slideDirection : nextMonth > lastMonth ? 'left' : 'right'
};
}
return null;
};
Calendar.prototype.componentDidMount = function () {
var _a = this.props,
date = _a.date,
minDate = _a.minDate,
maxDate = _a.maxDate,
utils = _a.utils,
disablePast = _a.disablePast,
disableFuture = _a.disableFuture;
if (this.shouldDisableDate(date)) {
var closestEnabledDate = findClosestEnabledDate({
date: date,
utils: utils,
minDate: minDate,
maxDate: maxDate,
disablePast: Boolean(disablePast),
disableFuture: Boolean(disableFuture),
shouldDisableDate: this.shouldDisableDate
});
this.onDateSelect(closestEnabledDate || minDate, false);
}
};
Calendar.prototype.render = function () {
var _a = this.state,
currentMonth = _a.currentMonth,
slideDirection = _a.slideDirection;
var _b = this.props,
classes = _b.classes,
allowKeyboardControl = _b.allowKeyboardControl;
return createElement(Fragment, null, allowKeyboardControl && createElement(EventListener, {
target: "window",
onKeyDown: this.handleKeyDown
}), createElement(CalendarHeader$1, {
slideDirection: slideDirection,
currentMonth: currentMonth,
onMonthChange: this.handleChangeMonth,
leftArrowIcon: this.props.leftArrowIcon,
rightArrowIcon: this.props.rightArrowIcon,
disablePrevMonth: this.shouldDisablePrevMonth(),
disableNextMonth: this.shouldDisableNextMonth()
}), createElement(SlideTransition$1, {
slideDirection: slideDirection,
transKey: currentMonth.toString(),
className: classes.transitionContainer
}, createElement("div", null, this.renderWeeks())));
};
process.env.NODE_ENV !== "production" ? Calendar.propTypes = {
date: object.isRequired,
minDate: DomainPropTypes.date,
maxDate: DomainPropTypes.date,
onChange: func.isRequired,
disablePast: bool,
disableFuture: bool,
renderDay: func,
shouldDisableDate: func,
utils: object.isRequired,
allowKeyboardControl: bool,
innerRef: any
} : void 0;
Calendar.defaultProps = {
minDate: new Date('1900-01-01'),
maxDate: new Date('2100-01-01'),
disablePast: false,
disableFuture: false,
allowKeyboardControl: true
};
return Calendar;
}(Component);
var styles$6 = function (theme) {
return {
transitionContainer: {
minHeight: 36 * 6,
marginTop: theme.spacing.unit * 1.5
},
week: {
display: 'flex',
justifyContent: 'center'
}
};
};
var Calendar$1 = withStyles$1(styles$6, {
name: 'MuiPickersCalendar',
withTheme: true
})(withUtils()(Calendar));
var Month =
/*@__PURE__*/
function (_super) {
__extends(Month, _super);
function Month() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handleClick = function () {
_this.props.onSelect(_this.props.value);
};
return _this;
}
Month.prototype.render = function () {
var _a;
var _b = this.props,
classes = _b.classes,
selected = _b.selected,
disabled = _b.disabled,
value = _b.value,
children = _b.children,
other = __rest(_b, ["classes", "selected", "disabled", "value", "children"]);
return createElement(Typography, __assign({
role: "button",
component: "div",
className: clsx(classes.root, (_a = {}, _a[classes.selected] = selected, _a[classes.disabled] = disabled, _a)),
tabIndex: disabled ? -1 : 0,
onClick: this.handleClick,
onKeyPress: this.handleClick,
color: selected ? 'primary' : 'default',
variant: selected ? 'h5' : 'subtitle1',
children: children
}, other));
};
Month.defaultProps = {
selected: false,
disabled: false
};
return Month;
}(PureComponent);
var styles$7 = function (theme) {
return createStyles$1({
root: {
flex: '1 0 33.33%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
outline: 'none',
height: 75,
transition: theme.transitions.create('font-size', {
duration: '100ms'
}),
'&:focus': {
color: theme.palette.primary.main,
fontWeight: theme.typography.fontWeightMedium
}
},
selected: {
color: theme.palette.primary.main,
fontWeight: theme.typography.fontWeightMedium
},
disabled: {
pointerEvents: 'none',
color: theme.palette.text.hint
}
});
};
var Month$1 = withStyles$1(styles$7, {
name: 'MuiPickersMonth'
})(Month);
var MonthSelection =
/*@__PURE__*/
function (_super) {
__extends(MonthSelection, _super);
function MonthSelection() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.onMonthSelect = function (month) {
var _a = _this.props,
date = _a.date,
onChange = _a.onChange,
utils = _a.utils;
var newDate = utils.setMonth(date, month);
onChange(newDate);
};
_this.shouldDisableMonth = function (month) {
var _a = _this.props,
utils = _a.utils,
disablePast = _a.disablePast,
disableFuture = _a.disableFuture,
minDate = _a.minDate,
maxDate = _a.maxDate;
var now = utils.date();
var utilMinDate = utils.date(minDate);
var utilMaxDate = utils.date(maxDate);
var firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, utilMinDate) ? now : utilMinDate);
var