Skip to content

Commit

Permalink
[pickers] Clean definition of validation props
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Oct 30, 2024
1 parent f613377 commit 3b73a0b
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 114 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
16 changes: 2 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,16 @@
import {
BaseDateValidationProps,
TimeValidationProps,
MakeOptional,
UseFieldInternalProps,
DateTimeValidationProps,
DateOrTimeViewWithMeridiem,
} 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 +29,7 @@ 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> {}

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

Expand Down
17 changes: 3 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 } 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,4 @@ export interface UseTimeRangeFieldProps<
'format'
>,
RangeFieldSeparatorProps,
TimeValidationProps<TDate>,
BaseTimeValidationProps {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
ExportedValidateTimeRangeProps<TDate> {}
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
22 changes: 19 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,32 @@
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> {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}

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
26 changes: 3 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,12 @@ 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';

export interface UseDateTimeFieldProps<
TDate extends PickerValidDate,
Expand All @@ -37,20 +29,8 @@ 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 {}

export type DateTimeFieldProps<
TDate extends PickerValidDate,
Expand Down
13 changes: 3 additions & 10 deletions packages/x-date-pickers/src/TimeField/TimeField.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,6 +14,7 @@ import {
UseClearableFieldSlots,
UseClearableFieldSlotProps,
} from '../hooks/useClearableField';
import { ExportedValidateTimeProps } from '../validation/validateTime';

export interface UseTimeFieldProps<
TDate extends PickerValidDate,
Expand All @@ -29,15 +29,8 @@ export interface UseTimeFieldProps<
>,
'format'
>,
TimeValidationProps<TDate>,
BaseTimeValidationProps,
ExportedUseClearableFieldProps {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
ExportedValidateTimeProps<TDate>,
ExportedUseClearableFieldProps {}

export type TimeFieldProps<
TDate extends PickerValidDate,
Expand Down
13 changes: 3 additions & 10 deletions packages/x-date-pickers/src/internals/models/props/clock.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
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<TDate extends PickerValidDate>
extends TimeValidationProps<TDate>,
BaseTimeValidationProps,
TimezoneProps {
/**
* 12h/24h view for hour selection clock.
* @default utils.is12HourCycleInCurrentLocale()
*/
ampm?: boolean;
}
extends ExportedValidateTimeProps<TDate>,
TimezoneProps {}

export interface BaseClockProps<TDate extends PickerValidDate, TView extends TimeViewWithMeridiem>
extends ExportedUseViewsOptions<TView>,
Expand Down
9 changes: 9 additions & 0 deletions packages/x-date-pickers/src/validation/validateDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
extends DayValidationProps<TDate>,
MonthValidationProps<TDate>,
YearValidationProps<TDate>,
BaseDateValidationProps<TDate> {}

export interface ValidateDateProps<TDate extends PickerValidDate>
extends DayValidationProps<TDate>,
MonthValidationProps<TDate>,
Expand Down
Loading

0 comments on commit 3b73a0b

Please sign in to comment.