Skip to content

Commit

Permalink
fix(card): loading属性增加TNode支持 (#3051)
Browse files Browse the repository at this point in the history
* fix(card): loading属性增加TNode支持

fix #2997

* fix(card): 在不使用loading属性的时候,去掉loading parent
  • Loading branch information
huangchen1031 authored Aug 31, 2024
1 parent d12c4e3 commit 3f9a77a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,31 @@ const Card = forwardRef<HTMLDivElement, CardProps>((props, ref) => {
);

const card = (
<div ref={ref} className={cardClass}>
<>
{showHeader ? renderHeader() : null}
{renderCover}
{renderChildren}
{renderFooter}
</div>
</>
);

return loading ? (
<Loading {...loadingProps} style={style}>
{card}
</Loading>
) : (
React.cloneElement(card, { style })
let childrenNode: React.ReactNode = null;
if (!Reflect.has(props, 'loading')) {
childrenNode = React.cloneElement(card, { style });
} else if (React.isValidElement(loading)) {
childrenNode = React.cloneElement(loading, null, card);
} else {
childrenNode = (
<Loading {...loadingProps} loading={!!loading}>
{card}
</Loading>
);
}

return (
<div ref={ref} className={cardClass} style={style}>
{childrenNode}
</div>
);
});

Expand Down

0 comments on commit 3f9a77a

Please sign in to comment.