mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 03:14:07 +08:00
chore(form): code style optimization (#43793)
* chore(form): code style optimization * fix: add type CSSMotionProps * Update ErrorList.tsx * Update FormItemLabel.tsx * Update FormItemLabel.tsx
This commit is contained in:
parent
8f7630273c
commit
f78f7bfef9
@ -1,4 +1,5 @@
|
||||
import classNames from 'classnames';
|
||||
import type { CSSMotionProps } from 'rc-motion';
|
||||
import CSSMotion, { CSSMotionList } from 'rc-motion';
|
||||
import * as React from 'react';
|
||||
import { useMemo } from 'react';
|
||||
@ -40,7 +41,7 @@ export interface ErrorListProps {
|
||||
onVisibleChanged?: (visible: boolean) => void;
|
||||
}
|
||||
|
||||
export default function ErrorList({
|
||||
const ErrorList: React.FC<ErrorListProps> = ({
|
||||
help,
|
||||
helpStatus,
|
||||
errors = EMPTY_LIST,
|
||||
@ -48,14 +49,14 @@ export default function ErrorList({
|
||||
className: rootClassName,
|
||||
fieldId,
|
||||
onVisibleChanged,
|
||||
}: ErrorListProps) {
|
||||
}) => {
|
||||
const { prefixCls } = React.useContext(FormItemPrefixContext);
|
||||
|
||||
const baseClassName = `${prefixCls}-item-explain`;
|
||||
|
||||
const [, hashId] = useStyle(prefixCls);
|
||||
|
||||
const collapseMotion = useMemo(() => initCollapseMotion(prefixCls), [prefixCls]);
|
||||
const collapseMotion: CSSMotionProps = useMemo(() => initCollapseMotion(prefixCls), [prefixCls]);
|
||||
|
||||
// We have to debounce here again since somewhere use ErrorList directly still need no shaking
|
||||
// ref: https://github.com/ant-design/ant-design/issues/36336
|
||||
@ -131,4 +132,6 @@ export default function ErrorList({
|
||||
}}
|
||||
</CSSMotion>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default ErrorList;
|
||||
|
@ -63,13 +63,13 @@ const FormItemInput: React.FC<FormItemInputProps & FormItemInputMiscProps> = (pr
|
||||
delete subFormContext.labelCol;
|
||||
delete subFormContext.wrapperCol;
|
||||
|
||||
const inputDom = (
|
||||
const inputDom: React.ReactNode = (
|
||||
<div className={`${baseClassName}-control-input`}>
|
||||
<div className={`${baseClassName}-control-input-content`}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
const formItemContext = React.useMemo(() => ({ prefixCls, status }), [prefixCls, status]);
|
||||
const errorListDom =
|
||||
const errorListDom: React.ReactNode =
|
||||
marginBottom !== null || errors.length || warnings.length ? (
|
||||
<div style={{ display: 'flex', flexWrap: 'nowrap' }}>
|
||||
<FormItemPrefixContext.Provider value={formItemContext}>
|
||||
@ -95,13 +95,13 @@ const FormItemInput: React.FC<FormItemInputProps & FormItemInputMiscProps> = (pr
|
||||
|
||||
// If extra = 0, && will goes wrong
|
||||
// 0&&error -> 0
|
||||
const extraDom = extra ? (
|
||||
const extraDom: React.ReactNode = extra ? (
|
||||
<div {...extraProps} className={`${baseClassName}-extra`}>
|
||||
{extra}
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
const dom =
|
||||
const dom: React.ReactNode =
|
||||
formItemRender && formItemRender.mark === 'pro_table_render' && formItemRender.render ? (
|
||||
formItemRender.render(props, { input: inputDom, errorList: errorListDom, extra: extraDom })
|
||||
) : (
|
||||
|
@ -84,7 +84,7 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required?: boolean; prefixC
|
||||
},
|
||||
);
|
||||
|
||||
let labelChildren = label;
|
||||
let labelChildren: React.ReactNode = label;
|
||||
|
||||
// Keep label is original where there should have no colon
|
||||
const computedColon = colon === true || (contextColon !== false && colon !== false);
|
||||
@ -100,7 +100,7 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required?: boolean; prefixC
|
||||
|
||||
if (tooltipProps) {
|
||||
const { icon = <QuestionCircleOutlined />, ...restTooltipProps } = tooltipProps;
|
||||
const tooltipNode = (
|
||||
const tooltipNode: React.ReactNode = (
|
||||
<Tooltip {...restTooltipProps}>
|
||||
{React.cloneElement(icon, { className: `${prefixCls}-item-tooltip`, title: '' })}
|
||||
</Tooltip>
|
||||
|
@ -2,7 +2,7 @@ import { FormProvider as RcFormProvider } from 'rc-field-form';
|
||||
import type { FormProviderProps as RcFormProviderProps } from 'rc-field-form/lib/FormContext';
|
||||
import type { Meta } from 'rc-field-form/lib/interface';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import type { FC, PropsWithChildren, ReactNode } from 'react';
|
||||
import type { PropsWithChildren, ReactNode } from 'react';
|
||||
import * as React from 'react';
|
||||
import { useContext, useMemo } from 'react';
|
||||
import type { ColProps } from '../grid/col';
|
||||
@ -70,7 +70,7 @@ export type NoFormStyleProps = PropsWithChildren<{
|
||||
override?: boolean;
|
||||
}>;
|
||||
|
||||
export const NoFormStyle: FC<NoFormStyleProps> = ({ children, status, override }) => {
|
||||
export const NoFormStyle: React.FC<NoFormStyleProps> = ({ children, status, override }) => {
|
||||
const formItemInputContext = useContext(FormItemInputContext);
|
||||
|
||||
const newFormItemInputContext = useMemo(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user