@mui/x-date-pickers-pro
Version:
The Pro plan edition of the MUI X Date and Time Picker components.
59 lines (54 loc) • 1.65 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["shouldDisableDate"];
import { validateDate } 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 Range Picker, Date Range Field and Date Range Calendar components.
*/
/**
* Validation props as received by the validateDateRange method.
*/
/**
* Name of the props that should be defaulted before being passed to the validateDateRange method.
*/
export const validateDateRange = ({
adapter,
value,
timezone,
props
}) => {
const [start, end] = value;
const {
shouldDisableDate
} = props,
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
const dateValidations = [validateDate({
adapter,
value: start,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'start')
})
}), validateDate({
adapter,
value: end,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'end')
})
})];
if (dateValidations[0] || dateValidations[1]) {
return dateValidations;
}
// for partial input
if (start === null || end === null) {
return [null, null];
}
if (!isRangeValid(adapter, value)) {
return ['invalidRange', 'invalidRange'];
}
return [null, null];
};
validateDateRange.valueManager = rangeValueManager;