mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-16 05:58:26 +02:00

* 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>
29 lines
792 B
TypeScript
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;
|
|
}
|