UNPKG

rsuite

Version:

A suite of react components

46 lines 1.91 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import React from 'react'; import Input from "../Input/index.js"; import { createChainedFunction } from "../internals/utils/index.js"; export function defaultRenderInput(props, ref) { return /*#__PURE__*/React.createElement(Input, _extends({ ref: ref }, props)); } const pickers = ['DatePicker', 'DateRangePicker', 'TimePicker', 'TimeRangePicker', 'InputPicker', 'TagPicker', 'Cascader', 'MultiCascader', 'SelectPicker', 'CheckPicker', 'CheckTreePicker', 'TreePicker']; function getDisplayName(Component) { var _Component$type; if (typeof (Component === null || Component === void 0 ? void 0 : Component.type) === 'string') { return Component === null || Component === void 0 ? void 0 : Component.type; } return (Component === null || Component === void 0 || (_Component$type = Component.type) === null || _Component$type === void 0 ? void 0 : _Component$type.displayName) || ''; } export function renderChildren(children, props, ref) { if (typeof children === 'function') { return children(props, ref); } if (pickers.includes(getDisplayName(children))) { const { onBlur, ...rest } = props; const childElement = children; const { onExit, onClean } = childElement.props; return /*#__PURE__*/React.cloneElement(childElement, { ...rest, // Pass onBlur to the child component to automatically save or cancel after the focus event is processed. // Special handling in the Picker component, call onBlur when onExit and onClean onExit: createChainedFunction(() => onBlur === null || onBlur === void 0 ? void 0 : onBlur(), onExit), onClean: createChainedFunction(() => onBlur === null || onBlur === void 0 ? void 0 : onBlur(), onClean), ref }); } return /*#__PURE__*/React.cloneElement(children, { ...props, ref }); }