You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.8 KiB

import * as React from 'react';
import { cloneElement } from 'react';
import { polyfill } from 'react-lifecycles-compat';
import RcTooltip from 'rc-tooltip';
import classNames from 'classnames';
import getPlacements, { AdjustOverflow, PlacementsConfig } from './placements';
import Button from '../button/index';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export { AdjustOverflow, PlacementsConfig };
export type TooltipPlacement =
| 'top'
| 'left'
| 'right'
| 'bottom'
| 'topLeft'
| 'topRight'
| 'bottomLeft'
| 'bottomRight'
| 'leftTop'
| 'leftBottom'
| 'rightTop'
| 'rightBottom';
10 years ago
export type TooltipTrigger = 'hover' | 'focus' | 'click' | 'contextMenu';
// 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 {
prefixCls?: string;
overlayClassName?: string;
style?: React.CSSProperties;
overlayStyle?: React.CSSProperties;
placement?: TooltipPlacement;
builtinPlacements?: Object;
defaultVisible?: boolean;
visible?: boolean;
onVisibleChange?: (visible: boolean) => void;
mouseEnterDelay?: number;
mouseLeaveDelay?: number;
transitionName?: string;
trigger?: TooltipTrigger;
openClassName?: string;
arrowPointAtCenter?: boolean;
autoAdjustOverflow?: boolean | AdjustOverflow;
// getTooltipContainer had been rename to getPopupContainer
getTooltipContainer?: (triggerNode: Element) => HTMLElement;
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
children?: React.ReactNode;
// align is a more higher api
align?: TooltipAlignConfig;
}
export type RenderFunction = () => React.ReactNode;
export interface TooltipProps extends AbstractTooltipProps {
title?: React.ReactNode | RenderFunction;
overlay?: React.ReactNode | RenderFunction;
9 years ago
}
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 };
};
class Tooltip extends React.Component<TooltipProps, any> {
static defaultProps = {
placement: 'top' as TooltipPlacement,
transitionName: 'zoom-big-fast',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1,
arrowPointAtCenter: false,
autoAdjustOverflow: true,