mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 23:18:36 +08:00
23 lines
689 B
TypeScript
23 lines
689 B
TypeScript
|
import { isValidElement, useMemo } from 'react';
|
||
|
import type { TooltipProps } from '../../tooltip';
|
||
|
|
||
|
const useTooltipProps = (
|
||
|
tooltip: React.ReactNode | TooltipProps,
|
||
|
editConfigText: React.ReactNode,
|
||
|
children: React.ReactNode,
|
||
|
) =>
|
||
|
useMemo(() => {
|
||
|
if (tooltip === true) {
|
||
|
return { title: editConfigText ?? children };
|
||
|
}
|
||
|
if (isValidElement(tooltip)) {
|
||
|
return { title: tooltip };
|
||
|
}
|
||
|
if (typeof tooltip === 'object') {
|
||
|
return { title: editConfigText ?? children, ...tooltip };
|
||
|
}
|
||
|
return { title: tooltip };
|
||
|
}, [typeof tooltip === 'object' ? JSON.stringify(tooltip) : tooltip, editConfigText, children]);
|
||
|
|
||
|
export default useTooltipProps;
|