UNPKG

zent

Version:

一套前端设计语言和基于React的实现

27 lines (26 loc) 1.5 kB
import { __assign } from "tslib"; import { jsx as _jsx } from "react/jsx-runtime"; import { useCallback } from 'react'; import Input from '../../input'; import { FormField } from '../Field'; import { TouchWhen, ValidateOccasion } from '../shared'; import { warningDefaultValueProp } from '../utils'; import { useEventCallbackRef } from '../../utils/hooks/useEventCallbackRef'; import * as React from 'react'; var InputField = function (_a) { var childProps = _a.childProps, props = _a.props; var onChangeRef = useEventCallbackRef(childProps.onChange); var onChange = useCallback(function (e) { var _a; (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, e.target.value); }, [onChangeRef]); return (_jsx(Input, __assign({}, props.props, childProps, { onChange: onChange }), void 0)); }; export var FormInputField = function (props) { var _a = props.validateOccasion, validateOccasion = _a === void 0 ? ValidateOccasion.Blur : _a; React.useEffect(function () { var _a; warningDefaultValueProp(!('defaultValue' in ((_a = props.props) !== null && _a !== void 0 ? _a : {})), 'defaultValue', 'FormInputField'); }, []); return (_jsx(FormField, __assign({}, props, { defaultValue: props.defaultValue || '', touchWhen: TouchWhen.Blur, validateOccasion: validateOccasion }, { children: function (childProps) { return _jsx(InputField, { childProps: childProps, props: props }, void 0); } }), void 0)); };