UNPKG

2.95 kBJavaScriptView Raw
1"use client";
2
3import * as React from 'react';
4import classNames from 'classnames';
5import Col from '../grid/col';
6import { FormContext, FormItemPrefixContext } from './context';
7import ErrorList from './ErrorList';
8import FallbackCmp from './style/fallbackCmp';
9const FormItemInput = props => {
10 const {
11 prefixCls,
12 status,
13 wrapperCol,
14 children,
15 errors,
16 warnings,
17 _internalItemRender: formItemRender,
18 extra,
19 help,
20 fieldId,
21 marginBottom,
22 onErrorVisibleChanged
23 } = props;
24 const baseClassName = `${prefixCls}-item`;
25 const formContext = React.useContext(FormContext);
26 const mergedWrapperCol = wrapperCol || formContext.wrapperCol || {};
27 const className = classNames(`${baseClassName}-control`, mergedWrapperCol.className);
28 // Pass to sub FormItem should not with col info
29 const subFormContext = React.useMemo(() => Object.assign({}, formContext), [formContext]);
30 delete subFormContext.labelCol;
31 delete subFormContext.wrapperCol;
32 const inputDom = /*#__PURE__*/React.createElement("div", {
33 className: `${baseClassName}-control-input`
34 }, /*#__PURE__*/React.createElement("div", {
35 className: `${baseClassName}-control-input-content`
36 }, children));
37 const formItemContext = React.useMemo(() => ({
38 prefixCls,
39 status
40 }), [prefixCls, status]);
41 const errorListDom = marginBottom !== null || errors.length || warnings.length ? ( /*#__PURE__*/React.createElement("div", {
42 style: {
43 display: 'flex',
44 flexWrap: 'nowrap'
45 }
46 }, /*#__PURE__*/React.createElement(FormItemPrefixContext.Provider, {
47 value: formItemContext
48 }, /*#__PURE__*/React.createElement(ErrorList, {
49 fieldId: fieldId,
50 errors: errors,
51 warnings: warnings,
52 help: help,
53 helpStatus: status,
54 className: `${baseClassName}-explain-connected`,
55 onVisibleChanged: onErrorVisibleChanged
56 })), !!marginBottom && /*#__PURE__*/React.createElement("div", {
57 style: {
58 width: 0,
59 height: marginBottom
60 }
61 }))) : null;
62 const extraProps = {};
63 if (fieldId) {
64 extraProps.id = `${fieldId}_extra`;
65 }
66 // If extra = 0, && will goes wrong
67 // 0&&error -> 0
68 const extraDom = extra ? ( /*#__PURE__*/React.createElement("div", Object.assign({}, extraProps, {
69 className: `${baseClassName}-extra`
70 }), extra)) : null;
71 const dom = formItemRender && formItemRender.mark === 'pro_table_render' && formItemRender.render ? formItemRender.render(props, {
72 input: inputDom,
73 errorList: errorListDom,
74 extra: extraDom
75 }) : ( /*#__PURE__*/React.createElement(React.Fragment, null, inputDom, errorListDom, extraDom));
76 return /*#__PURE__*/React.createElement(FormContext.Provider, {
77 value: subFormContext
78 }, /*#__PURE__*/React.createElement(Col, Object.assign({}, mergedWrapperCol, {
79 className: className
80 }), dom), /*#__PURE__*/React.createElement(FallbackCmp, {
81 prefixCls: prefixCls
82 }));
83};
84export default FormItemInput;
\No newline at end of file