Files
Iliyan Angelov 306b20e24a Frontend start
2025-09-14 00:54:48 +03:00

55 lines
2.1 KiB
JavaScript

import _extends from "@babel/runtime/helpers/esm/extends";
import { useThemeProps } from '@mui/material/styles';
import { useDefaultDates, useUtils } from '../internals/hooks/useUtils';
import { parsePickerInputValue, parseNonNullablePickerDate } from '../internals/utils/date-utils';
export function useDateTimePickerDefaultizedProps(props, name) {
// This is technically unsound if the type parameters appear in optional props.
// Optional props can be filled by `useThemeProps` with types that don't match the type parameters.
const themeProps = useThemeProps({
props,
name
});
const utils = useUtils();
const defaultDates = useDefaultDates();
const ampm = themeProps.ampm ?? utils.is12HourCycleInCurrentLocale();
if (themeProps.orientation != null && themeProps.orientation !== 'portrait') {
throw new Error('We are not supporting custom orientation for DateTimePicker yet :(');
}
return _extends({
ampm,
orientation: 'portrait',
openTo: 'day',
views: ['year', 'day', 'hours', 'minutes'],
ampmInClock: true,
acceptRegex: ampm ? /[\dap]/gi : /\d/gi,
disableMaskedInput: false,
inputFormat: ampm ? utils.formats.keyboardDateTime12h : utils.formats.keyboardDateTime24h,
disableIgnoringDatePartForTimeValidation: Boolean(themeProps.minDateTime || themeProps.maxDateTime),
disablePast: false,
disableFuture: false
}, themeProps, {
minDate: parseNonNullablePickerDate(utils, themeProps.minDateTime ?? themeProps.minDate, defaultDates.minDate),
maxDate: parseNonNullablePickerDate(utils, themeProps.maxDateTime ?? themeProps.maxDate, defaultDates.maxDate),
minTime: themeProps.minDateTime ?? themeProps.minTime,
maxTime: themeProps.maxDateTime ?? themeProps.maxTime
});
}
export const dateTimePickerValueManager = {
emptyValue: null,
getTodayValue: utils => utils.date(),
parseInput: parsePickerInputValue,
areValuesEqual: (utils, a, b) => utils.isEqual(a, b)
};
export const resolveViewTypeFromView = view => {
switch (view) {
case 'year':
case 'month':
case 'day':
return 'calendar';
default:
return 'clock';
}
};