From 302c87624442655db26a99585c16f68fdc398a22 Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Thu, 31 Oct 2024 11:47:44 +0100 Subject: [PATCH] [pickers] Clean definition of validation props (#15198) --- .../DateRangeCalendar.types.ts | 5 ++-- .../src/DateRangePicker/shared.tsx | 3 +- .../src/internals/models/dateTimeRange.ts | 18 +++--------- .../src/internals/models/timeRange.ts | 18 +++--------- .../src/models/dateRange.ts | 11 ++------ .../src/validation/validateDateRange.ts | 7 +++++ .../src/validation/validateDateTimeRange.ts | 18 ++++++++---- .../src/validation/validateTimeRange.ts | 16 +++++++++-- .../src/DateCalendar/DateCalendar.types.ts | 13 ++------- .../src/DateField/DateField.types.ts | 12 ++------ .../src/DateTimeField/DateTimeField.types.ts | 28 ++++--------------- .../src/DateTimePicker/shared.tsx | 2 +- .../DesktopDateTimePicker.types.ts | 2 +- .../DesktopTimePicker.types.ts | 2 +- .../src/DigitalClock/DigitalClock.types.ts | 2 +- .../MultiSectionDigitalClock.types.ts | 2 +- .../src/TimeClock/TimeClock.types.ts | 2 +- .../src/TimeField/TimeField.types.ts | 15 ++++------ .../x-date-pickers/src/TimePicker/shared.tsx | 2 +- .../x-date-pickers/src/internals/index.ts | 2 +- .../models/props/{clock.ts => time.ts} | 12 ++++---- .../src/internals/utils/date-time-utils.ts | 2 +- .../timeViewRenderers/timeViewRenderers.tsx | 2 +- .../src/validation/validateDate.ts | 9 ++++++ .../src/validation/validateDateTime.ts | 13 +++++++-- .../src/validation/validateTime.ts | 7 +++++ 26 files changed, 106 insertions(+), 119 deletions(-) rename packages/x-date-pickers/src/internals/models/props/{clock.ts => time.ts} (94%) diff --git a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts index ac56c4d44149..da1c6f546c40 100644 --- a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts +++ b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts @@ -19,12 +19,12 @@ import { DayCalendarProps, ExportedUseViewsOptions, } from '@mui/x-date-pickers/internals'; -import { DayRangeValidationProps } from '../internals/models/dateRange'; import { DateRange, RangePosition } from '../models'; import { DateRangeCalendarClasses } from './dateRangeCalendarClasses'; import { DateRangePickerDay, DateRangePickerDayProps } from '../DateRangePickerDay'; import { UseRangePositionProps } from '../internals/hooks/useRangePosition'; import { PickersRangeCalendarHeaderProps } from '../PickersRangeCalendarHeader'; +import { ExportedValidateDateRangeProps } from '../validation/validateDateRange'; export interface DateRangeCalendarSlots extends PickersArrowSwitcherSlots, @@ -62,8 +62,7 @@ export interface DateRangeCalendarSlotProps export interface ExportedDateRangeCalendarProps extends ExportedDayCalendarProps, - BaseDateValidationProps, - DayRangeValidationProps, + ExportedValidateDateRangeProps, TimezoneProps { /** * If `true`, after selecting `start` date calendar will not automatically switch to the month of `end` date. diff --git a/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx b/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx index 1099eb02994e..da7f89407687 100644 --- a/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx +++ b/packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx @@ -43,8 +43,7 @@ export interface BaseDateRangePickerProps BasePickerInputProps, TDate, 'day', DateRangeValidationError>, 'view' | 'views' | 'openTo' | 'onViewChange' | 'orientation' >, - ExportedDateRangeCalendarProps, - BaseDateValidationProps { + ExportedDateRangeCalendarProps { /** * Overridable component slots. * @default {} diff --git a/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts b/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts index ab37cab3b08d..395e0e19b18a 100644 --- a/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts @@ -1,19 +1,17 @@ import { - BaseDateValidationProps, - TimeValidationProps, MakeOptional, UseFieldInternalProps, - DateTimeValidationProps, DateOrTimeViewWithMeridiem, + AmPmProps, } from '@mui/x-date-pickers/internals'; import { PickerValidDate } from '@mui/x-date-pickers/models'; -import { DayRangeValidationProps } from './dateRange'; import { DateTimeRangeValidationError, RangeFieldSection, DateRange, RangeFieldSeparatorProps, } from '../../models'; +import { ExportedValidateDateTimeRangeProps } from '../../validation/validateDateTimeRange'; export interface UseDateTimeRangeFieldProps< TDate extends PickerValidDate, @@ -32,16 +30,8 @@ export interface UseDateTimeRangeFieldProps< 'format' >, RangeFieldSeparatorProps, - DayRangeValidationProps, - TimeValidationProps, - BaseDateValidationProps, - DateTimeValidationProps { - /** - * 12h/24h view for hour selection clock. - * @default utils.is12HourCycleInCurrentLocale() - */ - ampm?: boolean; -} + ExportedValidateDateTimeRangeProps, + AmPmProps {} export type DateTimeRangePickerView = Exclude; diff --git a/packages/x-date-pickers-pro/src/internals/models/timeRange.ts b/packages/x-date-pickers-pro/src/internals/models/timeRange.ts index 010182c83114..f31169641176 100644 --- a/packages/x-date-pickers-pro/src/internals/models/timeRange.ts +++ b/packages/x-date-pickers-pro/src/internals/models/timeRange.ts @@ -1,9 +1,4 @@ -import { - BaseTimeValidationProps, - TimeValidationProps, - MakeOptional, - UseFieldInternalProps, -} from '@mui/x-date-pickers/internals'; +import { MakeOptional, UseFieldInternalProps, AmPmProps } from '@mui/x-date-pickers/internals'; import { PickerValidDate } from '@mui/x-date-pickers/models'; import { TimeRangeValidationError, @@ -11,6 +6,7 @@ import { DateRange, RangeFieldSeparatorProps, } from '../../models'; +import type { ExportedValidateTimeRangeProps } from '../../validation/validateTimeRange'; export interface UseTimeRangeFieldProps< TDate extends PickerValidDate, @@ -29,11 +25,5 @@ export interface UseTimeRangeFieldProps< 'format' >, RangeFieldSeparatorProps, - TimeValidationProps, - BaseTimeValidationProps { - /** - * 12h/24h view for hour selection clock. - * @default utils.is12HourCycleInCurrentLocale() - */ - ampm?: boolean; -} + ExportedValidateTimeRangeProps, + AmPmProps {} diff --git a/packages/x-date-pickers-pro/src/models/dateRange.ts b/packages/x-date-pickers-pro/src/models/dateRange.ts index d110c1cb3b40..852145fd0fb4 100644 --- a/packages/x-date-pickers-pro/src/models/dateRange.ts +++ b/packages/x-date-pickers-pro/src/models/dateRange.ts @@ -1,13 +1,9 @@ -import { - BaseDateValidationProps, - MakeOptional, - UseFieldInternalProps, -} from '@mui/x-date-pickers/internals'; +import { MakeOptional, UseFieldInternalProps } from '@mui/x-date-pickers/internals'; import { PickerValidDate } from '@mui/x-date-pickers/models'; import { RangeFieldSection, RangeFieldSeparatorProps } from './fields'; import { DateRangeValidationError } from './validation'; import { DateRange } from './range'; -import { DayRangeValidationProps } from '../internals/models/dateRange'; +import type { ExportedValidateDateRangeProps } from '../validation/validateDateRange'; export interface UseDateRangeFieldProps< TDate extends PickerValidDate, @@ -26,5 +22,4 @@ export interface UseDateRangeFieldProps< 'format' >, RangeFieldSeparatorProps, - DayRangeValidationProps, - BaseDateValidationProps {} + ExportedValidateDateRangeProps {} diff --git a/packages/x-date-pickers-pro/src/validation/validateDateRange.ts b/packages/x-date-pickers-pro/src/validation/validateDateRange.ts index 125449ca9a6f..bf05511c9a38 100644 --- a/packages/x-date-pickers-pro/src/validation/validateDateRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateDateRange.ts @@ -6,6 +6,13 @@ import { DayRangeValidationProps } from '../internals/models/dateRange'; import { DateRangeValidationError, DateRange } from '../models'; import { rangeValueManager } from '../internals/utils/valueManagers'; +/** + * Validation props used by the Date Range Picker, Date Range Field and Date Range Calendar components. + */ +export interface ExportedValidateDateRangeProps + extends DayRangeValidationProps, + BaseDateValidationProps {} + export interface ValidateDateRangeProps extends DayRangeValidationProps, Required> {} diff --git a/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts b/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts index d86d65e8d3b3..754e8053c639 100644 --- a/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateDateTimeRange.ts @@ -1,15 +1,23 @@ import { PickerValidDate } from '@mui/x-date-pickers/models'; +import { DateTimeValidationProps } from '@mui/x-date-pickers/internals'; import { validateDateTime, Validator } from '@mui/x-date-pickers/validation'; -import { BaseDateValidationProps, TimeValidationProps } from '@mui/x-date-pickers/internals'; import { isRangeValid } from '../internals/utils/date-utils'; -import { DayRangeValidationProps } from '../internals/models/dateRange'; import { DateTimeRangeValidationError, DateRange } from '../models'; import { rangeValueManager } from '../internals/utils/valueManagers'; +import { ExportedValidateDateRangeProps, ValidateDateRangeProps } from './validateDateRange'; +import { ExportedValidateTimeRangeProps, ValidateTimeRangeProps } from './validateTimeRange'; + +/** + * Validation props used by the Date Time Range Picker and Date Time Range Field. + */ +export interface ExportedValidateDateTimeRangeProps + extends ExportedValidateDateRangeProps, + ExportedValidateTimeRangeProps, + DateTimeValidationProps {} export interface ValidateDateTimeRangeProps - extends DayRangeValidationProps, - TimeValidationProps, - Required> {} + extends ValidateDateRangeProps, + ValidateTimeRangeProps {} export const validateDateTimeRange: Validator< DateRange, diff --git a/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts b/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts index 483523a4b499..f6d48949de2e 100644 --- a/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/validation/validateTimeRange.ts @@ -1,16 +1,26 @@ import { validateTime, Validator } from '@mui/x-date-pickers/validation'; -import { BaseTimeValidationProps } from '@mui/x-date-pickers/internals'; +import { PickerValidDate } from '@mui/x-date-pickers/models'; +import { TimeValidationProps, BaseTimeValidationProps } from '@mui/x-date-pickers/internals'; import { isRangeValid } from '../internals/utils/date-utils'; import { TimeRangeValidationError, DateRange } from '../models'; import { rangeValueManager } from '../internals/utils/valueManagers'; -export interface ValidateTimeRangeProps extends Required {} +/** + * Validation props used by the Time Range Picker and Time Range Field. + */ +export interface ExportedValidateTimeRangeProps + extends BaseTimeValidationProps, + TimeValidationProps {} + +export interface ValidateTimeRangeProps + extends Required, + TimeValidationProps {} export const validateTimeRange: Validator< DateRange, any, TimeRangeValidationError, - ValidateTimeRangeProps + ValidateTimeRangeProps > = ({ adapter, value, timezone, props }) => { const [start, end] = value; diff --git a/packages/x-date-pickers/src/DateCalendar/DateCalendar.types.ts b/packages/x-date-pickers/src/DateCalendar/DateCalendar.types.ts index cc378565575d..0d20aec39d8d 100644 --- a/packages/x-date-pickers/src/DateCalendar/DateCalendar.types.ts +++ b/packages/x-date-pickers/src/DateCalendar/DateCalendar.types.ts @@ -10,12 +10,7 @@ import { } from '../PickersCalendarHeader'; import { DayCalendarSlots, DayCalendarSlotProps, ExportedDayCalendarProps } from './DayCalendar'; import { DateCalendarClasses } from './dateCalendarClasses'; -import { - BaseDateValidationProps, - YearValidationProps, - MonthValidationProps, - DayValidationProps, -} from '../internals/models/validation'; +import { BaseDateValidationProps } from '../internals/models/validation'; import { ExportedUseViewsOptions } from '../internals/hooks/useViews'; import { DateView, PickerValidDate, TimezoneProps } from '../models'; import { DefaultizedProps } from '../internals/models/helpers'; @@ -29,6 +24,7 @@ import { MonthCalendarSlots, MonthCalendarSlotProps, } from '../MonthCalendar/MonthCalendar.types'; +import { ExportedValidateDateProps } from '../validation/validateDate'; export interface DateCalendarSlots extends PickersCalendarHeaderSlots, @@ -55,10 +51,7 @@ export interface ExportedDateCalendarProps extends ExportedDayCalendarProps, ExportedMonthCalendarProps, ExportedYearCalendarProps, - BaseDateValidationProps, - DayValidationProps, - YearValidationProps, - MonthValidationProps, + ExportedValidateDateProps, TimezoneProps { /** * If `true`, the picker and text field are disabled. diff --git a/packages/x-date-pickers/src/DateField/DateField.types.ts b/packages/x-date-pickers/src/DateField/DateField.types.ts index 2b6feddbc943..610889b52b13 100644 --- a/packages/x-date-pickers/src/DateField/DateField.types.ts +++ b/packages/x-date-pickers/src/DateField/DateField.types.ts @@ -14,12 +14,7 @@ import { } from '../models'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { MakeOptional } from '../internals/models/helpers'; -import { - BaseDateValidationProps, - DayValidationProps, - MonthValidationProps, - YearValidationProps, -} from '../internals/models/validation'; +import { ExportedValidateDateProps } from '../validation/validateDate'; export interface UseDateFieldProps< TDate extends PickerValidDate, @@ -34,10 +29,7 @@ export interface UseDateFieldProps< >, 'format' >, - DayValidationProps, - MonthValidationProps, - YearValidationProps, - BaseDateValidationProps, + ExportedValidateDateProps, ExportedUseClearableFieldProps {} export type DateFieldProps< diff --git a/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts b/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts index f603981c1c95..38018c6a9b62 100644 --- a/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts +++ b/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts @@ -9,20 +9,13 @@ import { } from '../models'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { MakeOptional } from '../internals/models/helpers'; -import { - BaseDateValidationProps, - BaseTimeValidationProps, - DateTimeValidationProps, - DayValidationProps, - MonthValidationProps, - TimeValidationProps, - YearValidationProps, -} from '../internals/models/validation'; import { ExportedUseClearableFieldProps, UseClearableFieldSlots, UseClearableFieldSlotProps, } from '../hooks/useClearableField'; +import { ExportedValidateDateTimeProps } from '../validation/validateDateTime'; +import { AmPmProps } from '../internals/models/props/time'; export interface UseDateTimeFieldProps< TDate extends PickerValidDate, @@ -37,20 +30,9 @@ export interface UseDateTimeFieldProps< >, 'format' >, - DayValidationProps, - MonthValidationProps, - YearValidationProps, - BaseDateValidationProps, - TimeValidationProps, - BaseTimeValidationProps, - DateTimeValidationProps, - ExportedUseClearableFieldProps { - /** - * 12h/24h view for hour selection clock. - * @default utils.is12HourCycleInCurrentLocale() - */ - ampm?: boolean; -} + ExportedValidateDateTimeProps, + ExportedUseClearableFieldProps, + AmPmProps {} export type DateTimeFieldProps< TDate extends PickerValidDate, diff --git a/packages/x-date-pickers/src/DateTimePicker/shared.tsx b/packages/x-date-pickers/src/DateTimePicker/shared.tsx index 827c0ed4ef35..bef1c5a52aa2 100644 --- a/packages/x-date-pickers/src/DateTimePicker/shared.tsx +++ b/packages/x-date-pickers/src/DateTimePicker/shared.tsx @@ -31,7 +31,7 @@ import { PickerViewRendererLookup } from '../internals/hooks/usePicker/usePicker import { DateViewRendererProps } from '../dateViewRenderers'; import { TimeViewRendererProps } from '../timeViewRenderers'; import { applyDefaultViewProps } from '../internals/utils/views'; -import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/clock'; +import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/time'; import { DateOrTimeViewWithMeridiem, TimeViewWithMeridiem } from '../internals/models'; export interface BaseDateTimePickerSlots diff --git a/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.types.ts b/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.types.ts index 24d55d83dde6..ec7684db88ec 100644 --- a/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.types.ts +++ b/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.types.ts @@ -10,7 +10,7 @@ import { } from '../DateTimePicker/shared'; import { MakeOptional } from '../internals/models/helpers'; import { DateOrTimeView, PickerValidDate } from '../models'; -import { DesktopOnlyTimePickerProps } from '../internals/models/props/clock'; +import { DesktopOnlyTimePickerProps } from '../internals/models/props/time'; import { DateOrTimeViewWithMeridiem } from '../internals/models'; import { MultiSectionDigitalClockSlots, diff --git a/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.types.ts b/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.types.ts index 73974cf1df82..1ca74ab5d48f 100644 --- a/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.types.ts +++ b/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.types.ts @@ -10,7 +10,7 @@ import { } from '../TimePicker/shared'; import { MakeOptional } from '../internals/models/helpers'; import { TimeViewWithMeridiem } from '../internals/models'; -import { DesktopOnlyTimePickerProps } from '../internals/models/props/clock'; +import { DesktopOnlyTimePickerProps } from '../internals/models/props/time'; import { DigitalClockSlots, DigitalClockSlotProps } from '../DigitalClock'; import { MultiSectionDigitalClockSlots, diff --git a/packages/x-date-pickers/src/DigitalClock/DigitalClock.types.ts b/packages/x-date-pickers/src/DigitalClock/DigitalClock.types.ts index 3d5910de62db..b68d5903dba5 100644 --- a/packages/x-date-pickers/src/DigitalClock/DigitalClock.types.ts +++ b/packages/x-date-pickers/src/DigitalClock/DigitalClock.types.ts @@ -6,7 +6,7 @@ import { BaseClockProps, DigitalClockOnlyProps, ExportedBaseClockProps, -} from '../internals/models/props/clock'; +} from '../internals/models/props/time'; import { PickerValidDate, TimeView } from '../models'; export interface ExportedDigitalClockProps diff --git a/packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClock.types.ts b/packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClock.types.ts index e7efd1b3a350..5efc2fc42143 100644 --- a/packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClock.types.ts +++ b/packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClock.types.ts @@ -6,7 +6,7 @@ import { BaseClockProps, ExportedBaseClockProps, MultiSectionDigitalClockOnlyProps, -} from '../internals/models/props/clock'; +} from '../internals/models/props/time'; import { MultiSectionDigitalClockSectionProps } from './MultiSectionDigitalClockSection'; import { TimeViewWithMeridiem } from '../internals/models'; import { PickerValidDate } from '../models'; diff --git a/packages/x-date-pickers/src/TimeClock/TimeClock.types.ts b/packages/x-date-pickers/src/TimeClock/TimeClock.types.ts index fda54930f817..85e7abb1cc07 100644 --- a/packages/x-date-pickers/src/TimeClock/TimeClock.types.ts +++ b/packages/x-date-pickers/src/TimeClock/TimeClock.types.ts @@ -3,7 +3,7 @@ import { PickersArrowSwitcherSlots, PickersArrowSwitcherSlotProps, } from '../internals/components/PickersArrowSwitcher'; -import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/clock'; +import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/time'; import { PickerValidDate, TimeView } from '../models'; import { TimeViewWithMeridiem } from '../internals/models'; diff --git a/packages/x-date-pickers/src/TimeField/TimeField.types.ts b/packages/x-date-pickers/src/TimeField/TimeField.types.ts index 03d2c63932c3..e81ca139440a 100644 --- a/packages/x-date-pickers/src/TimeField/TimeField.types.ts +++ b/packages/x-date-pickers/src/TimeField/TimeField.types.ts @@ -3,7 +3,6 @@ import { SlotComponentProps } from '@mui/utils'; import TextField from '@mui/material/TextField'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { MakeOptional } from '../internals/models/helpers'; -import { BaseTimeValidationProps, TimeValidationProps } from '../internals/models/validation'; import { FieldSection, PickerValidDate, @@ -15,6 +14,8 @@ import { UseClearableFieldSlots, UseClearableFieldSlotProps, } from '../hooks/useClearableField'; +import { ExportedValidateTimeProps } from '../validation/validateTime'; +import { AmPmProps } from '../internals/models/props/time'; export interface UseTimeFieldProps< TDate extends PickerValidDate, @@ -29,15 +30,9 @@ export interface UseTimeFieldProps< >, 'format' >, - TimeValidationProps, - BaseTimeValidationProps, - ExportedUseClearableFieldProps { - /** - * 12h/24h view for hour selection clock. - * @default utils.is12HourCycleInCurrentLocale() - */ - ampm?: boolean; -} + ExportedValidateTimeProps, + ExportedUseClearableFieldProps, + AmPmProps {} export type TimeFieldProps< TDate extends PickerValidDate, diff --git a/packages/x-date-pickers/src/TimePicker/shared.tsx b/packages/x-date-pickers/src/TimePicker/shared.tsx index a459bac50d25..615897e64ba6 100644 --- a/packages/x-date-pickers/src/TimePicker/shared.tsx +++ b/packages/x-date-pickers/src/TimePicker/shared.tsx @@ -15,7 +15,7 @@ import { PickerValidDate, TimeValidationError } from '../models'; import { PickerViewRendererLookup } from '../internals/hooks/usePicker/usePickerViews'; import { TimeViewRendererProps } from '../timeViewRenderers'; import { applyDefaultViewProps } from '../internals/utils/views'; -import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/clock'; +import { BaseClockProps, ExportedBaseClockProps } from '../internals/models/props/time'; import { TimeViewWithMeridiem } from '../internals/models'; export interface BaseTimePickerSlots extends TimeClockSlots { diff --git a/packages/x-date-pickers/src/internals/index.ts b/packages/x-date-pickers/src/internals/index.ts index 49700d346134..f4a69cbcfd29 100644 --- a/packages/x-date-pickers/src/internals/index.ts +++ b/packages/x-date-pickers/src/internals/index.ts @@ -101,7 +101,7 @@ export type { BasePickerInputProps, BaseNonStaticPickerProps, } from './models/props/basePickerProps'; -export type { BaseClockProps, DesktopOnlyTimePickerProps } from './models/props/clock'; +export type { BaseClockProps, DesktopOnlyTimePickerProps, AmPmProps } from './models/props/time'; export type { BaseTabsProps, ExportedBaseTabsProps } from './models/props/tabs'; export type { BaseToolbarProps, ExportedBaseToolbarProps } from './models/props/toolbar'; export type { diff --git a/packages/x-date-pickers/src/internals/models/props/clock.ts b/packages/x-date-pickers/src/internals/models/props/time.ts similarity index 94% rename from packages/x-date-pickers/src/internals/models/props/clock.ts rename to packages/x-date-pickers/src/internals/models/props/time.ts index 41ac81136ae4..5683afbc1e4e 100644 --- a/packages/x-date-pickers/src/internals/models/props/clock.ts +++ b/packages/x-date-pickers/src/internals/models/props/time.ts @@ -1,15 +1,12 @@ import { SxProps, Theme } from '@mui/material/styles'; -import { BaseTimeValidationProps, TimeValidationProps } from '../validation'; import { PickerValidDate, TimeStepOptions, TimezoneProps } from '../../../models'; import type { ExportedDigitalClockProps } from '../../../DigitalClock/DigitalClock.types'; import type { ExportedMultiSectionDigitalClockProps } from '../../../MultiSectionDigitalClock/MultiSectionDigitalClock.types'; import type { ExportedUseViewsOptions } from '../../hooks/useViews'; import { TimeViewWithMeridiem } from '../common'; +import { ExportedValidateTimeProps } from '../../../validation/validateTime'; -export interface ExportedBaseClockProps - extends TimeValidationProps, - BaseTimeValidationProps, - TimezoneProps { +export interface AmPmProps { /** * 12h/24h view for hour selection clock. * @default utils.is12HourCycleInCurrentLocale() @@ -17,6 +14,11 @@ export interface ExportedBaseClockProps ampm?: boolean; } +export interface ExportedBaseClockProps + extends ExportedValidateTimeProps, + TimezoneProps, + AmPmProps {} + export interface BaseClockProps extends ExportedUseViewsOptions, ExportedBaseClockProps { diff --git a/packages/x-date-pickers/src/internals/utils/date-time-utils.ts b/packages/x-date-pickers/src/internals/utils/date-time-utils.ts index eb7c100e9468..75d78ca790d0 100644 --- a/packages/x-date-pickers/src/internals/utils/date-time-utils.ts +++ b/packages/x-date-pickers/src/internals/utils/date-time-utils.ts @@ -9,7 +9,7 @@ import { import { resolveTimeFormat, isTimeView, isInternalTimeView } from './time-utils'; import { isDatePickerView, resolveDateFormat } from './date-utils'; import { DateOrTimeViewWithMeridiem } from '../models'; -import { DesktopOnlyTimePickerProps } from '../models/props/clock'; +import { DesktopOnlyTimePickerProps } from '../models/props/time'; import { DefaultizedProps } from '../models/helpers'; export const resolveDateTimeFormat = ( diff --git a/packages/x-date-pickers/src/timeViewRenderers/timeViewRenderers.tsx b/packages/x-date-pickers/src/timeViewRenderers/timeViewRenderers.tsx index 6d9d631c6d0d..da0f02d44890 100644 --- a/packages/x-date-pickers/src/timeViewRenderers/timeViewRenderers.tsx +++ b/packages/x-date-pickers/src/timeViewRenderers/timeViewRenderers.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { TimeClock, TimeClockProps } from '../TimeClock'; import { PickerValidDate, TimeView } from '../models'; import { DigitalClock, DigitalClockProps } from '../DigitalClock'; -import { BaseClockProps } from '../internals/models/props/clock'; +import { BaseClockProps } from '../internals/models/props/time'; import { MultiSectionDigitalClock, MultiSectionDigitalClockProps, diff --git a/packages/x-date-pickers/src/validation/validateDate.ts b/packages/x-date-pickers/src/validation/validateDate.ts index e3bf707969aa..a47967e44d6f 100644 --- a/packages/x-date-pickers/src/validation/validateDate.ts +++ b/packages/x-date-pickers/src/validation/validateDate.ts @@ -9,6 +9,15 @@ import { DateValidationError, PickerValidDate } from '../models'; import { applyDefaultDate } from '../internals/utils/date-utils'; import { singleItemValueManager } from '../internals/utils/valueManagers'; +/** + * Validation props used by the Date Picker, Date Field and Date Calendar components. + */ +export interface ExportedValidateDateProps + extends DayValidationProps, + MonthValidationProps, + YearValidationProps, + BaseDateValidationProps {} + export interface ValidateDateProps extends DayValidationProps, MonthValidationProps, diff --git a/packages/x-date-pickers/src/validation/validateDateTime.ts b/packages/x-date-pickers/src/validation/validateDateTime.ts index 1e4824635532..fa0968313b3c 100644 --- a/packages/x-date-pickers/src/validation/validateDateTime.ts +++ b/packages/x-date-pickers/src/validation/validateDateTime.ts @@ -1,8 +1,17 @@ import { Validator } from './useValidation'; -import { validateDate, ValidateDateProps } from './validateDate'; -import { validateTime, ValidateTimeProps } from './validateTime'; +import { ExportedValidateDateProps, validateDate, ValidateDateProps } from './validateDate'; +import { ExportedValidateTimeProps, validateTime, ValidateTimeProps } from './validateTime'; import { DateTimeValidationError, PickerValidDate } from '../models'; import { singleItemValueManager } from '../internals/utils/valueManagers'; +import { DateTimeValidationProps } from '../internals/models/validation'; + +/** + * Validation props used by the Date Time Picker and Date Time Field components. + */ +export interface ExportedValidateDateTimeProps + extends ExportedValidateDateProps, + ExportedValidateTimeProps, + DateTimeValidationProps {} export interface ValidateDateTimeProps extends ValidateDateProps, diff --git a/packages/x-date-pickers/src/validation/validateTime.ts b/packages/x-date-pickers/src/validation/validateTime.ts index 2124913a3c14..4bf9ae6e1403 100644 --- a/packages/x-date-pickers/src/validation/validateTime.ts +++ b/packages/x-date-pickers/src/validation/validateTime.ts @@ -4,6 +4,13 @@ import { BaseTimeValidationProps, TimeValidationProps } from '../internals/model import { PickerValidDate, TimeValidationError } from '../models'; import { singleItemValueManager } from '../internals/utils/valueManagers'; +/** + * Validation props used by the Time Picker, Time Field and Clock components. + */ +export interface ExportedValidateTimeProps + extends BaseTimeValidationProps, + TimeValidationProps {} + export interface ValidateTimeProps extends Required, TimeValidationProps {}