UNPKG

@mui/x-date-pickers-pro

Version:

The Pro plan edition of the MUI X Date and Time Picker components.

53 lines 1.79 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["viewRenderer", "value", "onChange", "defaultValue", "onViewChange", "views", "className"]; import { useUtils } from '@mui/x-date-pickers/internals'; import { isRangeValid } from "../internals/utils/date-utils.js"; import { calculateRangeChange } from "../internals/utils/date-range-manager.js"; import { usePickerRangePositionContext } from "../hooks/index.js"; /** * @ignore - internal component. */ function TimeRangePickerTimeWrapper(props) { const utils = useUtils(); const { viewRenderer, value, onChange, defaultValue, onViewChange, views } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const { rangePosition } = usePickerRangePositionContext(); if (!viewRenderer) { return null; } const currentValue = (rangePosition === 'start' ? value?.[0] : value?.[1]) ?? null; const currentDefaultValue = (rangePosition === 'start' ? defaultValue?.[0] : defaultValue?.[1]) ?? null; const handleOnChange = (newDate, selectionState, selectedView) => { if (!onChange || !value) { return; } const { newRange } = calculateRangeChange({ newDate, utils, range: value, rangePosition }); const isFullRangeSelected = rangePosition === 'end' && isRangeValid(utils, newRange); onChange(newRange, isFullRangeSelected ? 'finish' : 'partial', selectedView); }; return viewRenderer(_extends({}, other, { views, onViewChange, value: currentValue, onChange: handleOnChange, defaultValue: currentDefaultValue })); } export { TimeRangePickerTimeWrapper };