Browse Source

Improve Tooltip type definitions

pull/8252/head
Wei Zhu 7 years ago
parent
commit
ac7212eba8
  1. 21
      components/tooltip/index.tsx
  2. 2
      components/tooltip/placements.tsx

21
components/tooltip/index.tsx

@ -3,6 +3,7 @@ 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 };
@ -40,9 +41,9 @@ export interface TooltipProps extends AbstractTooltipProps {
overlay?: React.ReactNode | RenderFunction;
}
const splitObject = (obj, keys) => {
const picked = {};
const omited = { ...obj };
const splitObject = (obj: any, keys: string[]) => {
const picked: any = {};
const omited: any = { ...obj };
keys.forEach(key => {
if (obj && key in obj) {
picked[key] = obj[key];
@ -63,7 +64,7 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
autoAdjustOverflow: true,
};
private tooltip: any;
private tooltip: typeof RcTooltip;
constructor(props: TooltipProps) {
super(props);
@ -79,7 +80,7 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
}
}
onVisibleChange = (visible) => {
onVisibleChange = (visible: boolean) => {
const { onVisibleChange } = this.props;
if (!('visible' in this.props)) {
this.setState({ visible: this.isNoTitle() ? false : visible });
@ -116,8 +117,8 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
// 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
getDisabledCompatibleChildren(element) {
if ((element.type.__ANT_BUTTON || element.type === 'button') &&
getDisabledCompatibleChildren(element: React.ReactElement<any>) {
if (((element.type as typeof Button).__ANT_BUTTON || element.type === 'button') &&
element.props.disabled && this.isHoverTrigger()) {
// Pick some layout related style properties up to span
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
@ -153,8 +154,8 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
}
// 动态设置动画点
onPopupAlign = (domNode, align) => {
const placements = this.getPlacements();
onPopupAlign = (domNode: HTMLElement, align: any) => {
const placements: any = this.getPlacements();
// 当前返回的位置
const placement = Object.keys(placements).filter(
key => (
@ -184,7 +185,7 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
domNode.style.transformOrigin = `${transformOrigin.left} ${transformOrigin.top}`;
}
saveTooltip = (node) => {
saveTooltip = (node: typeof RcTooltip) => {
this.tooltip = node;
}

2
components/tooltip/placements.tsx

@ -37,7 +37,7 @@ export function getOverflowOptions(autoAdjustOverflow: any) {
export default function getPlacements(config: PlacementsConfig = {}) {
const { arrowWidth = 5, horizontalArrowShift = 16, verticalArrowShift = 12, autoAdjustOverflow = true } = config;
const placementMap = {
const placementMap: any = {
left: {
points: ['cr', 'cl'],
offset: [-4, 0],

Loading…
Cancel
Save