ant-design/components/_util/convertToTooltipProps.ts
𝑾𝒖𝒙𝒉 d38aea0138
feat(float-button): support TooltipProps (#53138)
* feat(float-button): support Tooltips props

(cherry picked from commit fb3d131beea52655e780e462eae08662b08095db)

* chore: update demo

(cherry picked from commit 36b39f5e7bf8ace89c705e7ece22549bc623f9e3)

* chore: logic reuse

* chore: update demo snap

* test: add unit test

* chore: edge case

* chore: add warn

* docs: update docs

* revert

* fix: handle undefined and null in convertToTooltipProps
2025-03-13 11:02:06 +08:00

21 lines
481 B
TypeScript

import type { ReactNode } from 'react';
import { isValidElement } from 'react';
import type { TooltipProps } from '../tooltip';
function convertToTooltipProps<P extends TooltipProps>(tooltip: P | ReactNode): P | null {
// isNil
if (tooltip === undefined || tooltip === null) {
return null;
}
if (typeof tooltip === 'object' && !isValidElement(tooltip)) {
return tooltip as P;
}
return {
title: tooltip,
} as P;
}
export default convertToTooltipProps;