mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +08:00

* 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
21 lines
481 B
TypeScript
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;
|