Skip to content

Commit d886755

Browse files
naortororta
andauthored
created typings for react-portal-tooltip (DefinitelyTyped#45221)
* bootstrap * react-tooltip-portal * linter fixes * Update types/react-portal-tooltip/index.d.ts Co-authored-by: Orta <[email protected]>
1 parent 7895fb3 commit d886755

File tree

7 files changed

+173
-0
lines changed

7 files changed

+173
-0
lines changed

types/react-portal-tooltip/index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Type definitions for react-portal-tooltip 2.4
2+
// Project: https://github.com/romainberger/react-portal-tooltip
3+
// Definitions by: naortor <https://github.com/naortor>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
import * as React from 'react';
7+
8+
import ToolTip from './lib/ToolTip';
9+
import StatefulToolTip from './lib/StatefulToolTip';
10+
11+
export default ToolTip;
12+
export { StatefulToolTip };
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
3+
declare class Card extends React.Component<Card.CardProps> {}
4+
5+
export default Card;
6+
7+
declare namespace Card {
8+
type Position = 'top' | 'right' | 'bottom' | 'left';
9+
type Arrow = null | 'center' | 'top' | 'right' | 'bottom' | 'left';
10+
type Align = null | 'center' | 'right' | 'left';
11+
12+
interface CardProps {
13+
position?: Position;
14+
arrow?: Arrow;
15+
align?: Align;
16+
useHover?: boolean;
17+
style?: {
18+
style?: React.CSSProperties;
19+
arrowStyle?: React.CSSProperties;
20+
};
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import ToolTip, { TooltipProps } from './ToolTip';
3+
4+
declare class StatefulToolTip extends React.Component<StatefulToolTipProps> {}
5+
6+
export default StatefulToolTip;
7+
8+
interface StatefulToolTipProps extends TooltipProps {
9+
className?: string;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
import Card from './Card';
3+
4+
declare class Tooltip extends React.Component<TooltipProps> {}
5+
6+
export default Tooltip;
7+
8+
export interface TooltipProps extends Card.CardProps {
9+
parent: string | JSX.Element | React.RefObject<unknown>;
10+
active?: boolean;
11+
group?: string;
12+
tooltipTimeout?: number;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import * as React from 'react';
2+
import ToolTip, { StatefulToolTip } from 'react-portal-tooltip';
3+
4+
// Tooltip test
5+
6+
class ToolTipTest extends React.Component {
7+
state = {
8+
isTooltipActive: false,
9+
};
10+
showTooltip() {
11+
this.setState({ isTooltipActive: true });
12+
}
13+
hideTooltip() {
14+
this.setState({ isTooltipActive: false });
15+
}
16+
render() {
17+
return (
18+
<div>
19+
<p id="text" onMouseEnter={this.showTooltip.bind(this)} onMouseLeave={this.hideTooltip.bind(this)}>
20+
This is a cool component
21+
</p>
22+
<ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent="#text">
23+
<div>
24+
<p>This is the content of the tooltip</p>
25+
<img src="image.png" />
26+
</div>
27+
</ToolTip>
28+
</div>
29+
);
30+
}
31+
}
32+
33+
// Parent props
34+
35+
class ToolTipTestParentProp1 extends React.Component {
36+
state = {
37+
isTooltipActive: false,
38+
};
39+
showTooltip() {
40+
this.setState({ isTooltipActive: true });
41+
}
42+
hideTooltip() {
43+
this.setState({ isTooltipActive: false });
44+
}
45+
render() {
46+
return (
47+
<div>
48+
<div id="hoverMe" onMouseEnter={this.showTooltip} onMouseLeave={this.hideTooltip}>
49+
Hover me!!!
50+
</div>
51+
<ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent="#hoverMe">
52+
<div>
53+
<p>This is the content of the tooltip</p>
54+
</div>
55+
</ToolTip>
56+
</div>
57+
);
58+
}
59+
}
60+
61+
class ToolTipTestParentProp2 extends React.Component {
62+
readonly element = React.createRef<HTMLDivElement>();
63+
64+
constructor(props: {}) {
65+
super(props);
66+
}
67+
state = {
68+
isTooltipActive: false,
69+
};
70+
showTooltip() {
71+
this.setState({ isTooltipActive: true });
72+
}
73+
hideTooltip() {
74+
this.setState({ isTooltipActive: false });
75+
}
76+
render() {
77+
return (
78+
<div>
79+
<div ref={this.element} onMouseEnter={this.showTooltip} onMouseLeave={this.hideTooltip}>
80+
Hover me!!!
81+
</div>
82+
<ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent={this.element}>
83+
<div>
84+
<p>This is the content of the tooltip</p>
85+
</div>
86+
</ToolTip>
87+
</div>
88+
);
89+
}
90+
}
91+
92+
// StatefulToolTip test
93+
94+
const StatefulToolTipTest = () => {
95+
const button = <span>Hover me to display the tooltip</span>;
96+
97+
return <StatefulToolTip parent={button}>Stateful Tooltip content here!</StatefulToolTip>;
98+
};
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["es6"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictFunctionTypes": true,
8+
"strictNullChecks": true,
9+
"baseUrl": "../",
10+
"typeRoots": ["../"],
11+
"types": [],
12+
"noEmit": true,
13+
"jsx": "react",
14+
"forceConsistentCasingInFileNames": true
15+
},
16+
"files": ["index.d.ts", "react-portal-tooltip-tests.tsx"]
17+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)