ant-design/components/_util/reactNode.ts
lijianan cf51b5f34d
feat: CP support collapse expandIcon (#47473)
* feat: CP support Avatar icon

* fix: fix

* fix: fix

* test: fix test case

* fix: fix

* fix: fix type

* Update avatar.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update avatar.tsx

Signed-off-by: lijianan <574980606@qq.com>

---------

Signed-off-by: lijianan <574980606@qq.com>
2024-02-20 14:02:43 +08:00

29 lines
792 B
TypeScript

import * as React from 'react';
import type { AnyObject } from './type';
export const { isValidElement } = React;
export function isFragment(child: any): boolean {
return child && isValidElement(child) && child.type === React.Fragment;
}
type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | void);
export function replaceElement<P>(
element: React.ReactNode,
replacement: React.ReactNode,
props?: RenderProps,
) {
if (!isValidElement<P>(element)) {
return replacement;
}
return React.cloneElement<P>(
element,
typeof props === 'function' ? props(element.props || {}) : props,
);
}
export function cloneElement<P>(element: React.ReactNode, props?: RenderProps) {
return replaceElement<P>(element, element, props) as React.ReactElement;
}