@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
54 lines • 2.39 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { useThemeProps } from '@mui/material/styles';
import { useDefaultDates, useUtils } from "../internals/hooks/useUtils.js";
import { applyDefaultDate } from "../internals/utils/date-utils.js";
import { DateTimePickerTabs } from "./DateTimePickerTabs.js";
import { DateTimePickerToolbar } from "./DateTimePickerToolbar.js";
import { applyDefaultViewProps } from "../internals/utils/views.js";
export function useDateTimePickerDefaultizedProps(props, name) {
const utils = useUtils();
const defaultDates = useDefaultDates();
const themeProps = useThemeProps({
props,
name
});
const ampm = themeProps.ampm ?? utils.is12HourCycleInCurrentLocale();
const localeText = React.useMemo(() => {
if (themeProps.localeText?.toolbarTitle == null) {
return themeProps.localeText;
}
return _extends({}, themeProps.localeText, {
dateTimePickerToolbarTitle: themeProps.localeText.toolbarTitle
});
}, [themeProps.localeText]);
return _extends({}, themeProps, applyDefaultViewProps({
views: themeProps.views,
openTo: themeProps.openTo,
defaultViews: ['year', 'day', 'hours', 'minutes'],
defaultOpenTo: 'day'
}), {
ampm,
localeText,
orientation: themeProps.orientation ?? 'portrait',
// TODO: Remove from public API
disableIgnoringDatePartForTimeValidation: themeProps.disableIgnoringDatePartForTimeValidation ?? Boolean(themeProps.minDateTime || themeProps.maxDateTime ||
// allow time clock to correctly check time validity: https://github.com/mui/mui-x/issues/8520
themeProps.disablePast || themeProps.disableFuture),
disableFuture: themeProps.disableFuture ?? false,
disablePast: themeProps.disablePast ?? false,
minDate: applyDefaultDate(utils, themeProps.minDateTime ?? themeProps.minDate, defaultDates.minDate),
maxDate: applyDefaultDate(utils, themeProps.maxDateTime ?? themeProps.maxDate, defaultDates.maxDate),
minTime: themeProps.minDateTime ?? themeProps.minTime,
maxTime: themeProps.maxDateTime ?? themeProps.maxTime,
slots: _extends({
toolbar: DateTimePickerToolbar,
tabs: DateTimePickerTabs
}, themeProps.slots),
slotProps: _extends({}, themeProps.slotProps, {
toolbar: _extends({
ampm
}, themeProps.slotProps?.toolbar)
})
});
}