2021-06-07 09:35:03 +00:00
|
|
|
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
|
|
|
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
|
|
|
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
|
|
|
|
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
|
|
|
|
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { ColProps } from '../grid/Col';
|
|
|
|
import Col from '../grid/Col';
|
2021-06-07 09:35:03 +00:00
|
|
|
import { useProvideForm, useInjectForm, useProvideFormItemPrefix } from './context';
|
|
|
|
import ErrorList from './ErrorList';
|
|
|
|
import classNames from '../_util/classNames';
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { ValidateStatus } from './FormItem';
|
|
|
|
import type { VueNode } from '../_util/type';
|
|
|
|
import type { HTMLAttributes } from 'vue';
|
2022-03-12 01:56:32 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-06-07 09:35:03 +00:00
|
|
|
|
|
|
|
export interface FormItemInputMiscProps {
|
|
|
|
prefixCls: string;
|
|
|
|
errors: VueNode[];
|
|
|
|
hasFeedback?: boolean;
|
|
|
|
validateStatus?: ValidateStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface FormItemInputProps {
|
|
|
|
wrapperCol?: ColProps;
|
|
|
|
help?: VueNode;
|
|
|
|
extra?: VueNode;
|
|
|
|
status?: ValidateStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
const iconMap: { [key: string]: any } = {
|
|
|
|
success: CheckCircleFilled,
|
|
|
|
warning: ExclamationCircleFilled,
|
|
|
|
error: CloseCircleFilled,
|
|
|
|
validating: LoadingOutlined,
|
|
|
|
};
|
|
|
|
const FormItemInput = defineComponent({
|
|
|
|
slots: ['help', 'extra', 'errors'],
|
|
|
|
inheritAttrs: false,
|
|
|
|
props: [
|
|
|
|
'prefixCls',
|
|
|
|
'errors',
|
|
|
|
'hasFeedback',
|
|
|
|
'onDomErrorVisibleChange',
|
|
|
|
'wrapperCol',
|
|
|
|
'help',
|
|
|
|
'extra',
|
|
|
|
'status',
|
|
|
|
],
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const formContext = useInjectForm();
|
|
|
|
const { wrapperCol: contextWrapperCol } = formContext;
|
|
|
|
|
|
|
|
// Pass to sub FormItem should not with col info
|
|
|
|
const subFormContext = { ...formContext };
|
|
|
|
delete subFormContext.labelCol;
|
|
|
|
delete subFormContext.wrapperCol;
|
|
|
|
useProvideForm(subFormContext);
|
|
|
|
useProvideFormItemPrefix({
|
|
|
|
prefixCls: computed(() => props.prefixCls),
|
|
|
|
status: computed(() => props.status),
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
wrapperCol,
|
|
|
|
help = slots.help?.(),
|
|
|
|
errors = slots.errors?.(),
|
|
|
|
hasFeedback,
|
2022-03-17 13:53:14 +00:00
|
|
|
status,
|
2021-06-07 09:35:03 +00:00
|
|
|
extra = slots.extra?.(),
|
|
|
|
} = props;
|
|
|
|
const baseClassName = `${prefixCls}-item`;
|
|
|
|
|
|
|
|
const mergedWrapperCol: ColProps & HTMLAttributes =
|
|
|
|
wrapperCol || contextWrapperCol?.value || {};
|
|
|
|
|
|
|
|
const className = classNames(`${baseClassName}-control`, mergedWrapperCol.class);
|
|
|
|
|
|
|
|
// Should provides additional icon if `hasFeedback`
|
2022-03-17 13:53:14 +00:00
|
|
|
const IconNode = status && iconMap[status];
|
2021-06-07 09:35:03 +00:00
|
|
|
|
|
|
|
return (
|
2021-09-25 08:51:32 +00:00
|
|
|
<Col
|
|
|
|
{...mergedWrapperCol}
|
|
|
|
class={className}
|
|
|
|
v-slots={{
|
|
|
|
default: () => (
|
|
|
|
<>
|
|
|
|
<div class={`${baseClassName}-control-input`}>
|
|
|
|
<div class={`${baseClassName}-control-input-content`}>{slots.default?.()}</div>
|
|
|
|
{hasFeedback && IconNode ? (
|
|
|
|
<span class={`${baseClassName}-children-icon`}>
|
|
|
|
<IconNode />
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<ErrorList
|
|
|
|
errors={errors}
|
|
|
|
help={help}
|
2022-03-12 01:56:32 +00:00
|
|
|
class={`${baseClassName}-explain-connected`}
|
2021-09-25 08:51:32 +00:00
|
|
|
/>
|
|
|
|
{extra ? <div class={`${baseClassName}-extra`}>{extra}</div> : null}
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
></Col>
|
2021-06-07 09:35:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FormItemInput;
|