From 415f8eb7281b013d42102db0f10244518ac8160c Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 14 May 2024 19:14:59 +0300 Subject: [PATCH] Avoid root exporting `DayRangeValidationProps` --- .../DateRangeCalendar.types.ts | 3 +- .../src/internals/models/dateTimeRange.ts | 2 +- .../utils/validation/validateDateRange.ts | 3 +- .../utils/validation/validateDateTimeRange.ts | 3 +- .../src/models/dateRange.ts | 46 +++++++++++++++++++ .../x-date-pickers-pro/src/models/index.ts | 1 + .../x-date-pickers-pro/src/models/range.ts | 44 ------------------ 7 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 packages/x-date-pickers-pro/src/models/dateRange.ts 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 7c611b549a2b..355598821b36 100644 --- a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts +++ b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.types.ts @@ -19,7 +19,8 @@ import { DayCalendarProps, ExportedUseViewsOptions, } from '@mui/x-date-pickers/internals'; -import { DateRange, DayRangeValidationProps } from '../models'; +import { DayRangeValidationProps } from '../models/dateRange'; +import { DateRange } from '../models'; import { DateRangeCalendarClasses } from './dateRangeCalendarClasses'; import { DateRangePickerDay, DateRangePickerDayProps } from '../DateRangePickerDay'; import { UseRangePositionProps } from '../internals/hooks/useRangePosition'; 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 3d8882dd094f..6063d764b864 100644 --- a/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/internals/models/dateTimeRange.ts @@ -7,12 +7,12 @@ import { DateOrTimeViewWithMeridiem, } from '@mui/x-date-pickers/internals'; import { PickerValidDate } from '@mui/x-date-pickers/models'; +import { DayRangeValidationProps } from '../../models/dateRange'; import { DateTimeRangeValidationError, RangeFieldSection, DateRange, RangeFieldSeparatorProps, - DayRangeValidationProps, } from '../../models'; export interface UseDateTimeRangeFieldProps< diff --git a/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateRange.ts b/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateRange.ts index f23db5da8686..fc621db83970 100644 --- a/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateRange.ts +++ b/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateRange.ts @@ -6,7 +6,8 @@ import { DefaultizedProps, } from '@mui/x-date-pickers/internals'; import { isRangeValid } from '../date-utils'; -import { DateRangeValidationError, DateRange, DayRangeValidationProps } from '../../../models'; +import { DayRangeValidationProps } from '../../../models/dateRange'; +import { DateRangeValidationError, DateRange } from '../../../models'; export interface DateRangeComponentValidationProps extends DayRangeValidationProps, diff --git a/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateTimeRange.ts b/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateTimeRange.ts index 12ce9428adfa..bdace5051347 100644 --- a/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateTimeRange.ts +++ b/packages/x-date-pickers-pro/src/internals/utils/validation/validateDateTimeRange.ts @@ -7,7 +7,8 @@ import { DefaultizedProps, } from '@mui/x-date-pickers/internals'; import { isRangeValid } from '../date-utils'; -import { DateTimeRangeValidationError, DateRange, DayRangeValidationProps } from '../../../models'; +import { DayRangeValidationProps } from '../../../models/dateRange'; +import { DateTimeRangeValidationError, DateRange } from '../../../models'; export interface DateTimeRangeComponentValidationProps extends DayRangeValidationProps, diff --git a/packages/x-date-pickers-pro/src/models/dateRange.ts b/packages/x-date-pickers-pro/src/models/dateRange.ts new file mode 100644 index 000000000000..cc0292d2aaef --- /dev/null +++ b/packages/x-date-pickers-pro/src/models/dateRange.ts @@ -0,0 +1,46 @@ +import { + BaseDateValidationProps, + 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'; + +/** + * Props used to validate a day value in range pickers. + */ +export interface DayRangeValidationProps { + /** + * Disable specific date. + * + * Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance. + * + * @template TDate + * @param {TDate} day The date to test. + * @param {string} position The date to test, 'start' or 'end'. + * @returns {boolean} Returns `true` if the date should be disabled. + */ + shouldDisableDate?: (day: TDate, position: 'start' | 'end') => boolean; +} + +export interface UseDateRangeFieldProps< + TDate extends PickerValidDate, + TEnableAccessibleFieldDOMStructure extends boolean, +> extends MakeOptional< + Omit< + UseFieldInternalProps< + DateRange, + TDate, + RangeFieldSection, + TEnableAccessibleFieldDOMStructure, + DateRangeValidationError + >, + 'unstableFieldRef' + >, + 'format' + >, + RangeFieldSeparatorProps, + DayRangeValidationProps, + BaseDateValidationProps {} diff --git a/packages/x-date-pickers-pro/src/models/index.ts b/packages/x-date-pickers-pro/src/models/index.ts index 7a709045ff25..cb450d757b94 100644 --- a/packages/x-date-pickers-pro/src/models/index.ts +++ b/packages/x-date-pickers-pro/src/models/index.ts @@ -1,3 +1,4 @@ +export type { UseDateRangeFieldProps } from './dateRange'; export * from './fields'; export * from './range'; export * from './validation'; diff --git a/packages/x-date-pickers-pro/src/models/range.ts b/packages/x-date-pickers-pro/src/models/range.ts index 0542eb172e6a..92bbff21e1d1 100644 --- a/packages/x-date-pickers-pro/src/models/range.ts +++ b/packages/x-date-pickers-pro/src/models/range.ts @@ -1,51 +1,7 @@ -import { - BaseDateValidationProps, - 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'; export type DateRange = [TDate | null, TDate | null]; export type NonEmptyDateRange = [TDate, TDate]; export type RangePosition = 'start' | 'end'; - -/** - * Props used to validate a day value in range pickers. - */ -export interface DayRangeValidationProps { - /** - * Disable specific date. - * - * Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance. - * - * @template TDate - * @param {TDate} day The date to test. - * @param {string} position The date to test, 'start' or 'end'. - * @returns {boolean} Returns `true` if the date should be disabled. - */ - shouldDisableDate?: (day: TDate, position: 'start' | 'end') => boolean; -} - -export interface UseDateRangeFieldProps< - TDate extends PickerValidDate, - TEnableAccessibleFieldDOMStructure extends boolean, -> extends MakeOptional< - Omit< - UseFieldInternalProps< - DateRange, - TDate, - RangeFieldSection, - TEnableAccessibleFieldDOMStructure, - DateRangeValidationError - >, - 'unstableFieldRef' - >, - 'format' - >, - RangeFieldSeparatorProps, - DayRangeValidationProps, - BaseDateValidationProps {}