material-ui-pickers-fork
Version:
React components, that implements material design pickers for material-ui v1
1,664 lines (1,440 loc) • 109 kB
JavaScript
import _extends from '@babel/runtime/helpers/esm/extends';
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
import React, { PureComponent, Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import EventListener from 'react-event-listener';
import withStyles from '@material-ui/core/styles/withStyles';
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 _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
import MaskedInput from 'react-text-mask';
import Icon from '@material-ui/core/Icon';
import InputAdornment from '@material-ui/core/InputAdornment';
import TextField from '@material-ui/core/TextField';
import IconButton from '@material-ui/core/IconButton';
import keycode from 'keycode';
import TransitionGroup from 'react-transition-group/TransitionGroup';
import CSSTransition from 'react-transition-group/CSSTransition';
import Typography from '@material-ui/core/Typography';
import throttle from 'lodash.throttle';
import { findDOMNode } from 'react-dom';
import Toolbar from '@material-ui/core/Toolbar';
import _createClass from '@babel/runtime/helpers/esm/createClass';
import compose from 'recompose/compose';
import lifecycle from 'recompose/lifecycle';
import setDisplayName from 'recompose/setDisplayName';
import withHandlers from 'recompose/withHandlers';
import toRenderProps from 'recompose/toRenderProps';
import withState from 'recompose/withState';
import withTheme from '@material-ui/core/styles/withTheme';
import Paper from '@material-ui/core/Paper';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
var dialogWidth = 310;
var styles = {
dialogRoot: {
minWidth: dialogWidth
},
dialog: {
width: dialogWidth,
overflow: 'hidden',
'&:first-child': {
padding: 0
}
},
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 = function ModalDialog(_ref) {
var _classnames;
var children = _ref.children,
classes = _ref.classes,
onKeyDown = _ref.onKeyDown,
onAccept = _ref.onAccept,
onDismiss = _ref.onDismiss,
onClear = _ref.onClear,
onSetToday = _ref.onSetToday,
okLabel = _ref.okLabel,
cancelLabel = _ref.cancelLabel,
clearLabel = _ref.clearLabel,
todayLabel = _ref.todayLabel,
dialogContentClassName = _ref.dialogContentClassName,
clearable = _ref.clearable,
showTodayButton = _ref.showTodayButton,
other = _objectWithoutPropertiesLoose(_ref, ["children", "classes", "onKeyDown", "onAccept", "onDismiss", "onClear", "onSetToday", "okLabel", "cancelLabel", "clearLabel", "todayLabel", "dialogContentClassName", "clearable", "showTodayButton"]);
return React.createElement(Dialog, _extends({
onClose: onDismiss,
classes: {
paper: classes.dialogRoot
}
}, other), React.createElement(EventListener, {
target: "window",
onKeyDown: onKeyDown
}), React.createElement(DialogContent, {
className: classnames(classes.dialog, dialogContentClassName)
}, children), React.createElement(DialogActions, {
classes: {
root: clearable && classes.dialogActions,
action: classnames(classes.dialogAction, (_classnames = {}, _classnames[classes.clearableDialogAction] = clearable, _classnames[classes.todayDialogAction] = !clearable && showTodayButton, _classnames))
}
}, clearable && React.createElement(Button, {
color: "primary",
onClick: onClear,
"aria-label": clearLabel
}, clearLabel), !clearable && showTodayButton && React.createElement(Button, {
color: "primary",
onClick: onSetToday,
"aria-label": todayLabel
}, todayLabel), React.createElement(Button, {
color: "primary",
onClick: onDismiss,
"aria-label": cancelLabel
}, cancelLabel), React.createElement(Button, {
color: "primary",
onClick: onAccept,
"aria-label": okLabel
}, okLabel)));
};
ModalDialog.propTypes = {
children: PropTypes.node.isRequired,
onKeyDown: PropTypes.func.isRequired,
onAccept: PropTypes.func.isRequired,
onDismiss: PropTypes.func.isRequired,
onClear: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
dialogContentClassName: PropTypes.string,
okLabel: PropTypes.node.isRequired,
cancelLabel: PropTypes.node.isRequired,
clearLabel: PropTypes.node.isRequired,
clearable: PropTypes.bool.isRequired,
todayLabel: PropTypes.node.isRequired,
showTodayButton: PropTypes.bool.isRequired,
onSetToday: PropTypes.func.isRequired
};
ModalDialog.defaultProps = {
dialogContentClassName: ''
};
var ModalDialog$1 = withStyles(styles, {
name: 'MuiPickersModal'
})(ModalDialog);
var date = PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]);
var DomainPropTypes = {
date: date
};
var Input =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(Input, _PureComponent);
function Input() {
return _PureComponent.apply(this, arguments) || this;
}
var _proto = Input.prototype;
_proto.render = function render() {
var _this$props = this.props,
inputRef = _this$props.inputRef,
props = _objectWithoutPropertiesLoose(_this$props, ["inputRef"]);
return this.props.mask ? React.createElement(MaskedInput, _extends({}, props, {
ref: inputRef
})) : React.createElement("input", _extends({}, props, {
ref: inputRef
}));
};
return Input;
}(PureComponent);
Input.propTypes = {
mask: PropTypes.any,
inputRef: PropTypes.func.isRequired
};
Input.defaultProps = {
mask: undefined
};
var _React$createContext = React.createContext(),
Consumer = _React$createContext.Consumer,
Provider = _React$createContext.Provider;
var MuiPickersContextConsumer = Consumer;
var MuiPickersUtilsProvider =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(MuiPickersUtilsProvider, _Component);
function MuiPickersUtilsProvider() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.state = {
utils: null
};
return _this;
}
MuiPickersUtilsProvider.getDerivedStateFromProps = function getDerivedStateFromProps(_ref) {
var Utils = _ref.utils,
locale = _ref.locale,
moment = _ref.moment;
return {
utils: new Utils({
locale: locale,
moment: moment
})
};
};
var _proto = MuiPickersUtilsProvider.prototype;
_proto.render = function render() {
return React.createElement(Provider, {
value: this.state.utils
}, this.props.children);
};
return MuiPickersUtilsProvider;
}(Component);
MuiPickersUtilsProvider.propTypes = {
/* eslint-disable react/no-unused-prop-types */
utils: PropTypes.func.isRequired,
locale: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
children: PropTypes.oneOfType([PropTypes.element.isRequired, PropTypes.arrayOf(PropTypes.element.isRequired)]).isRequired,
moment: PropTypes.func
};
MuiPickersUtilsProvider.defaultProps = {
locale: undefined,
moment: undefined
};
var WithUtils = function WithUtils() {
return function (Component$$1) {
var withUtils = function withUtils(props) {
return React.createElement(MuiPickersContextConsumer, null, function (utils) {
return React.createElement(Component$$1, _extends({
utils: utils
}, props));
});
};
withUtils.displayName = "WithUtils(" + (Component$$1.displayName || Component$$1.name) + ")";
return withUtils;
};
};
var getDisplayDate = function getDisplayDate(props) {
var utils = props.utils,
value = props.value,
format = props.format,
invalidLabel = props.invalidLabel,
emptyLabel = props.emptyLabel,
labelFunc = props.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 getError(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 (!utils.isValid(value)) {
// if null - do not show error
if (utils.isNull(value)) {
return '';
}
return invalidDateMessage;
}
if (maxDate && utils.isAfter(value, maxDate) || disableFuture && utils.isAfter(value, utils.endOfDay(utils.date()))) {
return maxDateMessage;
}
if (minDate && utils.isBefore(value, minDate) || disablePast && utils.isBefore(value, utils.startOfDay(utils.date()))) {
return minDateMessage;
}
return '';
};
var DateTextField =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(DateTextField, _PureComponent);
function DateTextField() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
_this.state = DateTextField.updateState(_this.props);
_this.commitUpdates = function (value) {
var _this$props = _this.props,
clearable = _this$props.clearable,
onClear = _this$props.onClear,
utils = _this$props.utils,
format = _this$props.format,
onError = _this$props.onError;
if (value === '') {
if (_this.props.value === null) {
_this.setState(DateTextField.updateState(_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)) {
_this.props.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 _this$props2 = _this.props,
utils = _this$props2.utils,
format = _this$props2.format,
onInputChange = _this$props2.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 {
_this.commitUpdates(e.target.value);
}
}
};
_this.openPicker = function (e) {
var _this$props3 = _this.props,
disabled = _this$props3.disabled,
onClick = _this$props3.onClick;
if (!disabled) {
onClick(e);
}
};
return _this;
}
var _proto = DateTextField.prototype;
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (!this.props.utils.isEqual(this.props.value, prevProps.value) || prevProps.format !== this.props.format || prevProps.maxDate !== this.props.maxDate || prevProps.minDate !== this.props.minDate || prevProps.emptyLabel !== this.props.emptyLabel || prevProps.utils !== this.props.utils) {
/* eslint-disable-next-line react/no-did-update-set-state */
this.setState(DateTextField.updateState(this.props));
}
};
_proto.render = function render() {
var _this$props4 = this.props,
adornmentPosition = _this$props4.adornmentPosition,
classes = _this$props4.classes,
clearable = _this$props4.clearable,
disabled = _this$props4.disabled,
disableFuture = _this$props4.disableFuture,
disableOpenOnEnter = _this$props4.disableOpenOnEnter,
disablePast = _this$props4.disablePast,
emptyLabel = _this$props4.emptyLabel,
format = _this$props4.format,
InputAdornmentProps = _this$props4.InputAdornmentProps,
InputProps = _this$props4.InputProps,
invalidDateMessage = _this$props4.invalidDateMessage,
invalidLabel = _this$props4.invalidLabel,
keyboard = _this$props4.keyboard,
keyboardIcon = _this$props4.keyboardIcon,
labelFunc = _this$props4.labelFunc,
mask = _this$props4.mask,
maxDate = _this$props4.maxDate,
maxDateMessage = _this$props4.maxDateMessage,
minDate = _this$props4.minDate,
minDateMessage = _this$props4.minDateMessage,
onBlur = _this$props4.onBlur,
onClear = _this$props4.onClear,
onClick = _this$props4.onClick,
TextFieldComponent = _this$props4.TextFieldComponent,
utils = _this$props4.utils,
value = _this$props4.value,
onInputChange = _this$props4.onInputChange,
other = _objectWithoutPropertiesLoose(_this$props4, ["adornmentPosition", "classes", "clearable", "disabled", "disableFuture", "disableOpenOnEnter", "disablePast", "emptyLabel", "format", "InputAdornmentProps", "InputProps", "invalidDateMessage", "invalidLabel", "keyboard", "keyboardIcon", "labelFunc", "mask", "maxDate", "maxDateMessage", "minDate", "minDateMessage", "onBlur", "onClear", "onClick", "TextFieldComponent", "utils", "value", "onInputChange"]);
var _this$state = this.state,
displayValue = _this$state.displayValue,
error = _this$state.error;
var localInputProps = {
className: classes.input,
inputComponent: Input,
inputProps: {
mask: !keyboard ? null : mask,
readOnly: !keyboard
}
};
if (keyboard) {
localInputProps[adornmentPosition + "Adornment"] = React.createElement(InputAdornment, _extends({
position: adornmentPosition
}, InputAdornmentProps), React.createElement(IconButton, {
disabled: disabled,
onClick: this.openPicker
}, React.createElement(Icon, null, " ", keyboardIcon, " ")));
}
return React.createElement(TextFieldComponent, _extends({
onClick: this.handleFocus,
error: !!error,
helperText: error,
onKeyPress: this.handleKeyPress,
onBlur: this.handleBlur,
disabled: disabled,
value: displayValue
}, other, {
onChange: this.handleChange,
InputProps: _extends({}, localInputProps, InputProps)
}));
};
return DateTextField;
}(PureComponent);
DateTextField.updateState = function (props) {
return {
value: props.value,
displayValue: getDisplayDate(props),
error: getError(props.utils.date(props.value), props)
};
};
DateTextField.propTypes = {
classes: PropTypes.shape({}).isRequired,
value: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number, PropTypes.instanceOf(Date)]),
minDate: DomainPropTypes.date,
maxDate: DomainPropTypes.date,
disablePast: PropTypes.bool,
disableFuture: PropTypes.bool,
format: PropTypes.string,
onBlur: PropTypes.func,
onChange: PropTypes.func.isRequired,
onClear: PropTypes.func,
onClick: PropTypes.func.isRequired,
clearable: PropTypes.bool,
utils: PropTypes.object.isRequired,
disabled: PropTypes.bool,
InputProps: PropTypes.shape(),
/** Input mask, used in keyboard mode read more <a href="https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#readme">here</a> */
mask: PropTypes.any,
/** Error message, shown if date is less then minimal date */
minDateMessage: PropTypes.node,
/** Error message, shown if date is more then maximal date */
maxDateMessage: PropTypes.node,
/** Message displaying in text field, if date is invalid (doesn't work in keyboard mode) */
invalidLabel: PropTypes.string,
/** Message displaying in text field, if null passed (doesn't work in keyboard mode) */
emptyLabel: PropTypes.string,
/** Dynamic label generation function (date, invalidLabel) => string */
labelFunc: PropTypes.func,
/** On/off manual keyboard input mode */
keyboard: PropTypes.bool,
/** Icon displayed for open picker button in keyboard mode */
keyboardIcon: PropTypes.node,
/** enables/disable automatic opening of the picker when the user clicks enter */
disableOpenOnEnter: PropTypes.bool,
/** Message, appearing when date cannot be parsed */
invalidDateMessage: PropTypes.node,
/** Component that should replace the default Material-UI TextField */
TextFieldComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/** Props to pass to keyboard input adornment */
InputAdornmentProps: PropTypes.object,
/** Specifies position of keyboard button adornment */
adornmentPosition: PropTypes.oneOf(['start', 'end']),
/** Callback firing when date that applied in the keyboard is invalid */
onError: PropTypes.func,
/** Callback firing on change input in keyboard mode */
onInputChange: PropTypes.func
};
DateTextField.defaultProps = {
disabled: false,
invalidLabel: 'Unknown',
emptyLabel: '',
value: new Date(),
labelFunc: undefined,
format: undefined,
InputProps: undefined,
keyboard: false,
mask: undefined,
keyboardIcon: 'event',
disableOpenOnEnter: false,
invalidDateMessage: 'Invalid Date Format',
clearable: false,
onBlur: undefined,
onClear: undefined,
disablePast: false,
disableFuture: false,
onError: undefined,
onInputChange: undefined,
minDate: '1900-01-01',
maxDate: '2100-01-01',
minDateMessage: 'Date should not be before minimal date',
maxDateMessage: 'Date should not be after maximal date',
TextFieldComponent: TextField,
InputAdornmentProps: {},
adornmentPosition: 'end'
};
var styles$1 = {
input: {
alignItems: 'flex-end'
}
};
var DateTextField$1 = withStyles(styles$1)(WithUtils()(DateTextField));
var ModalWrapper =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(ModalWrapper, _PureComponent);
function ModalWrapper() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
_this.state = {
open: false
};
_this.handleKeyDown = function (event) {
switch (keycode(event)) {
case 'enter':
_this.handleAccept();
break;
default:
// if keycode 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 getDerivedStateFromProps(nextProps) {
// only if accept = true close the dialog
if (nextProps.isAccepted) {
return {
open: false
};
}
return null;
};
var _proto = ModalWrapper.prototype;
_proto.render = function render() {
var _this$props = this.props,
value = _this$props.value,
format = _this$props.format,
children = _this$props.children,
dialogContentClassName = _this$props.dialogContentClassName,
onAccept = _this$props.onAccept,
onDismiss = _this$props.onDismiss,
invalidLabel = _this$props.invalidLabel,
labelFunc = _this$props.labelFunc,
okLabel = _this$props.okLabel,
cancelLabel = _this$props.cancelLabel,
clearLabel = _this$props.clearLabel,
clearable = _this$props.clearable,
todayLabel = _this$props.todayLabel,
showTodayButton = _this$props.showTodayButton,
onOpen = _this$props.onOpen,
onClose = _this$props.onClose,
onSetToday = _this$props.onSetToday,
isAccepted = _this$props.isAccepted,
container = _this$props.container,
other = _objectWithoutPropertiesLoose(_this$props, ["value", "format", "children", "dialogContentClassName", "onAccept", "onDismiss", "invalidLabel", "labelFunc", "okLabel", "cancelLabel", "clearLabel", "clearable", "todayLabel", "showTodayButton", "onOpen", "onClose", "onSetToday", "isAccepted", "container"]);
return React.createElement(Fragment, null, React.createElement(DateTextField$1, _extends({
value: value,
format: format,
onClick: this.open // onFocus={this.togglePicker} <- Currently not properly works with .blur() on TextField
,
invalidLabel: invalidLabel,
labelFunc: labelFunc,
clearable: clearable
}, other)), React.createElement(ModalDialog$1, {
open: this.state.open,
onKeyDown: this.handleKeyDown,
onClear: this.handleClear,
onAccept: this.handleAccept,
onDismiss: this.handleDismiss,
onSetToday: this.handleSetTodayDate,
dialogContentClassName: dialogContentClassName,
clearLabel: clearLabel,
todayLabel: todayLabel,
okLabel: okLabel,
cancelLabel: cancelLabel,
clearable: clearable,
showTodayButton: showTodayButton,
container: container
}, children));
};
return ModalWrapper;
}(PureComponent);
ModalWrapper.propTypes = {
/** Picker value */
value: DomainPropTypes.date,
/** Format string */
invalidLabel: PropTypes.node,
/** Function for dynamic rendering label (date, invalidLabel) => string */
labelFunc: PropTypes.func,
/** "OK" label message */
okLabel: PropTypes.node,
/** "Cancel" label message */
cancelLabel: PropTypes.node,
/** "Clear" label message */
clearLabel: PropTypes.node,
/** If true clear button will be displayed */
clearable: PropTypes.bool,
/** "Today" label message */
todayLabel: PropTypes.string,
/**
* If true today button will be displayed
* <b>Note*</b> that clear button has higher priority
*/
showTodayButton: PropTypes.bool,
/** On open callback */
onOpen: PropTypes.func,
/** On close callback */
onClose: PropTypes.func,
/** Format string */
format: PropTypes.string,
onAccept: PropTypes.func,
onDismiss: PropTypes.func,
onClear: PropTypes.func,
onSetToday: PropTypes.func,
children: PropTypes.node.isRequired,
dialogContentClassName: PropTypes.string,
isAccepted: PropTypes.bool.isRequired,
container: PropTypes.node
};
ModalWrapper.defaultProps = {
dialogContentClassName: '',
invalidLabel: undefined,
value: new Date(),
labelFunc: undefined,
okLabel: 'OK',
cancelLabel: 'Cancel',
clearLabel: 'Clear',
todayLabel: 'Today',
clearable: false,
showTodayButton: false,
format: undefined,
onAccept: undefined,
onDismiss: undefined,
onClear: undefined,
onOpen: undefined,
onClose: undefined,
onSetToday: undefined,
container: undefined
};
/* eslint-disable import/prefer-default-export */
var findClosestEnabledDate = function findClosestEnabledDate(_ref) {
var date = _ref.date,
utils = _ref.utils,
minDate = _ref.minDate,
maxDate = _ref.maxDate,
disableFuture = _ref.disableFuture,
disablePast = _ref.disablePast,
shouldDisableDate = _ref.shouldDisableDate;
var now = utils.date();
if ((disableFuture || disablePast) && !shouldDisableDate(now)) {
return now;
}
var diffFromMaxDate = Math.abs(utils.getDiff(date, maxDate));
var diffFromMinDate = Math.abs(utils.getDiff(date, minDate));
return diffFromMaxDate < diffFromMinDate ? utils.date(maxDate) : utils.date(minDate);
};
var animationDuration = 350;
var transitionFactory = function transitionFactory(props) {
return function (child) {
return React.cloneElement(child, props);
};
};
var SlideTransition = function SlideTransition(_ref) {
var classes = _ref.classes,
className = _ref.className,
children = _ref.children,
transKey = _ref.transKey,
slideDirection = _ref.slideDirection;
return React.createElement(TransitionGroup, {
className: classnames(classes.transitionContainer, className),
childFactory: transitionFactory({
classNames: {
enter: classes["slideEnter-" + slideDirection],
enterActive: classes.slideEnterActive,
exit: classes.slideExit,
exitActive: classes["slideExitActiveLeft-" + slideDirection]
}
})
}, React.createElement(CSSTransition, {
key: transKey,
mountOnEnter: true,
unmountOnExit: true,
timeout: animationDuration
}, children));
};
SlideTransition.propTypes = {
classes: PropTypes.shape({}).isRequired,
children: PropTypes.node.isRequired,
className: PropTypes.string,
slideDirection: PropTypes.oneOf(['left', 'right']).isRequired,
transKey: PropTypes.string.isRequired
};
SlideTransition.defaultProps = {
className: undefined
};
var styles$2 = function styles(theme) {
var slideTransition = theme.transitions.create('transform', {
duration: animationDuration,
easing: 'cubic-bezier(0.35, 0.8, 0.4, 1)'
});
return {
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(-100%)',
transition: slideTransition
},
'slideExitActiveLeft-right': {
willChange: 'transform',
transform: 'translate(100%)',
transition: slideTransition
}
};
};
var SlideTransition$1 = withStyles(styles$2, {
name: 'MuiPickersSlideTransition'
})(SlideTransition);
var CalendarHeader = function CalendarHeader(_ref) {
var classes = _ref.classes,
theme = _ref.theme,
currentMonth = _ref.currentMonth,
onMonthChange = _ref.onMonthChange,
leftArrowIcon = _ref.leftArrowIcon,
rightArrowIcon = _ref.rightArrowIcon,
disablePrevMonth = _ref.disablePrevMonth,
disableNextMonth = _ref.disableNextMonth,
utils = _ref.utils,
slideDirection = _ref.slideDirection;
var rtl = theme.direction === 'rtl';
var selectNextMonth = function selectNextMonth() {
return onMonthChange(utils.getNextMonth(currentMonth), 'left');
};
var selectPreviousMonth = function selectPreviousMonth() {
return onMonthChange(utils.getPreviousMonth(currentMonth), 'right');
};
return React.createElement("div", null, React.createElement("div", {
className: classes.switchHeader
}, React.createElement(IconButton, {
disabled: disablePrevMonth,
onClick: selectPreviousMonth,
className: classes.iconButton
}, React.createElement(Icon, null, rtl ? rightArrowIcon : leftArrowIcon)), React.createElement(SlideTransition$1, {
slideDirection: slideDirection,
transKey: currentMonth,
className: classes.transitionContainer
}, React.createElement(Typography, {
align: "center",
variant: "body1"
}, utils.getCalendarHeaderText(currentMonth))), React.createElement(IconButton, {
disabled: disableNextMonth,
onClick: selectNextMonth,
className: classes.iconButton
}, React.createElement(Icon, null, rtl ? leftArrowIcon : rightArrowIcon))), React.createElement("div", {
className: classes.daysHeader
}, utils.getWeekdays().map(function (day, index) {
return React.createElement(Typography, {
key: index // eslint-disable-line react/no-array-index-key
,
variant: "caption",
className: classes.dayLabel
}, day);
})));
};
CalendarHeader.propTypes = {
currentMonth: PropTypes.object.isRequired,
onMonthChange: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
leftArrowIcon: PropTypes.node,
rightArrowIcon: PropTypes.node,
disablePrevMonth: PropTypes.bool,
disableNextMonth: PropTypes.bool,
utils: PropTypes.object.isRequired,
slideDirection: PropTypes.oneOf(['right', 'left']).isRequired
};
CalendarHeader.defaultProps = {
leftArrowIcon: 'keyboard_arrow_left',
rightArrowIcon: 'keyboard_arrow_right',
disablePrevMonth: false,
disableNextMonth: false
};
var styles$3 = function styles(theme) {
return {
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
}
}
},
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 = withStyles(styles$3, {
withTheme: true,
name: 'MuiPickersCalendarHeader'
})(WithUtils()(CalendarHeader));
var Day =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(Day, _PureComponent);
function Day() {
return _PureComponent.apply(this, arguments) || this;
}
var _proto = Day.prototype;
_proto.render = function render() {
var _classnames;
var _this$props = this.props,
children = _this$props.children,
classes = _this$props.classes,
disabled = _this$props.disabled,
hidden = _this$props.hidden,
current = _this$props.current,
selected = _this$props.selected,
other = _objectWithoutPropertiesLoose(_this$props, ["children", "classes", "disabled", "hidden", "current", "selected"]);
var className = classnames(classes.day, (_classnames = {}, _classnames[classes.hidden] = hidden, _classnames[classes.current] = current, _classnames[classes.selected] = selected, _classnames[classes.disabled] = disabled, _classnames));
return React.createElement(IconButton, _extends({
className: className,
tabIndex: hidden || disabled ? -1 : 0
}, other), React.createElement("span", null, " ", children, " "));
};
return Day;
}(PureComponent);
Day.propTypes = {
children: PropTypes.node.isRequired,
classes: PropTypes.object.isRequired,
current: PropTypes.bool,
disabled: PropTypes.bool,
hidden: PropTypes.bool,
selected: PropTypes.bool
};
Day.defaultProps = {
disabled: false,
hidden: false,
current: false,
selected: false
};
var styles$4 = function styles(theme) {
return {
day: {
width: 36,
height: 36,
fontSize: theme.typography.caption.fontSize,
margin: '0 2px',
color: theme.palette.text.primary,
fontWeight: theme.typography.fontWeightMedium
},
hidden: {
opacity: 0,
pointerEvents: 'none'
},
current: {
color: theme.palette.primary.main,
fontWeight: 600
},
selected: {
color: theme.palette.common.white,
backgroundColor: theme.palette.primary.main,
fontWeight: theme.typography.fontWeightMedium,
'&:hover': {
backgroundColor: theme.palette.primary.main
}
},
disabled: {
pointerEvents: 'none',
color: theme.palette.text.hint
}
};
};
var Day$1 = withStyles(styles$4, {
name: 'MuiPickersDay'
})(Day);
var DayWrapper =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(DayWrapper, _PureComponent);
function DayWrapper() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
_this.handleClick = function () {
_this.props.onSelect(_this.props.value);
};
return _this;
}
var _proto = DayWrapper.prototype;
_proto.render = function render() {
var _this$props = this.props,
children = _this$props.children,
value = _this$props.value,
dayInCurrentMonth = _this$props.dayInCurrentMonth,
disabled = _this$props.disabled,
onSelect = _this$props.onSelect,
other = _objectWithoutPropertiesLoose(_this$props, ["children", "value", "dayInCurrentMonth", "disabled", "onSelect"]);
return React.createElement("div", _extends({
onClick: dayInCurrentMonth && !disabled ? this.handleClick : undefined,
onKeyPress: dayInCurrentMonth && !disabled ? this.handleClick : undefined,
role: "presentation"
}, other), children);
};
return DayWrapper;
}(PureComponent);
DayWrapper.propTypes = {
children: PropTypes.node.isRequired,
dayInCurrentMonth: PropTypes.bool,
disabled: PropTypes.bool,
onSelect: PropTypes.func.isRequired,
value: PropTypes.any.isRequired
};
DayWrapper.defaultProps = {
dayInCurrentMonth: true,
disabled: false
};
/* eslint-disable no-unused-expressions */
var Calendar =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(Calendar, _Component);
function Calendar() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.state = {
slideDirection: 'left',
currentMonth: _this.props.utils.getStartOfMonth(_this.props.date)
};
_this.onDateSelect = function (day, isFinish) {
if (isFinish === void 0) {
isFinish = true;
}
var _this$props = _this.props,
date = _this$props.date,
utils = _this$props.utils;
_this.props.onChange(utils.mergeDateAndTime(day, date), isFinish);
};
_this.handleChangeMonth = function (newMonth, slideDirection) {
_this.setState({
currentMonth: newMonth,
slideDirection: slideDirection
});
};
_this.throttledHandleChangeMonth = throttle(_this.handleChangeMonth, 350);
_this.validateMinMaxDate = function (day) {
var _this$props2 = _this.props,
minDate = _this$props2.minDate,
maxDate = _this$props2.maxDate,
utils = _this$props2.utils;
return minDate && utils.isBeforeDay(day, utils.date(minDate)) || maxDate && utils.isAfterDay(day, utils.date(maxDate));
};
_this.shouldDisablePrevMonth = function () {
var _this$props3 = _this.props,
utils = _this$props3.utils,
disablePast = _this$props3.disablePast,
minDate = _this$props3.minDate;
var now = utils.date();
return !utils.isBefore(utils.getStartOfMonth(disablePast && utils.isAfter(now, minDate) ? now : utils.date(minDate)), _this.state.currentMonth);
};
_this.shouldDisableNextMonth = function () {
var _this$props4 = _this.props,
utils = _this$props4.utils,
disableFuture = _this$props4.disableFuture,
maxDate = _this$props4.maxDate;
var now = utils.date();
return !utils.isAfter(utils.getStartOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : utils.date(maxDate)), _this.state.currentMonth);
};
_this.shouldDisableDate = function (day) {
var _this$props5 = _this.props,
disablePast = _this$props5.disablePast,
disableFuture = _this$props5.disableFuture,
shouldDisableDate = _this$props5.shouldDisableDate,
utils = _this$props5.utils;
return disableFuture && utils.isAfterDay(day, utils.date()) || disablePast && utils.isBeforeDay(day, utils.date()) || _this.validateMinMaxDate(day) || shouldDisableDate(day);
};
_this.moveToDay = function (day) {
if (day && !_this.shouldDisableDate(day)) {
_this.props.onChange(day);
}
};
_this.handleKeyDown = function (event) {
var _this$props6 = _this.props,
theme = _this$props6.theme,
date = _this$props6.date,
utils = _this$props6.utils;
switch (keycode(event)) {
case 'up':
_this.moveToDay(utils.addDays(date, -7));
break;
case 'down':
_this.moveToDay(utils.addDays(date, 7));
break;
case 'left':
theme.direction === 'ltr' ? _this.moveToDay(utils.addDays(date, -1)) : _this.moveToDay(utils.addDays(date, 1));
break;
case 'right':
theme.direction === 'ltr' ? _this.moveToDay(utils.addDays(date, 1)) : _this.moveToDay(utils.addDays(date, -1));
break;
default:
// if keycode is not handled, stop execution
return;
} // if event was handled prevent other side effects (e.g. page scroll)
event.preventDefault();
};
_this.renderWeeks = function () {
var utils = _this.props.utils;
var currentMonth = _this.state.currentMonth;
var weeks = utils.getWeekArray(currentMonth);
return weeks.map(function (week) {
return React.createElement("div", {
key: "week-" + week[0].toString(),
className: _this.props.classes.week
}, _this.renderDays(week));
});
};
_this.renderDays = function (week) {
var _this$props7 = _this.props,
date = _this$props7.date,
renderDay = _this$props7.renderDay,
utils = _this$props7.utils;
var selectedDate = utils.startOfDay(date);
var currentMonthNumber = utils.getMonth(_this.state.currentMonth);
var now = utils.date();
return week.map(function (day) {
var disabled = _this.shouldDisableDate(day);
var dayInCurrentMonth = utils.getMonth(day) === currentMonthNumber;
var dayComponent = React.createElement(Day$1, {
current: utils.isSameDay(day, now),
hidden: !dayInCurrentMonth,
disabled: disabled,
selected: utils.isSameDay(selectedDate, day)
}, utils.getDayText(day));
if (renderDay) {
dayComponent = renderDay(day, selectedDate, dayInCurrentMonth, dayComponent);
}
return React.createElement(DayWrapper, {
key: day.toString(),
value: day,
dayInCurrentMonth: dayInCurrentMonth,
disabled: disabled,
onSelect: _this.onDateSelect
}, dayComponent);
});
};
return _this;
}
Calendar.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, state) {
if (!nextProps.utils.isEqual(nextProps.date, state.lastDate)) {
return {
lastDate: nextProps.date,
currentMonth: nextProps.utils.getStartOfMonth(nextProps.date)
};
}
return null;
};
var _proto = Calendar.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this$props8 = this.props,
date = _this$props8.date,
minDate = _this$props8.minDate,
maxDate = _this$props8.maxDate,
utils = _this$props8.utils,
disableFuture = _this$props8.disableFuture,
disablePast = _this$props8.disablePast;
if (this.shouldDisableDate(date)) {
this.onDateSelect(findClosestEnabledDate({
date: date,
utils: utils,
minDate: minDate,
maxDate: maxDate,
disablePast: disablePast,
disableFuture: disableFuture,
shouldDisableDate: this.shouldDisableDate
}), false);
}
};
_proto.render = function render() {
var _this$state = this.state,
currentMonth = _this$state.currentMonth,
slideDirection = _this$state.slideDirection;
var _this$props9 = this.props,
classes = _this$props9.classes,
utils = _this$props9.utils,
allowKeyboardControl = _this$props9.allowKeyboardControl;
return React.createElement(Fragment, null, allowKeyboardControl && React.createElement(EventListener, {
target: "window",
onKeyDown: this.handleKeyDown
}), React.createElement(CalendarHeader$1, {
slideDirection: slideDirection,
currentMonth: currentMonth,
onMonthChange: this.throttledHandleChangeMonth,
leftArrowIcon: this.props.leftArrowIcon,
rightArrowIcon: this.props.rightArrowIcon,
disablePrevMonth: this.shouldDisablePrevMonth(),
disableNextMonth: this.shouldDisableNextMonth(),
utils: utils
}), React.createElement(SlideTransition$1, {
slideDirection: slideDirection,
transKey: currentMonth,
className: classes.transitionContainer
}, React.createElement("div", {
/* eslint-disable-next-line */
autoFocus: true // Autofocus required for getting work keyboard navigation feature
}, this.renderWeeks())));
};
return Calendar;
}(Component);
Calendar.propTypes = {
date: PropTypes.object.isRequired,
minDate: DomainPropTypes.date,
maxDate: DomainPropTypes.date,
classes: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
disablePast: PropTypes.bool,
disableFuture: PropTypes.bool,
leftArrowIcon: PropTypes.node,
rightArrowIcon: PropTypes.node,
renderDay: PropTypes.func,
theme: PropTypes.object.isRequired,
shouldDisableDate: PropTypes.func,
utils: PropTypes.object.isRequired,
allowKeyboardControl: PropTypes.bool
};
Calendar.defaultProps = {
minDate: '1900-01-01',
maxDate: '2100-01-01',
disablePast: false,
disableFuture: false,
leftArrowIcon: undefined,
rightArrowIcon: undefined,
renderDay: undefined,
allowKeyboardControl: false,
shouldDisableDate: function shouldDisableDate() {
return false;
}
};
var styles$5 = function styles(theme) {
return {
transitionContainer: {
minHeight: 36 * 6,
marginTop: theme.spacing.unit * 1.5
},
week: {
display: 'flex',
justifyContent: 'center'
}
};
};
var Calendar$1 = withStyles(styles$5, {
name: 'MuiPickersCalendar',
withTheme: true
})(WithUtils()(Calendar));
var Year =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(Year, _PureComponent);
function Year() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
_this.handleClick = function () {
_this.props.onSelect(_this.props.value);
};
return _this;
}
var _proto = Year.prototype;
_proto.render = function render() {
var _classnames;
var _this$props = this.props,
classes = _this$props.classes,
selected = _this$props.selected,
disabled = _this$props.disabled,
value = _this$props.value,
children = _this$props.children,
other = _objectWithoutPropertiesLoose(_this$props, ["classes", "selected", "disabled", "value", "children"]);
return React.createElement(Typography, _extends({
role: "button",
component: "div",
className: classnames(classes.root, (_classnames = {}, _classnames[classes.selected] = selected, _classnames[classes.disabled] = disabled, _classnames)),
tabIndex: disabled ? -1 : 0,
onClick: this.handleClick,
onKeyPress: this.handleClick,
color: selected ? 'primary' : 'default',
variant: selected ? 'headline' : 'subheading'
}, other), children);
};
return Year;
}(PureComponent);
Year.propTypes = {
children: PropTypes.node.isRequired,
classes: PropTypes.object.isRequired,
disabled: PropTypes.bool,
onSelect: PropTypes.func.isRequired,
selected: PropTypes.bool,
value: PropTypes.any.isRequired
};
Year.defaultProps = {
selected: false,
disabled: false
};
var styles$6 = function styles(theme) {
return {
root: {
height: theme.spacing.unit * 5,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
outline: 'none',
'&:focus': {
color: theme.palette.primary.main,
fontWeight: theme.typography.fontWeightMedium
}
},
selected: {
margin: '10px 0',
fontWeight: theme.typography.fontWeightMedium
},
disabled: {
pointerEvents: 'none',
color: theme.palette.text.hint
}
};
};
var Year$1 = withStyles(styles$6, {
name: 'MuiPickersYear'
})(Year);
var YearSelection =
/*#__PURE__*/
function (_PureComponent) {
_inheritsLoose(YearSelection, _PureComponent);
function YearSelection() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
_this.componentDidMount = function () {
_this.scrollToCurrentYear();
};
_this.onYearSelect = function (year) {
var _this$props = _this.props,
date = _this$props.date,
onChange = _this$props.onChange,
utils = _this$props.utils;
var newDate = utils.setYear(date, year);
onChange(newDate);
};
_this.getSelectedYearRef = function (ref) {
_this.selectedYearRef = ref;
};
_this.scrollToCurrentYear = function () {
var animateYearScrolling = _this.props.animateYearScrolling;
var currentYearElement = findDOMNode(_this.selectedYearRef);
if (currentYearElement && currentYearElement.scrollIntoView) {
currentYearElement.scrollIntoView({
behavior: animateYearScrolling ? 'smooth' : 'auto'
});
}
};
_this.selectedYearRef = undefined;
return _this;
}
var _proto = YearSelection.prototype;
_proto.render = function render() {
var _this2 = this;
var _this$props2 = this.props,
minDate = _this$props2.minDate,
maxDate = _this$props2.maxDate,
date = _this$props2.date,
classes = _this$props2.classes,
disablePast = _this$props2.disablePast,
disableFuture = _this$props2.disableFuture,
utils = _this$props2.utils;
var currentYear = utils.getYear(date);
return React.createElement("div", {
className: classes.container
}, utils.getYearRange(minDate, maxDate).map(function (year) {
var yearNumber = utils.getYear(year);
var selected = yearNumber === currentYear;
return React.createElement(Year$1, {
selected: selected,
disabled: disablePast && utils.isBeforeYear(year, utils.date()) || disableFuture && utils.isAfterYear(year, utils.date()),
value: yearNumber,
key: utils.getYearText(year),
onSelect: _this2.onYearSelect,
ref: selected ? _this2.getSelectedYearRef : undefined
}, utils.getYearText(year));
}));
};
return YearSelection;
}(PureComponent);
YearSelection.propTypes = {
date: PropTypes.shape({}).isRequired,
minDate: DomainPropTypes.date.isRequired,
maxDate: DomainPropTypes.date.isRequired,
classes: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
disablePast: PropTypes.bool.isRequired,
disableFuture: PropTypes.bool.isRequired,
animateYearScrolling: PropTypes.bool,
utils: PropTypes.object.isRequired
};
YearSelection.defaultProps = {
animateYearScrolling: false
};
var styles$7 = {
container: {
maxHeight: 300,
overflowY: 'auto',
justifyContent: 'center'
}
};
var YearSelection$1 = withStyles(styles$7, {
name: 'MuiPickersYearSelection'
})(WithUtils()(YearSelection));
var PickerToolbar = function PickerToolbar(props) {
var children = props.children,
className = props.className,
classes