From 38b18eef2d8ea9a4399d90634c32786415ca813f Mon Sep 17 00:00:00 2001 From: bang88 Date: Mon, 27 Jun 2016 00:18:52 +0700 Subject: [PATCH] refactor(Tooltip): rewrite Tooltip --- components/index.tsx | 2 ++ components/tooltip/index.tsx | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/index.tsx b/components/index.tsx index dc82ac2f254b..a1e028d71b29 100644 --- a/components/index.tsx +++ b/components/index.tsx @@ -7,3 +7,5 @@ export { default as Tag } from './Tag'; export { default as TimePicker } from './time-picker'; export { default as Timeline } from './timeline'; + +export { default as Tooltip } from './tooltip'; diff --git a/components/tooltip/index.tsx b/components/tooltip/index.tsx index 249ca1b2a75d..52c31e4d5dda 100644 --- a/components/tooltip/index.tsx +++ b/components/tooltip/index.tsx @@ -1,19 +1,30 @@ -import React, { cloneElement } from 'react'; +import * as React from 'react'; +const { cloneElement } = React; import RcTooltip from 'rc-tooltip'; import getPlacements from '../popover/placements'; const placements = getPlacements({ verticalArrowShift: 8, }); +type PopoverPlacement = 'top' | 'left' | 'right' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom' -export default class Tooltip extends React.Component { +// Tooltip +export interface TooltipProps { + /** 气泡框位置,可选 `top` `left` `right` `bottom` `topLeft` `topRight` `bottomLeft` `bottomRight` `leftTop` `leftBottom` `rightTop` `rightBottom`*/ + placement?: PopoverPlacement, + /** 提示文字*/ + title?: string | React.ReactNode, + + style?: React.CSSProperties +} +export default class Tooltip extends React.Component { static defaultProps = { prefixCls: 'ant-tooltip', placement: 'top', transitionName: 'zoom-big', mouseEnterDelay: 0.1, mouseLeaveDelay: 0.1, - onVisibleChange() {}, + onVisibleChange() { }, } constructor(props) { @@ -86,7 +97,7 @@ export default class Tooltip extends React.Component { ref="tooltip" {...this.props} onVisibleChange={this.onVisibleChange} - > + > {visible ? cloneElement(children, { className: childrenCls }) : children} );