UNPKG

@material-ui/lab

Version:

Material-UI Lab - Incubator for Material-UI React components.

70 lines (62 loc) 2.97 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import * as React from 'react'; import Picker from './Picker'; import { parsePickerInputValue } from '../date-utils'; import { withDefaultProps } from '../withDefaultProps'; import { KeyboardDateInput } from '../KeyboardDateInput'; import { withDateAdapterProp } from '../withDateAdapterProp'; import { makeWrapperComponent } from '../wrappers/makeWrapperComponent'; import { PureDateInput } from '../PureDateInput'; import { usePickerState } from '../hooks/usePickerState'; var valueManager = { emptyValue: null, parseInput: parsePickerInputValue, areValuesEqual: function areValuesEqual(utils, a, b) { return utils.isEqual(a, b); } }; export function makePickerWithStateAndWrapper(Wrapper, _ref) { var name = _ref.name, useInterceptProps = _ref.useInterceptProps, useValidation = _ref.useValidation, DefaultToolbarComponent = _ref.DefaultToolbarComponent; var WrapperComponent = makeWrapperComponent(Wrapper, { KeyboardDateInputComponent: KeyboardDateInput, PureDateInputComponent: PureDateInput }); function PickerWithState(__props) { var allProps = useInterceptProps(__props); var validationError = useValidation(allProps.value, allProps) !== null; var _usePickerState = usePickerState(allProps, valueManager), pickerProps = _usePickerState.pickerProps, inputProps = _usePickerState.inputProps, wrapperProps = _usePickerState.wrapperProps; // Note that we are passing down all the value without spread. // It saves us >1kb gzip and make any prop available automatically on any level down. var value = allProps.value, onChange = allProps.onChange, other = _objectWithoutProperties(allProps, ["value", "onChange"]); var AllDateInputProps = _extends({}, inputProps, other, { validationError: validationError }); return /*#__PURE__*/React.createElement(WrapperComponent, _extends({ wrapperProps: wrapperProps, DateInputProps: AllDateInputProps }, other), /*#__PURE__*/React.createElement(Picker, _extends({}, pickerProps, { toolbarTitle: allProps.label || allProps.toolbarTitle, ToolbarComponent: other.ToolbarComponent || DefaultToolbarComponent, DateInputProps: AllDateInputProps }, other))); } var FinalPickerComponent = withDefaultProps({ name: name }, withDateAdapterProp(PickerWithState)); // tslint:disable-next-line // @ts-ignore Simply ignore generic values in props, because it is impossible // to keep generics without additional cast when using forwardRef // @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35834 return /*#__PURE__*/React.forwardRef(function (props, ref) { return /*#__PURE__*/React.createElement(FinalPickerComponent, _extends({}, props, { forwardedRef: ref })); }); }