UNPKG

@mui/x-date-pickers-pro

Version:

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

127 lines (126 loc) 5.51 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.useMobileRangePicker = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var React = _interopRequireWildcard(require("react")); var _useSlotProps2 = _interopRequireDefault(require("@mui/utils/useSlotProps")); var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback")); var _resolveComponentProps = _interopRequireDefault(require("@mui/utils/resolveComponentProps")); var _xLicense = require("@mui/x-license"); var _PickersLayout = require("@mui/x-date-pickers/PickersLayout"); var _internals = require("@mui/x-date-pickers/internals"); var _hooks = require("@mui/x-date-pickers/hooks"); var _useRangePosition = require("../useRangePosition"); var _usePickerRangePositionContext = require("../../../hooks/usePickerRangePositionContext"); var _dateFieldsUtils = require("../../utils/date-fields-utils"); var _createRangePickerStepNavigation = require("../../utils/createRangePickerStepNavigation"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["props", "steps"], _excluded2 = ["ownerState"]; const useMobileRangePicker = _ref => { let { props, steps } = _ref, pickerParams = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded); (0, _xLicense.useLicenseVerifier)('x-date-pickers-pro', "MTc1NDYwNDAwMDAwMA=="); const { slots, slotProps: innerSlotProps, label, inputRef, localeText } = props; const fieldType = (0, _dateFieldsUtils.getRangeFieldType)(slots.field); const rangePositionResponse = (0, _useRangePosition.useRangePosition)(props); const contextTranslations = (0, _hooks.usePickerTranslations)(); const getStepNavigation = (0, _createRangePickerStepNavigation.createRangePickerStepNavigation)({ steps, rangePositionResponse }); const { providerProps, renderCurrentView, ownerState } = (0, _internals.usePicker)((0, _extends2.default)({}, pickerParams, { props, variant: 'mobile', autoFocusView: true, viewContainerRole: 'dialog', localeText, getStepNavigation, onPopperExited: (0, _useEventCallback.default)(() => rangePositionResponse.setRangePosition(props.defaultRangePosition ?? 'start')) })); const labelId = providerProps.privateContextValue.labelId; const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false; const Field = slots.field; const _useSlotProps = (0, _useSlotProps2.default)({ elementType: Field, externalSlotProps: innerSlotProps?.field, additionalProps: (0, _extends2.default)({}, fieldType === 'single-input' && isToolbarHidden && { id: labelId }), ownerState }), fieldProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded2); const Layout = slots?.layout ?? _PickersLayout.PickersLayout; const finalLocaleText = (0, _extends2.default)({}, contextTranslations, localeText); let labelledById = pickerParams.valueType === 'date-time' ? `${labelId}-start-toolbar ${labelId}-end-toolbar` : labelId; if (isToolbarHidden) { const labels = []; if (fieldType === 'multi-input') { if (finalLocaleText.start) { labels.push(`${labelId}-start-label`); } if (finalLocaleText.end) { labels.push(`${labelId}-end-label`); } } else if (label != null) { labels.push(`${labelId}-label`); } labelledById = labels.length > 0 ? labels.join(' ') : undefined; } const slotProps = (0, _extends2.default)({}, innerSlotProps, { toolbar: (0, _extends2.default)({}, innerSlotProps?.toolbar, { titleId: labelId }), mobilePaper: (0, _extends2.default)({ 'aria-labelledby': labelledById }, innerSlotProps?.mobilePaper) }, fieldType === 'multi-input' && { textField: slotOwnerState => { return (0, _extends2.default)({}, (0, _resolveComponentProps.default)(innerSlotProps?.textField, slotOwnerState), { id: `${labelId}-${slotOwnerState.position}` }); } }); const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.PickerProvider, (0, _extends2.default)({}, providerProps, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.PickerFieldUIContextProvider, { slots: slots, slotProps: slotProps, inputRef: inputRef, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_usePickerRangePositionContext.PickerRangePositionContext.Provider, { value: rangePositionResponse, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, fieldProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.PickersModalDialog, { slots: slots, slotProps: slotProps, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Layout, (0, _extends2.default)({}, slotProps?.layout, { slots: slots, slotProps: slotProps, children: renderCurrentView() })) })] }) }) })); if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker"; return { renderPicker }; }; exports.useMobileRangePicker = useMobileRangePicker;