From df56cdeddeab21df282dcf51b5333761151df9b4 Mon Sep 17 00:00:00 2001 From: quirkyshop Date: Wed, 17 Feb 2021 22:09:53 +0800 Subject: [PATCH] feat: add feedback layout --- packages/antd/docs/components/FormItem.md | 85 +++++++++++++++++++++-- packages/antd/src/form-item/index.tsx | 24 ++++--- packages/antd/src/form-item/style.less | 10 ++- 3 files changed, 103 insertions(+), 16 deletions(-) diff --git a/packages/antd/docs/components/FormItem.md b/packages/antd/docs/components/FormItem.md index 9bfa638656e..b0ebe4a266d 100644 --- a/packages/antd/docs/components/FormItem.md +++ b/packages/antd/docs/components/FormItem.md @@ -159,6 +159,25 @@ export default () => { return ( + + + { title="默认" x-decorator="FormItem" x-component="Input" - /> + /> { /> , }} /> + + + + + + + + + + + + { onFieldChange('size', ['value'], (field, form) => { form.setFieldState('sizeWrap.*', (state) => { - if (!state.props['x-decorator-props']) { - state.props['x-decorator-props'] = {} + if (state.decorator[1]) { + state.decorator[1].size = field.value } - state.props['x-decorator-props'].size = field.value }) }) }, diff --git a/packages/antd/src/form-item/index.tsx b/packages/antd/src/form-item/index.tsx index 6de51461194..80cc8ff6d98 100644 --- a/packages/antd/src/form-item/index.tsx +++ b/packages/antd/src/form-item/index.tsx @@ -4,7 +4,7 @@ import { usePrefixCls } from '../__builtins__' import { isVoidField } from '@formily/core' import { connect, mapProps } from '@formily/react' import { useFormLayout, useFormShallowLayout } from '../form-layout' -import { Tooltip } from 'antd' +import { Tooltip, Popover } from 'antd' import { QuestionCircleOutlined } from '@ant-design/icons' export interface IFormItemProps { @@ -113,12 +113,20 @@ export const BaseItem: React.FC = (props) => { enableCol = true } + const formatChildren = (feedbackLayout === 'popover' && feedbackText) ? ( + {children} + ) : children; + const prefixCls = usePrefixCls('formily-form-item', props) return (
= (props) => { [props.className]: !!props.className, })} > -
= (props) => { )} - {colon && {':'}} -
+ { label && {colon ? ':' : ''}} +
}
= (props) => { [`${prefixCls}-control-content-component-has-feedback-icon`]: !!feedbackIcon, })} > - {children} + {formatChildren} {feedbackIcon && (
{feedbackIcon} @@ -181,7 +189,7 @@ export const BaseItem: React.FC = (props) => {
{addonAfter}
)}
- {!!feedbackText && ( + {(!!feedbackText && feedbackLayout !== 'popover') && (
{feedbackText}
)} {extra &&
{extra}
} @@ -219,7 +227,7 @@ export const FormItem: ComposeFormItem = connect( feedbackStatus: field.validateStatus === 'validating' ? 'pending' - : field.validateStatus, + : field.decorator[1]?.feedbackStatus || field.validateStatus, } }, (props, field) => { @@ -235,7 +243,7 @@ export const FormItem: ComposeFormItem = connect( return { asterisk, } - } + }, ) ) diff --git a/packages/antd/src/form-item/style.less b/packages/antd/src/form-item/style.less index de830b9816d..6145f51e3a8 100644 --- a/packages/antd/src/form-item/style.less +++ b/packages/antd/src/form-item/style.less @@ -4,7 +4,7 @@ .@{form-item-cls} { display: flex; - margin-bottom: 24px; + margin-bottom: 16px; } .@{form-item-cls}-label { @@ -357,7 +357,7 @@ .@{form-item-cls}-help, .@{form-item-cls}-extra { clear: both; - min-height: 24px; + min-height: 16px; color: rgba(0, 0, 0, 0.45); font-size: 14px; line-height: 1.5715; @@ -448,4 +448,10 @@ .@{form-item-cls}-help { color: #faad14; } +} + +.@{form-item-cls}-feedback-layout-terse { + &.@{form-item-cls}-feedback-status-valid { + margin-bottom: 0; + } } \ No newline at end of file