@mui/x-date-pickers-pro
Version:
The Pro plan edition of the MUI X Date and Time Picker components.
55 lines (51 loc) • 1.56 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["shouldDisableDate"];
import { validateDateTime } from '@mui/x-date-pickers/validation';
import { isRangeValid } from "../internals/utils/date-utils.js";
import { rangeValueManager } from "../internals/utils/valueManagers.js";
/**
* Validation props used by the Date Time Range Picker and Date Time Range Field.
*/
/**
* Validation props as received by the validateDateTimeRange method.
*/
export const validateDateTimeRange = ({
adapter,
value,
timezone,
props
}) => {
const [start, end] = value;
const {
shouldDisableDate
} = props,
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
const dateTimeValidations = [validateDateTime({
adapter,
value: start,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'start')
})
}), validateDateTime({
adapter,
value: end,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'end')
})
})];
if (dateTimeValidations[0] || dateTimeValidations[1]) {
return dateTimeValidations;
}
// for partial input
if (start === null || end === null) {
return [null, null];
}
if (!isRangeValid(adapter, value)) {
return ['invalidRange', 'invalidRange'];
}
return [null, null];
};
validateDateTimeRange.valueManager = rangeValueManager;