Skip to content

Commit

Permalink
[pickers] Clean definition of validation props (#15198)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Oct 31, 2024
1 parent 3ed65dc commit 302c876
Show file tree
Hide file tree
Showing 26 changed files with 106 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
extends PickersArrowSwitcherSlots,
Expand Down Expand Up @@ -62,8 +62,7 @@ export interface DateRangeCalendarSlotProps<TDate extends PickerValidDate>

export interface ExportedDateRangeCalendarProps<TDate extends PickerValidDate>
extends ExportedDayCalendarProps<TDate>,
BaseDateValidationProps<TDate>,
DayRangeValidationProps<TDate>,
ExportedValidateDateRangeProps<TDate>,
TimezoneProps {
/**
* If `true`, after selecting `start` date calendar will not automatically switch to the month of `end` date.
Expand Down
3 changes: 1 addition & 2 deletions packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export interface BaseDateRangePickerProps<TDate extends PickerValidDate>
BasePickerInputProps<DateRange<TDate>, TDate, 'day', DateRangeValidationError>,
'view' | 'views' | 'openTo' | 'onViewChange' | 'orientation'
>,
ExportedDateRangeCalendarProps<TDate>,
BaseDateValidationProps<TDate> {
ExportedDateRangeCalendarProps<TDate> {
/**
* Overridable component slots.
* @default {}
Expand Down
18 changes: 4 additions & 14 deletions packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -32,16 +30,8 @@ export interface UseDateTimeRangeFieldProps<
'format'
>,
RangeFieldSeparatorProps,
DayRangeValidationProps<TDate>,
TimeValidationProps<TDate>,
BaseDateValidationProps<TDate>,
DateTimeValidationProps<TDate> {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
ExportedValidateDateTimeRangeProps<TDate>,
AmPmProps {}

export type DateTimeRangePickerView = Exclude<DateOrTimeViewWithMeridiem, 'month' | 'year'>;

Expand Down
18 changes: 4 additions & 14 deletions packages/x-date-pickers-pro/src/internals/models/timeRange.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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,
RangeFieldSection,
DateRange,
RangeFieldSeparatorProps,
} from '../../models';
import type { ExportedValidateTimeRangeProps } from '../../validation/validateTimeRange';

export interface UseTimeRangeFieldProps<
TDate extends PickerValidDate,
Expand All @@ -29,11 +25,5 @@ export interface UseTimeRangeFieldProps<
'format'
>,
RangeFieldSeparatorProps,
TimeValidationProps<TDate>,
BaseTimeValidationProps {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
ExportedValidateTimeRangeProps<TDate>,
AmPmProps {}
11 changes: 3 additions & 8 deletions packages/x-date-pickers-pro/src/models/dateRange.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,5 +22,4 @@ export interface UseDateRangeFieldProps<
'format'
>,
RangeFieldSeparatorProps,
DayRangeValidationProps<TDate>,
BaseDateValidationProps<TDate> {}
ExportedValidateDateRangeProps<TDate> {}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
extends DayRangeValidationProps<TDate>,
BaseDateValidationProps<TDate> {}

export interface ValidateDateRangeProps<TDate extends PickerValidDate>
extends DayRangeValidationProps<TDate>,
Required<BaseDateValidationProps<TDate>> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TDate extends PickerValidDate>
extends ExportedValidateDateRangeProps<TDate>,
ExportedValidateTimeRangeProps<TDate>,
DateTimeValidationProps<TDate> {}

export interface ValidateDateTimeRangeProps<TDate extends PickerValidDate>
extends DayRangeValidationProps<TDate>,
TimeValidationProps<TDate>,
Required<BaseDateValidationProps<TDate>> {}
extends ValidateDateRangeProps<TDate>,
ValidateTimeRangeProps<TDate> {}

export const validateDateTimeRange: Validator<
DateRange<any>,
Expand Down
16 changes: 13 additions & 3 deletions packages/x-date-pickers-pro/src/validation/validateTimeRange.ts
Original file line number Diff line number Diff line change
@@ -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<BaseTimeValidationProps> {}
/**
* Validation props used by the Time Range Picker and Time Range Field.
*/
export interface ExportedValidateTimeRangeProps<TDate extends PickerValidDate>
extends BaseTimeValidationProps,
TimeValidationProps<TDate> {}

export interface ValidateTimeRangeProps<TDate extends PickerValidDate>
extends Required<BaseTimeValidationProps>,
TimeValidationProps<TDate> {}

export const validateTimeRange: Validator<
DateRange<any>,
any,
TimeRangeValidationError,
ValidateTimeRangeProps
ValidateTimeRangeProps<any>
> = ({ adapter, value, timezone, props }) => {
const [start, end] = value;

Expand Down
13 changes: 3 additions & 10 deletions packages/x-date-pickers/src/DateCalendar/DateCalendar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,6 +24,7 @@ import {
MonthCalendarSlots,
MonthCalendarSlotProps,
} from '../MonthCalendar/MonthCalendar.types';
import { ExportedValidateDateProps } from '../validation/validateDate';

export interface DateCalendarSlots<TDate extends PickerValidDate>
extends PickersCalendarHeaderSlots,
Expand All @@ -55,10 +51,7 @@ export interface ExportedDateCalendarProps<TDate extends PickerValidDate>
extends ExportedDayCalendarProps<TDate>,
ExportedMonthCalendarProps,
ExportedYearCalendarProps,
BaseDateValidationProps<TDate>,
DayValidationProps<TDate>,
YearValidationProps<TDate>,
MonthValidationProps<TDate>,
ExportedValidateDateProps<TDate>,
TimezoneProps {
/**
* If `true`, the picker and text field are disabled.
Expand Down
12 changes: 2 additions & 10 deletions packages/x-date-pickers/src/DateField/DateField.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,10 +29,7 @@ export interface UseDateFieldProps<
>,
'format'
>,
DayValidationProps<TDate>,
MonthValidationProps<TDate>,
YearValidationProps<TDate>,
BaseDateValidationProps<TDate>,
ExportedValidateDateProps<TDate>,
ExportedUseClearableFieldProps {}

export type DateFieldProps<
Expand Down
28 changes: 5 additions & 23 deletions packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,20 +30,9 @@ export interface UseDateTimeFieldProps<
>,
'format'
>,
DayValidationProps<TDate>,
MonthValidationProps<TDate>,
YearValidationProps<TDate>,
BaseDateValidationProps<TDate>,
TimeValidationProps<TDate>,
BaseTimeValidationProps,
DateTimeValidationProps<TDate>,
ExportedUseClearableFieldProps {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
ExportedValidateDateTimeProps<TDate>,
ExportedUseClearableFieldProps,
AmPmProps {}

export type DateTimeFieldProps<
TDate extends PickerValidDate,
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/DateTimePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/TimeClock/TimeClock.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading

0 comments on commit 302c876

Please sign in to comment.