Skip to content

Commit

Permalink
Avoid root exporting DayRangeValidationProps
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy committed May 14, 2024
1 parent 94e5120 commit 415f8eb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
extends DayRangeValidationProps<TDate>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TDate extends PickerValidDate>
extends DayRangeValidationProps<TDate>,
Expand Down
46 changes: 46 additions & 0 deletions packages/x-date-pickers-pro/src/models/dateRange.ts
Original file line number Diff line number Diff line change
@@ -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<TDate extends PickerValidDate> {
/**
* 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>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
DateRangeValidationError
>,
'unstableFieldRef'
>,
'format'
>,
RangeFieldSeparatorProps,
DayRangeValidationProps<TDate>,
BaseDateValidationProps<TDate> {}
1 change: 1 addition & 0 deletions packages/x-date-pickers-pro/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { UseDateRangeFieldProps } from './dateRange';
export * from './fields';
export * from './range';
export * from './validation';
Expand Down
44 changes: 0 additions & 44 deletions packages/x-date-pickers-pro/src/models/range.ts
Original file line number Diff line number Diff line change
@@ -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 extends PickerValidDate> = [TDate | null, TDate | null];

export type NonEmptyDateRange<TDate extends PickerValidDate> = [TDate, TDate];

export type RangePosition = 'start' | 'end';

/**
* Props used to validate a day value in range pickers.
*/
export interface DayRangeValidationProps<TDate extends PickerValidDate> {
/**
* 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>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
DateRangeValidationError
>,
'unstableFieldRef'
>,
'format'
>,
RangeFieldSeparatorProps,
DayRangeValidationProps<TDate>,
BaseDateValidationProps<TDate> {}

0 comments on commit 415f8eb

Please sign in to comment.