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.

229 lines
6.9 KiB

import * as React from 'react';
import { cloneElement } from 'react';
import RcTooltip from 'rc-tooltip';
import classNames from 'classnames';
import getPlacements, { AdjustOverflow, PlacementsConfig } from './placements';
import Button from '../button/index';
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';
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: Element) => HTMLElement;
children?: React.ReactNode;
}
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 };
};
9 years ago
export default class Tooltip extends React.Component<TooltipProps, any> {
static defaultProps = {
prefixCls: 'ant-tooltip',
placement: 'top' as TooltipPlacement,
transitionName: 'zoom-big-fast',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1,
arrowPointAtCenter: false,
autoAdjustOverflow: true,
};
private tooltip: typeof RcTooltip;
constructor(props: TooltipProps) {
super(props);
this.state = {
visible: !!props.visible || !!props.defaultVisible,
};
}
componentWillReceiveProps(nextProps: TooltipProps) {
if ('visible' in nextProps) {
this.setState({ visible: nextProps.visible });
}
}
onVisibleChange = (visible: boolean) => {
const { onVisibleChange } = this.props;
if (!('visible' in this.props)) {
this.setState({ visible: this.isNoTitle() ? false : visible });
}
if (onVisibleChange && !this.isNoTitle()) {