|
|
|
import * as React from 'react';
|
|
|
|
import RcTooltip from 'rc-tooltip';
|
|
|
|
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
|
|
|
import { TooltipProps as RcTooltipProps } from 'rc-tooltip/lib/Tooltip';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { placements as Placements } from 'rc-tooltip/lib/placements';
|
|
|
|
import getPlacements, { AdjustOverflow, PlacementsConfig } from './placements';
|
|
|
|
import { cloneElement, isValidElement } from '../_util/reactNode';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import { PresetColorType, PresetColorTypes } from '../_util/colors';
|
|
|
|
import { LiteralUnion } from '../_util/type';
|
|
|
|
import { getTransitionName } from '../_util/motion';
|
|
|
|
|
|
|
|
export { AdjustOverflow, PlacementsConfig };
|
|
|
|
|
|
|
|
export type TooltipPlacement =
|
|
|
|
| 'top'
|
|
|
|
| 'left'
|
|
|
|
| 'right'
|
|
|
|
| 'bottom'
|
|
|
|
| 'topLeft'
|
|
|
|
| 'topRight'
|
|
|
|
| 'bottomLeft'
|
|
|
|
| 'bottomRight'
|
|
|
|
| 'leftTop'
|
|
|
|
| 'leftBottom'
|
|
|
|
| 'rightTop'
|
|
|
|
| 'rightBottom';
|
|
|
|
|
|
|
|
// https://github.com/react-component/tooltip
|
|
|
|
// https://github.com/yiminghe/dom-align
|
|
|
|
export interface TooltipAlignConfig {
|
|
|
|
points?: [string, string];
|
|
|
|
offset?: [number | string, number | string];
|
|
|
|
targetOffset?: [number | string, number | string];
|
|
|
|
overflow?: { adjustX: boolean; adjustY: boolean };
|
|
|
|
useCssRight?: boolean;
|
|
|
|
useCssBottom?: boolean;
|
|
|
|
useCssTransform?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AbstractTooltipProps extends Partial<Omit<RcTooltipProps, 'children'>> {
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
className?: string;
|
|
|
|
color?: LiteralUnion<PresetColorType, string>;
|
|
|
|
placement?: TooltipPlacement;
|
|
|
|
builtinPlacements?: typeof Placements;
|
|
|
|
openClassName?: string;
|
|
|
|
arrowPointAtCenter?: boolean;
|
|
|
|
autoAdjustOverflow?: boolean | AdjustOverflow;
|
|
|
|
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type RenderFunction = () => React.ReactNode;
|
|
|
|
|
|
|
|
export interface TooltipPropsWithOverlay extends AbstractTooltipProps {
|
|
|
|
title?: React.ReactNode | RenderFunction;
|
|
|
|
overlay: React.ReactNode | RenderFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TooltipPropsWithTitle extends AbstractTooltipProps {
|
|
|
|
title: React.ReactNode | RenderFunction;
|
|
|
|
overlay?: React.ReactNode | RenderFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
|
|
|
|
|
|
|
|
const splitObject = (obj: any, keys: string[]) => {
|
|
|
|
const picked: any = {};
|
|
|
|
const omitted: any = { ...obj };
|
|
|
|
keys.forEach(key => {
|
|
|
|
if (obj && key in obj) {
|
|
|
|
picked[key] = obj[key];
|
|
|
|
delete omitted[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return { picked, omitted };
|
|
|
|
};
|
|
|
|
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
|
|
|
|
|
|
|
// Fix Tooltip won't hide at disabled button
|
|
|
|
// mouse events don't trigger at disabled button in Chrome
|
|
|
|
// https://github.com/react-component/tooltip/issues/18
|
|
|
|
function getDisabledCompatibleChildren(element: React.ReactElement<any>, prefixCls: string) {
|
|
|