diff --git a/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx b/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx index b098d57cfb0f3..091038268e6c9 100644 --- a/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx +++ b/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx @@ -6,7 +6,6 @@ import { useDefaultDates, useUtils, applyDefaultDate, - BaseDateValidationProps, BasePickerInputProps, PickerViewRendererLookup, PickerRangeValue, @@ -23,6 +22,7 @@ import { ExportedDateRangePickerToolbarProps, } from './DateRangePickerToolbar'; import { DateRangeViewRendererProps } from '../dateRangeViewRenderers'; +import { ValidateDateRangePropsToDefault } from '../validation/validateDateRange'; export interface BaseDateRangePickerSlots extends DateRangeCalendarSlots { /** @@ -63,7 +63,7 @@ export interface BaseDateRangePickerProps } type UseDateRangePickerDefaultizedProps = - LocalizedComponent>; + LocalizedComponent>; export function useDateRangePickerDefaultizedProps( props: Props, diff --git a/packages/x-date-pickers-pro/src/DateTimeRangePicker/shared.tsx b/packages/x-date-pickers-pro/src/DateTimeRangePicker/shared.tsx index d3f2d3127fd93..11f4aa361b468 100644 --- a/packages/x-date-pickers-pro/src/DateTimeRangePicker/shared.tsx +++ b/packages/x-date-pickers-pro/src/DateTimeRangePicker/shared.tsx @@ -6,7 +6,6 @@ import { useDefaultDates, useUtils, applyDefaultDate, - BaseDateValidationProps, BasePickerInputProps, PickerViewRendererLookup, BaseClockProps, @@ -15,7 +14,6 @@ import { TimeViewWithMeridiem, resolveTimeViewsResponse, UseViewsOptions, - DateTimeValidationProps, DateOrTimeViewWithMeridiem, PickerRangeValue, } from '@mui/x-date-pickers/internals'; @@ -43,6 +41,10 @@ import { DateTimeRangePickerTabsProps, ExportedDateTimeRangePickerTabsProps, } from './DateTimeRangePickerTabs'; +import { + ExportedValidateDateTimeRangeProps, + ValidateDateTimeRangePropsToDefault, +} from '../validation/validateDateTimeRange'; export interface BaseDateTimeRangePickerSlots extends DateRangeCalendarSlots, @@ -94,12 +96,11 @@ export interface BaseDateTimeRangePickerProps 'orientation' | 'views' | 'openTo' >, ExportedDateRangeCalendarProps, - BaseDateValidationProps, + ExportedValidateDateTimeRangeProps, DesktopOnlyTimePickerProps, Partial< Pick, 'openTo' | 'views'> - >, - DateTimeValidationProps { + > { /** * Overridable component slots. * @default {} @@ -120,7 +121,7 @@ export interface BaseDateTimeRangePickerProps type UseDateTimeRangePickerDefaultizedProps = LocalizedComponent< - Omit, 'views'> + Omit, 'views'> > & { shouldRenderTimeInASingleColumn: boolean; views: readonly DateTimeRangePickerView[]; diff --git a/packages/x-date-pickers-pro/src/validation/validateDateRange.ts b/packages/x-date-pickers-pro/src/validation/validateDateRange.ts index 44effa217b603..ac262f477cc22 100644 --- a/packages/x-date-pickers-pro/src/validation/validateDateRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateDateRange.ts @@ -1,3 +1,4 @@ +import type { MakeRequired } from '@mui/x-internals/types'; import { validateDate, Validator } from '@mui/x-date-pickers/validation'; import { BaseDateValidationProps, PickerRangeValue } from '@mui/x-date-pickers/internals'; import { isRangeValid } from '../internals/utils/date-utils'; @@ -12,9 +13,16 @@ export interface ExportedValidateDateRangeProps extends DayRangeValidationProps, BaseDateValidationProps {} +/** + * Validation props as received by the validateDateRange method. + */ export interface ValidateDateRangeProps - extends DayRangeValidationProps, - Required {} + extends MakeRequired {} + +/** + * Name of the props that should be defaulted before being passed to the validateDateRange method. + */ +export type ValidateDateRangePropsToDefault = keyof BaseDateValidationProps; export const validateDateRange: Validator< PickerRangeValue, diff --git a/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts b/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts index 743360be7d7d7..3296957a4412e 100644 --- a/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts @@ -3,8 +3,16 @@ import { validateDateTime, Validator } from '@mui/x-date-pickers/validation'; import { isRangeValid } from '../internals/utils/date-utils'; import { DateTimeRangeValidationError } from '../models'; import { rangeValueManager } from '../internals/utils/valueManagers'; -import { ExportedValidateDateRangeProps, ValidateDateRangeProps } from './validateDateRange'; -import { ExportedValidateTimeRangeProps, ValidateTimeRangeProps } from './validateTimeRange'; +import { + ExportedValidateDateRangeProps, + ValidateDateRangeProps, + ValidateDateRangePropsToDefault, +} from './validateDateRange'; +import { + ExportedValidateTimeRangeProps, + ValidateTimeRangeProps, + ValidateTimeRangePropsToDefault, +} from './validateTimeRange'; /** * Validation props used by the Date Time Range Picker and Date Time Range Field. @@ -14,10 +22,17 @@ export interface ExportedValidateDateTimeRangeProps ExportedValidateTimeRangeProps, DateTimeValidationProps {} +/** + * Validation props as received by the validateDateTimeRange method. + */ export interface ValidateDateTimeRangeProps extends ValidateDateRangeProps, ValidateTimeRangeProps {} +export type ValidateDateTimeRangePropsToDefault = + | ValidateDateRangePropsToDefault + | ValidateTimeRangePropsToDefault; + export const validateDateTimeRange: Validator< PickerRangeValue, DateTimeRangeValidationError, diff --git a/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts b/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts index 2f5cd591cd86a..82f44de4a4190 100644 --- a/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts @@ -1,3 +1,4 @@ +import type { MakeRequired } from '@mui/x-internals/types'; import { validateTime, Validator } from '@mui/x-date-pickers/validation'; import { TimeValidationProps, @@ -15,9 +16,16 @@ export interface ExportedValidateTimeRangeProps extends BaseTimeValidationProps, TimeValidationProps {} +/** + * Validation props as received by the validateTimeRange method. + */ export interface ValidateTimeRangeProps - extends Required, - TimeValidationProps {} + extends MakeRequired {} + +/** + * Name of the props that should be defaulted before being passed to the validateTimeRange method. + */ +export type ValidateTimeRangePropsToDefault = keyof BaseTimeValidationProps; export const validateTimeRange: Validator< PickerRangeValue, diff --git a/packages/x-date-pickers/src/DatePicker/shared.tsx b/packages/x-date-pickers/src/DatePicker/shared.tsx index 05573e1cc9e22..ddfcbc42a54ea 100644 --- a/packages/x-date-pickers/src/DatePicker/shared.tsx +++ b/packages/x-date-pickers/src/DatePicker/shared.tsx @@ -11,7 +11,6 @@ import { applyDefaultViewProps } from '../internals/utils/views'; import { DateValidationError, DateView, PickerValidDate } from '../models'; import { BasePickerInputProps } from '../internals/models/props/basePickerProps'; import { applyDefaultDate } from '../internals/utils/date-utils'; -import { BaseDateValidationProps } from '../internals/models/validation'; import { LocalizedComponent, PickersInputLocaleText } from '../locales/utils/pickersLocaleTextApi'; import { DatePickerToolbar, @@ -20,6 +19,7 @@ import { } from './DatePickerToolbar'; import { PickerViewRendererLookup } from '../internals/hooks/usePicker/usePickerViews'; import { DateViewRendererProps } from '../dateViewRenderers'; +import { ValidateDatePropsToDefault } from '../validation/validateDate'; export interface BaseDatePickerSlots extends DateCalendarSlots { /** @@ -65,7 +65,7 @@ export interface BaseDatePickerProps } type UseDatePickerDefaultizedProps = LocalizedComponent< - DefaultizedProps + DefaultizedProps >; export function useDatePickerDefaultizedProps( diff --git a/packages/x-date-pickers/src/DateTimePicker/shared.tsx b/packages/x-date-pickers/src/DateTimePicker/shared.tsx index 10bb9510bcbae..3bb939565333c 100644 --- a/packages/x-date-pickers/src/DateTimePicker/shared.tsx +++ b/packages/x-date-pickers/src/DateTimePicker/shared.tsx @@ -16,11 +16,6 @@ import { DateTimePickerTabsProps, ExportedDateTimePickerTabsProps, } from './DateTimePickerTabs'; -import { - BaseDateValidationProps, - BaseTimeValidationProps, - DateTimeValidationProps, -} from '../internals/models/validation'; import { LocalizedComponent, PickersInputLocaleText } from '../locales/utils/pickersLocaleTextApi'; import { DateTimePickerToolbar, @@ -33,6 +28,10 @@ import { TimeViewRendererProps } from '../timeViewRenderers'; import { applyDefaultViewProps } from '../internals/utils/views'; import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/time'; import { DateOrTimeViewWithMeridiem, TimeViewWithMeridiem } from '../internals/models'; +import { + ExportedValidateDateTimeProps, + ValidateDateTimePropsToDefault, +} from '../validation/validateDateTime'; export interface BaseDateTimePickerSlots extends DateCalendarSlots, TimeClockSlots { /** @@ -76,7 +75,7 @@ export interface BaseDateTimePickerProps, Omit, ExportedBaseClockProps, - DateTimeValidationProps { + ExportedValidateDateTimeProps { /** * Display ampm controls under the clock (instead of in the toolbar). * @default true on desktop, false on mobile @@ -106,12 +105,7 @@ type UseDateTimePickerDefaultizedProps< > = LocalizedComponent< DefaultizedProps< Props, - | 'views' - | 'openTo' - | 'orientation' - | 'ampm' - | keyof BaseDateValidationProps - | keyof BaseTimeValidationProps + 'views' | 'openTo' | 'orientation' | 'ampm' | ValidateDateTimePropsToDefault > >; diff --git a/packages/x-date-pickers/src/TimePicker/shared.tsx b/packages/x-date-pickers/src/TimePicker/shared.tsx index e5a9a8368f291..4326cb61e4147 100644 --- a/packages/x-date-pickers/src/TimePicker/shared.tsx +++ b/packages/x-date-pickers/src/TimePicker/shared.tsx @@ -4,7 +4,6 @@ import { DefaultizedProps } from '@mui/x-internals/types'; import { useUtils } from '../internals/hooks/useUtils'; import { TimeClockSlots, TimeClockSlotProps } from '../TimeClock/TimeClock.types'; import { BasePickerInputProps } from '../internals/models/props/basePickerProps'; -import { BaseTimeValidationProps } from '../internals/models/validation'; import { LocalizedComponent, PickersInputLocaleText } from '../locales/utils/pickersLocaleTextApi'; import { TimePickerToolbarProps, @@ -17,6 +16,7 @@ import { TimeViewRendererProps } from '../timeViewRenderers'; import { applyDefaultViewProps } from '../internals/utils/views'; import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/time'; import { TimeViewWithMeridiem } from '../internals/models'; +import { ValidateTimePropsToDefault } from '../validation/validateTime'; export interface BaseTimePickerSlots extends TimeClockSlots { /** @@ -70,7 +70,7 @@ type UseTimePickerDefaultizedProps< TView extends TimeViewWithMeridiem, Props extends BaseTimePickerProps, > = LocalizedComponent< - DefaultizedProps + DefaultizedProps >; export function useTimePickerDefaultizedProps< diff --git a/packages/x-date-pickers/src/validation/validateDate.ts b/packages/x-date-pickers/src/validation/validateDate.ts index 3c53ee7acb38a..aae7114967d87 100644 --- a/packages/x-date-pickers/src/validation/validateDate.ts +++ b/packages/x-date-pickers/src/validation/validateDate.ts @@ -1,3 +1,4 @@ +import type { MakeRequired } from '@mui/x-internals/types'; import { Validator } from './useValidation'; import { BaseDateValidationProps, @@ -18,11 +19,16 @@ export interface ExportedValidateDateProps YearValidationProps, BaseDateValidationProps {} +/** + * Validation props as received by the validateDate method. + */ export interface ValidateDateProps - extends DayValidationProps, - MonthValidationProps, - YearValidationProps, - Required {} + extends MakeRequired {} + +/** + * Name of the props that should be defaulted before being passed to the validateDate method. + */ +export type ValidateDatePropsToDefault = keyof BaseDateValidationProps; export const validateDate: Validator< PickerValidDate | null, diff --git a/packages/x-date-pickers/src/validation/validateDateTime.ts b/packages/x-date-pickers/src/validation/validateDateTime.ts index 34ef257efba2c..f1827fc83b727 100644 --- a/packages/x-date-pickers/src/validation/validateDateTime.ts +++ b/packages/x-date-pickers/src/validation/validateDateTime.ts @@ -1,6 +1,16 @@ import { Validator } from './useValidation'; -import { ExportedValidateDateProps, validateDate, ValidateDateProps } from './validateDate'; -import { ExportedValidateTimeProps, validateTime, ValidateTimeProps } from './validateTime'; +import { + ExportedValidateDateProps, + validateDate, + ValidateDateProps, + ValidateDatePropsToDefault, +} from './validateDate'; +import { + ExportedValidateTimeProps, + validateTime, + ValidateTimeProps, + ValidateTimePropsToDefault, +} from './validateTime'; import { DateTimeValidationError, PickerValidDate } from '../models'; import { singleItemValueManager } from '../internals/utils/valueManagers'; import { DateTimeValidationProps } from '../internals/models/validation'; @@ -13,8 +23,18 @@ export interface ExportedValidateDateTimeProps ExportedValidateTimeProps, DateTimeValidationProps {} +/** + * Validation props as received by the validateDateTime method. + */ export interface ValidateDateTimeProps extends ValidateDateProps, ValidateTimeProps {} +/** + * Name of the props that should be defaulted before being passed to the validateDateTime method. + */ +export type ValidateDateTimePropsToDefault = + | ValidateDatePropsToDefault + | ValidateTimePropsToDefault; + export const validateDateTime: Validator< PickerValidDate | null, DateTimeValidationError, diff --git a/packages/x-date-pickers/src/validation/validateTime.ts b/packages/x-date-pickers/src/validation/validateTime.ts index 2979aa6864e19..c27c31e5614e5 100644 --- a/packages/x-date-pickers/src/validation/validateTime.ts +++ b/packages/x-date-pickers/src/validation/validateTime.ts @@ -1,3 +1,4 @@ +import type { MakeRequired } from '@mui/x-internals/types'; import { createIsAfterIgnoreDatePart } from '../internals/utils/time-utils'; import { Validator } from './useValidation'; import { BaseTimeValidationProps, TimeValidationProps } from '../internals/models/validation'; @@ -9,7 +10,16 @@ import { singleItemValueManager } from '../internals/utils/valueManagers'; */ export interface ExportedValidateTimeProps extends BaseTimeValidationProps, TimeValidationProps {} -export interface ValidateTimeProps extends Required, TimeValidationProps {} +/** + * Validation props as received by the validateTime method. + */ +export interface ValidateTimeProps + extends MakeRequired {} + +/** + * Name of the props that should be defaulted before being passed to the validateTime method. + */ +export type ValidateTimePropsToDefault = keyof BaseTimeValidationProps; export const validateTime: Validator< PickerValidDate | null,