File size: 481 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;