Skip to content

Commit

Permalink
refactor: fix compiling (ant-design#44616)
Browse files Browse the repository at this point in the history
* refactor: fix compiling

* perf: code logic update
  • Loading branch information
MadCcc authored Sep 4, 2023
1 parent 85dc67f commit b284648
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
32 changes: 15 additions & 17 deletions components/modal/components/ConfirmCancelBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ const ConfirmCancelBtn: FC = () => {
onCancel,
onConfirm,
} = useContext(ModalContext);
return (
mergedOkCancel && (
<ActionButton
isSilent={isSilent}
actionFn={onCancel}
close={(...args: any[]) => {
close?.(...args);
onConfirm?.(false);
}}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{cancelTextLocale}
</ActionButton>
)
);
return mergedOkCancel ? (
<ActionButton
isSilent={isSilent}
actionFn={onCancel}
close={(...args: any[]) => {
close?.(...args);
onConfirm?.(false);
}}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{cancelTextLocale}
</ActionButton>
) : null;
};

export default ConfirmCancelBtn;
36 changes: 17 additions & 19 deletions components/modal/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,23 @@ export const Footer: React.FC<

const btnCtxValueMemo = React.useMemo(() => btnCtxValue, [...Object.values(btnCtxValue)]);

const footerOriginNode = (
<>
<NormalCancelBtn />
<NormalOkBtn />
</>
);

return footer === undefined || typeof footer === 'function' ? (
<DisabledContextProvider disabled={false}>
let footerNode;
if (typeof footer === 'function' || typeof footer === 'undefined') {
footerNode = (
<ModalContextProvider value={btnCtxValueMemo}>
{typeof footer === 'function'
? footer(footerOriginNode, {
OkBtn: NormalOkBtn,
CancelBtn: NormalCancelBtn,
})
: footerOriginNode}
<NormalCancelBtn />
<NormalOkBtn />
</ModalContextProvider>
</DisabledContextProvider>
) : (
footer
);
);
if (typeof footer === 'function') {
footerNode = footer(footerNode, {
OkBtn: NormalOkBtn,
CancelBtn: NormalCancelBtn,
});
}
} else {
footerNode = footer;
}

return <DisabledContextProvider disabled={false}>{footerNode}</DisabledContextProvider>;
};

0 comments on commit b284648

Please sign in to comment.