Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Aug 24, 2022
1 parent efcc39e commit 882feff
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ DateRangePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function DateRangePickerViewDesktop<TDate>(props: DesktopDateRangeCalenda
onSelectedDaysChange,
renderDay = (_, dateRangeProps) => <DateRangePickerDay {...dateRangeProps} />,
rightArrowButtonText: rightArrowButtonTextProp,
shouldDisableDate,
...other
} = props;

Expand Down Expand Up @@ -174,6 +175,10 @@ export function DateRangePickerViewDesktop<TDate>(props: DesktopDateRangeCalenda
changeMonth(utils.getPreviousMonth(currentMonth));
}, [changeMonth, currentMonth, utils]);

const wrappedShouldDisableDate =
shouldDisableDate &&
((dayToTest: TDate) => shouldDisableDate?.(dayToTest, currentlySelectingRangeEnd));

return (
<DateRangePickerViewDesktopRoot>
{getCalendarsArray(calendars).map((_, index) => {
Expand All @@ -197,6 +202,7 @@ export function DateRangePickerViewDesktop<TDate>(props: DesktopDateRangeCalenda
</DateRangePickerViewDesktopArrowSwitcher>
<DateRangePickerViewDesktopCalendar<TDate>
{...other}
shouldDisableDate={wrappedShouldDisableDate}
minDate={minDate}
maxDate={maxDate}
disablePast={disablePast}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ DesktopDateRangePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ MobileDateRangePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ StaticDateRangePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ export const validateDateRange: Validator<any, DateRangeValidationProps<any, any
return [null, null];
}

const { shouldDisableDate, ...otherProps } = props;

const dateValidations: [DateRangeValidationErrorValue, DateRangeValidationErrorValue] = [
validateDate({ adapter, value: start, props }),
validateDate({ adapter, value: end, props }),
validateDate({
adapter,
value: start,
props: {
...otherProps,
shouldDisableDate: (day) => !!shouldDisableDate?.(day, 'start'),
},
}),
validateDate({
adapter,
value: end,
props: {
...otherProps,
shouldDisableDate: (day) => !!shouldDisableDate?.(day, 'end'),
},
}),
];

if (dateValidations[0] || dateValidations[1]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ CalendarPicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions packages/x-date-pickers/src/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ DatePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ DateTimePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ DesktopDatePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ DesktopDateTimePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ MobileDatePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ MobileDateTimePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ StaticDatePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ StaticDateTimePicker.propTypes = {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export interface DayValidationProps<TDate> {
* Disable specific date. @DateIOType
* @template TDate
* @param {TDate} day The date to test.
* @param {'start' | 'end'} position The date to test.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
shouldDisableDate?: (day: TDate) => boolean;
shouldDisableDate?: (day: TDate, position?: 'start' | 'end') => boolean;
}

/**
Expand Down

0 comments on commit 882feff

Please sign in to comment.