@mui/x-date-pickers-pro
Version: 
The Pro plan edition of the MUI X Date and Time Picker components.
72 lines (71 loc) • 2.51 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["props", "steps"];
import * as React from 'react';
import clsx from 'clsx';
import { styled } from '@mui/material/styles';
import { PickersLayout } from '@mui/x-date-pickers/PickersLayout';
import { usePicker, DIALOG_WIDTH, PickerProvider, mergeSx } from '@mui/x-date-pickers/internals';
import { useRangePosition } from "../useRangePosition.js";
import { PickerRangePositionContext } from "../../../hooks/usePickerRangePositionContext.js";
import { createRangePickerStepNavigation } from "../../utils/createRangePickerStepNavigation.js";
import { jsx as _jsx } from "react/jsx-runtime";
const PickerStaticLayout = styled(PickersLayout)(({
  theme
}) => ({
  overflow: 'hidden',
  minWidth: DIALOG_WIDTH,
  backgroundColor: (theme.vars || theme).palette.background.paper
}));
/**
 * Hook managing all the range static pickers:
 * - StaticDateRangePicker
 */
export const useStaticRangePicker = _ref => {
  let {
      props,
      steps
    } = _ref,
    pickerParams = _objectWithoutPropertiesLoose(_ref, _excluded);
  const {
    localeText,
    slots,
    slotProps,
    displayStaticWrapperAs,
    autoFocus
  } = props;
  const rangePositionResponse = useRangePosition(props);
  const getStepNavigation = createRangePickerStepNavigation({
    steps,
    rangePositionResponse
  });
  const {
    providerProps,
    renderCurrentView
  } = usePicker(_extends({}, pickerParams, {
    props,
    variant: displayStaticWrapperAs,
    autoFocusView: autoFocus ?? false,
    viewContainerRole: null,
    localeText,
    getStepNavigation
  }));
  const Layout = slots?.layout ?? PickerStaticLayout;
  const renderPicker = () => /*#__PURE__*/_jsx(PickerRangePositionContext.Provider, {
    value: rangePositionResponse,
    children: /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, {
      children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, {
        slots: slots,
        slotProps: slotProps,
        sx: mergeSx(providerProps.contextValue.rootSx, slotProps?.layout?.sx),
        className: clsx(providerProps.contextValue.rootClassName, slotProps?.layout?.className),
        ref: providerProps.contextValue.rootRef,
        children: renderCurrentView()
      }))
    }))
  });
  if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker";
  return {
    renderPicker
  };
};