UNPKG

4.28 kBTypeScriptView Raw
1/*
2 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20
21import { AbstractPureComponent2, Classes } from "../../common";
22import { DISPLAYNAME_PREFIX, IntentProps } from "../../common/props";
23// eslint-disable-next-line import/no-cycle
24import { Popover, PopoverInteractionKind } from "../popover/popover";
25import { IPopoverSharedProps } from "../popover/popoverSharedProps";
26
27// eslint-disable-next-line deprecation/deprecation
28export type TooltipProps = ITooltipProps;
29/** @deprecated use TooltipProps */
30export interface ITooltipProps extends IPopoverSharedProps, IntentProps {
31 /**
32 * The content that will be displayed inside of the tooltip.
33 */
34 content: JSX.Element | string;
35
36 /**
37 * The amount of time in milliseconds the tooltip should remain open after
38 * the user hovers off the trigger. The timer is canceled if the user mouses
39 * over the target before it expires.
40 *
41 * @default 0
42 */
43 hoverCloseDelay?: number;
44
45 /**
46 * The amount of time in milliseconds the tooltip should wait before opening
47 * after the user hovers over the trigger. The timer is canceled if the user
48 * mouses away from the target before it expires.
49 *
50 * @default 100
51 */
52 hoverOpenDelay?: number;
53
54 /**
55 * The kind of hover interaction that triggers the display of the tooltip.
56 * Tooltips do not support click interactions.
57 *
58 * @default PopoverInteractionKind.HOVER_TARGET_ONLY
59 */
60 interactionKind?: typeof PopoverInteractionKind.HOVER | typeof PopoverInteractionKind.HOVER_TARGET_ONLY;
61
62 /**
63 * Indicates how long (in milliseconds) the tooltip's appear/disappear
64 * transition takes. This is used by React `CSSTransition` to know when a
65 * transition completes and must match the duration of the animation in CSS.
66 * Only set this prop if you override Blueprint's default transitions with
67 * new transitions of a different length.
68 *
69 * @default 100
70 */
71 transitionDuration?: number;
72}
73
74/** @deprecated use { Tooltip2 } from "@blueprintjs/popover2" */
75@polyfill
76export class Tooltip extends AbstractPureComponent2<TooltipProps> {
77 public static displayName = `${DISPLAYNAME_PREFIX}.Tooltip`;
78
79 public static defaultProps: Partial<TooltipProps> = {
80 hoverCloseDelay: 0,
81 hoverOpenDelay: 100,
82 minimal: false,
83 transitionDuration: 100,
84 };
85
86 // eslint-disable-next-line deprecation/deprecation
87 private popover: Popover | null = null;
88
89 public render() {
90 const { children, intent, popoverClassName, ...restProps } = this.props;
91 const classes = classNames(
92 Classes.TOOLTIP,
93 { [Classes.MINIMAL]: this.props.minimal },
94 Classes.intentClass(intent),
95 popoverClassName,
96 );
97
98 return (
99 /* eslint-disable deprecation/deprecation */
100 <Popover
101 interactionKind={PopoverInteractionKind.HOVER_TARGET_ONLY}
102 modifiers={{ arrow: { enabled: !this.props.minimal } }}
103 {...restProps}
104 autoFocus={false}
105 canEscapeKeyClose={false}
106 enforceFocus={false}
107 lazy={true}
108 popoverClassName={classes}
109 portalContainer={this.props.portalContainer}
110 ref={ref => (this.popover = ref)}
111 >
112 {children}
113 </Popover>
114 );
115 }
116
117 public reposition() {
118 if (this.popover != null) {
119 this.popover.reposition();
120 }
121 }
122}