@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
39 lines • 1.47 kB
JavaScript
import * as React from 'react';
import { useUtils } from "./useUtils.js";
import { getMeridiem, convertToMeridiem } from "../utils/time-utils.js";
export function useNextMonthDisabled(month, {
disableFuture,
maxDate,
timezone
}) {
const utils = useUtils();
return React.useMemo(() => {
const now = utils.date(undefined, timezone);
const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
return !utils.isAfter(lastEnabledMonth, month);
}, [disableFuture, maxDate, month, utils, timezone]);
}
export function usePreviousMonthDisabled(month, {
disablePast,
minDate,
timezone
}) {
const utils = useUtils();
return React.useMemo(() => {
const now = utils.date(undefined, timezone);
const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
return !utils.isBefore(firstEnabledMonth, month);
}, [disablePast, minDate, month, utils, timezone]);
}
export function useMeridiemMode(date, ampm, onChange, selectionState) {
const utils = useUtils();
const meridiemMode = getMeridiem(date, utils);
const handleMeridiemChange = React.useCallback(mode => {
const timeWithMeridiem = date == null ? null : convertToMeridiem(date, mode, Boolean(ampm), utils);
onChange(timeWithMeridiem, selectionState ?? 'partial');
}, [ampm, date, onChange, selectionState, utils]);
return {
meridiemMode,
handleMeridiemChange
};
}