Skip to content

Commit

Permalink
Set position non nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Aug 26, 2022
1 parent c9959ad commit 7ac942a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import {
PickerStatePickerProps,
DayPickerProps,
BaseDateValidationProps,
DayValidationProps,
} from '@mui/x-date-pickers/internals';
import { DateRange, CurrentlySelectingRangeEndProps } from '../internal/models/dateRange';
import {
DateRange,
CurrentlySelectingRangeEndProps,
DayRangeValidationProps,
} from '../internal/models/dateRange';
import { isRangeValid } from '../internal/utils/date-utils';
import { calculateRangeChange } from './date-range-manager';
import { DateRangePickerToolbar } from './DateRangePickerToolbar';
Expand All @@ -38,9 +43,13 @@ export interface DateRangePickerViewSlotsComponentsProps

export interface ExportedDateRangePickerViewProps<TDate>
extends ExportedDesktopDateRangeCalendarProps<TDate>,
DayRangeValidationProps<TDate>,
Omit<
ExportedCalendarPickerProps<TDate>,
'onYearChange' | 'renderDay' | keyof BaseDateValidationProps<TDate>
| 'onYearChange'
| 'renderDay'
| keyof BaseDateValidationProps<TDate>
| keyof DayValidationProps<TDate>
> {
/**
* Overrideable components.
Expand Down Expand Up @@ -74,14 +83,6 @@ export interface ExportedDateRangePickerViewProps<TDate>
* className applied to the root component.
*/
className?: string;
/**
* Disable specific date. @DateIOType
* @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;
}

interface DateRangePickerViewProps<TInputDate, TDate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@ import {
DateValidationError,
validateDate,
BaseDateValidationProps,
DayValidationProps,
} from '@mui/x-date-pickers/internals';
import { isRangeValid, parseRangeInputValue } from '../../utils/date-utils';
import { DateRange } from '../../models';
import { DateRange, DayRangeValidationProps } from '../../models/dateRange';

export interface DateRangeValidationProps<TInputDate, TDate>
extends DayValidationProps<TDate>,
extends DayRangeValidationProps<TDate>,
Required<BaseDateValidationProps<TDate>>,
ValidationProps<DateRangeValidationError, DateRange<TInputDate>> {
/**
* Disable specific date. @DateIOType
* @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;
}
ValidationProps<DateRangeValidationError, DateRange<TInputDate>> {}

export const validateDateRange: Validator<any, DateRangeValidationProps<any, any>> = ({
props,
Expand Down
14 changes: 14 additions & 0 deletions packages/x-date-pickers-pro/src/internal/models/dateRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@ export interface CurrentlySelectingRangeEndProps {
currentlySelectingRangeEnd: 'start' | 'end';
setCurrentlySelectingRangeEnd: (newSelectingEnd: 'start' | 'end') => void;
}

/**
* Props used to validate a day value in range pickers.
*/
export interface DayRangeValidationProps<TDate> {
/**
* Disable specific date. @DateIOType
* @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;
}

0 comments on commit 7ac942a

Please sign in to comment.