UNPKG

@mui/x-date-pickers-pro

Version:

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

83 lines 3.29 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["props", "steps"], _excluded2 = ["ownerState"]; import * as React from 'react'; import useSlotProps from '@mui/utils/useSlotProps'; import useEventCallback from '@mui/utils/useEventCallback'; import { useLicenseVerifier } from '@mui/x-license'; import { PickersLayout } from '@mui/x-date-pickers/PickersLayout'; import { usePicker, PickerPopper, PickerProvider, PickerFieldUIContextProvider } from '@mui/x-date-pickers/internals'; import { useRangePosition } from "../useRangePosition.js"; import { PickerRangePositionContext } from "../../../hooks/usePickerRangePositionContext.js"; import { getRangeFieldType } from "../../utils/date-fields-utils.js"; import { createRangePickerStepNavigation } from "../../utils/createRangePickerStepNavigation.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export const useDesktopRangePicker = _ref => { let { props, steps } = _ref, pickerParams = _objectWithoutPropertiesLoose(_ref, _excluded); useLicenseVerifier('x-date-pickers-pro', "MTc1NDYwNDAwMDAwMA=="); const { slots, slotProps, inputRef, localeText } = props; const fieldType = getRangeFieldType(slots.field); const viewContainerRole = fieldType === 'single-input' ? 'dialog' : 'tooltip'; const rangePositionResponse = useRangePosition(props); const getStepNavigation = createRangePickerStepNavigation({ steps, rangePositionResponse }); const { providerProps, renderCurrentView, ownerState } = usePicker(_extends({}, pickerParams, { props, variant: 'desktop', autoFocusView: viewContainerRole === 'dialog', viewContainerRole, localeText, getStepNavigation, onPopperExited: useEventCallback(() => rangePositionResponse.setRangePosition(props.defaultRangePosition ?? 'start')) })); const Field = slots.field; const _useSlotProps = useSlotProps({ elementType: Field, externalSlotProps: slotProps?.field, ownerState, additionalProps: { 'data-active-range-position': providerProps.contextValue.open ? rangePositionResponse.rangePosition : undefined } }), fieldProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded2); const Layout = slots?.layout ?? PickersLayout; const renderPicker = () => /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, { children: /*#__PURE__*/_jsx(PickerFieldUIContextProvider, { slots: slots, slotProps: slotProps, inputRef: inputRef, children: /*#__PURE__*/_jsxs(PickerRangePositionContext.Provider, { value: rangePositionResponse, children: [/*#__PURE__*/_jsx(Field, _extends({}, fieldProps)), /*#__PURE__*/_jsx(PickerPopper, { slots: slots, slotProps: slotProps, children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, { slots: slots, slotProps: slotProps, children: renderCurrentView() })) })] }) }) })); if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker"; return { renderPicker }; };