Skip to content

Commit

Permalink
fix(form): fix FormList size=small, icon is default size error
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jul 12, 2024
1 parent 4fb181c commit d797fa7
Show file tree
Hide file tree
Showing 7 changed files with 1,249 additions and 1,052 deletions.
5 changes: 3 additions & 2 deletions packages/form/src/components/Group/demos/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
ProFormSelect,
ProFormText,
} from '@ant-design/pro-components';
import { ConfigProvider } from 'antd';
import { useState } from 'react';

const Demo = () => {
const [position, setPosition] = useState<'bottom' | 'top'>('bottom');
return (
<>
<ConfigProvider componentSize="small">
<ProFormRadio.Group
fieldProps={{
value: position,
Expand Down Expand Up @@ -119,7 +120,7 @@ const Demo = () => {
</ProFormGroup>
</ProFormList>
</ProForm>
</>
</ConfigProvider>
);
};

Expand Down
67 changes: 49 additions & 18 deletions packages/form/src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { CopyOutlined, DeleteOutlined } from '@ant-design/icons';
import {
CopyOutlined,
DeleteOutlined,
LoadingOutlined,
} from '@ant-design/icons';
import { ProProvider } from '@ant-design/pro-provider';
import { SearchTransformKeyFn } from '@ant-design/pro-utils';
import type { ButtonProps, FormInstance } from 'antd';
import { Spin, Tooltip } from 'antd';
import { ConfigProvider, Tooltip } from 'antd';
import type {
FormListFieldData,
FormListOperation,
FormListProps,
} from 'antd/lib/form/FormList';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import set from 'rc-util/lib/utils/set';
import type { CSSProperties, ReactNode } from 'react';
Expand Down Expand Up @@ -312,6 +317,7 @@ const ProFormListItem: React.FC<
...rest
} = props;
const { hashId } = useContext(ProProvider);
const { componentSize } = ConfigProvider.useConfig();
const listContext = useContext(FormListContext);
const unmountedRef = useRef(false);

Expand Down Expand Up @@ -379,9 +385,14 @@ const ProFormListItem: React.FC<
const { Icon = CopyOutlined, tooltipText } = copyIconProps as IconConfig;
return (
<Tooltip title={tooltipText} key="copy">
<Spin spinning={loadingCopy}>
{loadingCopy ? (
<LoadingOutlined />
) : (
<Icon
className={`${prefixCls}-action-icon action-copy ${hashId}`.trim()}
className={classNames(
`${prefixCls}-action-icon action-copy`,
hashId,
)}
onClick={async () => {
setLoadingCopy(true);
const row = formInstance?.getFieldValue(
Expand All @@ -393,7 +404,7 @@ const ProFormListItem: React.FC<
setLoadingCopy(false);
}}
/>
</Spin>
)}
</Tooltip>
);
}, [
Expand All @@ -416,9 +427,14 @@ const ProFormListItem: React.FC<
const { Icon = DeleteOutlined, tooltipText } = deleteIconProps!;
return (
<Tooltip title={tooltipText} key="delete">
<Spin spinning={loadingRemove}>
{loadingRemove ? (
<LoadingOutlined />
) : (
<Icon
className={`${prefixCls}-action-icon action-remove ${hashId}`.trim()}
className={classNames(
`${prefixCls}-action-icon action-remove`,
hashId,
)}
onClick={async () => {
setLoadingRemove(true);
await action.remove(field.name);
Expand All @@ -427,7 +443,7 @@ const ProFormListItem: React.FC<
}
}}
/>
</Spin>
)}
</Tooltip>
);
}, [
Expand All @@ -454,7 +470,17 @@ const ProFormListItem: React.FC<

const dom =
actions.length > 0 && mode !== 'read' ? (
<div className={`${prefixCls}-action ${hashId}`.trim()}>{actions}</div>
<div
className={classNames(
`${prefixCls}-action`,
{
[`${prefixCls}-action-small`]: componentSize === 'small',
},
hashId,
)}
>
{actions}
</div>
) : null;

const options = {
Expand All @@ -480,9 +506,11 @@ const ProFormListItem: React.FC<
{
listDom: (
<div
className={`${prefixCls}-container ${containerClassName || ''} ${
hashId || ''
}`.trim()}
className={classNames(
`${prefixCls}-container`,
containerClassName,
hashId,
)}
style={{
width: grid ? '100%' : undefined,
...containerStyle,
Expand All @@ -496,18 +524,21 @@ const ProFormListItem: React.FC<
options,
) || (
<div
className={`${prefixCls}-item ${hashId}
${alwaysShowItemLabel === undefined && `${prefixCls}-item-default`}
${alwaysShowItemLabel ? `${prefixCls}-item-show-label` : ''}`}
className={classNames(`${prefixCls}-item`, hashId, {
[`${prefixCls}-item-default`]: alwaysShowItemLabel === undefined,
[`${prefixCls}-item-show-label`]: alwaysShowItemLabel,
})}
style={{
display: 'flex',
alignItems: 'flex-end',
}}
>
<div
className={`${prefixCls}-container ${
containerClassName || ''
} ${hashId}`.trim()}
className={classNames(
`${prefixCls}-container`,
containerClassName,
hashId,
)}
style={{
width: grid ? '100%' : undefined,
...containerStyle,
Expand Down
8 changes: 6 additions & 2 deletions packages/form/src/components/List/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ const genProStyle: GenerateStyle<ProToken> = (token) => {
},
'&-action': {
display: 'flex',
height: '32px',
height: token.controlHeight,
marginBlockEnd: token.marginLG,
lineHeight: '32px',
lineHeight: token.controlHeight,
'&-small': {
height: token.controlHeightSM,
lineHeight: token.controlHeightSM,
},
},
'&-action-icon': {
marginInlineStart: 8,
Expand Down
Loading

0 comments on commit d797fa7

Please sign in to comment.