Skip to content

Commit b5da7c6

Browse files
authored
Merge pull request #33 from mohsinulhaq/typescript
switch to TypeScript
2 parents 4f912bc + e5d9421 commit b5da7c6

26 files changed

+1120
-1154
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

.size-snapshot.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"dist/cjs/react-popper-tooltip.js": {
3-
"bundled": 14340,
4-
"minified": 7879,
5-
"gzipped": 2190
3+
"bundled": 14704,
4+
"minified": 7887,
5+
"gzipped": 2209
66
},
77
"dist/esm/react-popper-tooltip.js": {
8-
"bundled": 14288,
9-
"minified": 7846,
10-
"gzipped": 2185,
8+
"bundled": 14652,
9+
"minified": 7854,
10+
"gzipped": 2204,
1111
"treeshaked": {
1212
"rollup": {
13-
"code": 7271,
13+
"code": 7279,
1414
"import_statements": 331
1515
},
1616
"webpack": {
17-
"code": 8505
17+
"code": 8513
1818
}
1919
}
2020
}

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ branches:
77
except:
88
- gh-pages
99
script:
10+
- yarn typecheck
1011
- yarn lint
1112
- yarn test --ci --coverage
1213
- yarn build

README.md

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# React Tooltip
2+
23
[![npm version](https://img.shields.io/npm/v/react-popper-tooltip.svg?style=flat-square)](https://www.npmjs.com/package/react-popper-tooltip)
34
[![npm downloads](https://img.shields.io/npm/dm/react-popper-tooltip.svg?style=flat-square)](https://www.npmjs.com/package/react-popper-tooltip)
45
[![Build Status](https://travis-ci.com/mohsinulhaq/react-popper-tooltip.svg?branch=master)](https://travis-ci.com/mohsinulhaq/react-popper-tooltip)
56
[![Dependency Status](https://img.shields.io/david/mohsinulhaq/react-popper-tooltip.svg?style=flat-square)](https://david-dm.org/mohsinulhaq/react-popper-tooltip)
67
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
78
[![codecov](https://codecov.io/gh/mohsinulhaq/react-popper-tooltip/branch/master/graph/badge.svg)](https://codecov.io/gh/mohsinulhaq/react-popper-tooltip)
89

9-
React tooltip component based on [react-popper](https://github.com/FezVrasta/react-popper), the
10-
React wrapper around [popper.js](https://popper.js.org/) library.
10+
React tooltip component based on [react-popper](https://github.com/FezVrasta/react-popper), the React wrapper around [popper.js](https://popper.js.org/) library.
1111

1212
## Homepage
13+
1314
https://mohsinulhaq.github.io/react-popper-tooltip/
1415

1516
## Example
17+
1618
https://codesandbox.io/s/pykkz77z5j
1719

1820
### Usage
1921

2022
```bash
2123
npm install react-popper-tooltip
2224
```
25+
2326
or
27+
2428
```bash
2529
yarn add react-popper-tooltip
2630
```
@@ -31,10 +35,10 @@ import {render} from 'react-dom';
3135
import TooltipTrigger from 'react-popper-tooltip';
3236

3337
const Tooltip = ({
34-
getTooltipProps,
35-
getArrowProps,
36-
tooltipRef,
3738
arrowRef,
39+
tooltipRef,
40+
getArrowProps,
41+
getTooltipProps,
3842
placement
3943
}) => (
4044
<div
@@ -47,8 +51,8 @@ const Tooltip = ({
4751
<div
4852
{...getArrowProps({
4953
ref: arrowRef,
50-
'data-placement': placement,
51-
className: 'tooltip-arrow'
54+
className: 'tooltip-arrow',
55+
'data-placement': placement
5256
/* your props here */
5357
})}
5458
/>
@@ -69,11 +73,7 @@ const Trigger = ({getTriggerProps, triggerRef}) => (
6973
);
7074

7175
render(
72-
<TooltipTrigger
73-
placement="right"
74-
trigger="click"
75-
tooltip={Tooltip}
76-
>
76+
<TooltipTrigger placement="right" trigger="click" tooltip={Tooltip}>
7777
{Trigger}
7878
</TooltipTrigger>,
7979
document.getElementById('root')
@@ -95,14 +95,14 @@ import React from 'react';
9595
import TooltipTrigger from 'react-popper-tooltip';
9696
import 'react-popper-tooltip/dist/styles.css';
9797

98-
const Tooltip = ({tooltip, children, hideArrow ...props}) => (
98+
const Tooltip = ({children, tooltip, hideArrow, ...props}) => (
9999
<TooltipTrigger
100100
{...props}
101101
tooltip={({
102-
getTooltipProps,
103-
getArrowProps,
104-
tooltipRef,
105102
arrowRef,
103+
tooltipRef,
104+
getArrowProps,
105+
getTooltipProps,
106106
placement
107107
}) => (
108108
<div
@@ -111,13 +111,15 @@ const Tooltip = ({tooltip, children, hideArrow ...props}) => (
111111
className: 'tooltip-container'
112112
})}
113113
>
114-
{!hideArrow && <div
115-
{...getArrowProps({
116-
ref: arrowRef,
117-
'data-placement': placement,
118-
className: 'tooltip-arrow'
119-
})}
120-
/>}
114+
{!hideArrow && (
115+
<div
116+
{...getArrowProps({
117+
ref: arrowRef,
118+
className: 'tooltip-arrow',
119+
'data-placement': placement
120+
})}
121+
/>
122+
)}
121123
{tooltip}
122124
</div>
123125
)}
@@ -138,24 +140,31 @@ const Tooltip = ({tooltip, children, hideArrow ...props}) => (
138140
export default Tooltip;
139141
```
140142

141-
Then you can use it as shown in the example below.
143+
Then you can use it as shown in the example below.
142144

143145
```jsx
144-
<Tooltip placement="top" trigger="click" tooltip="Hi there!">Click me</Tooltip>
146+
<Tooltip placement="top" trigger="click" tooltip="Hi there!">
147+
Click me
148+
</Tooltip>
145149
```
146150

147151
## Examples
152+
148153
To fiddle with our example recipes, run:
154+
149155
```bash
150156
> npm install
151157
> npm run docs
152158
```
159+
153160
or
161+
154162
```bash
155163
> yarn
156164
> yarn docs
157165
```
158-
and open up [localhost:3000](http://localhost:3000) in your browser.
166+
167+
and open up [localhost:3000](http://localhost:3000) in your browser.
159168

160169
## Props
161170

@@ -173,7 +182,6 @@ the section "[Children and tooltip functions](#children-and-tooltip-functions)".
173182
This is called with an object. Read more about the properties of this object in
174183
the section "[Children and tooltip functions](#children-and-tooltip-functions)".
175184

176-
177185
### defaultTooltipShown
178186

179187
> `boolean` | defaults to `false`
@@ -192,9 +200,9 @@ Called with the tooltip state, when the visibility of the tooltip changes
192200
193201
Use this prop if you want to control the visibility state of the tooltip.
194202

195-
`react-popper-tooltip` manages its own state internally. You can use this prop to pass the
196-
visibility state of the tooltip from the outside. You will be required to keep this state up to
197-
date (this is where `onVisibilityChange` becomes useful), but you can also control the state
203+
`react-popper-tooltip` manages its own state internally. You can use this prop to pass the
204+
visibility state of the tooltip from the outside. You will be required to keep this state up to
205+
date (this is where `onVisibilityChange` becomes useful), but you can also control the state
198206
from anywhere, be that state from other components, `redux`, `react-router`, or anywhere else.
199207

200208
### delayShow
@@ -214,25 +222,27 @@ Delay in hiding the tooltip (ms).
214222
> `string` | defaults to `right`
215223
216224
The tooltip placement. Valid placements are:
225+
217226
- `auto`
218227
- `top`
219228
- `right`
220229
- `bottom`
221230
- `left`
222231

223232
Each placement can have a variation from this list:
233+
224234
- `-start`
225235
- `-end`
226236

227237
### trigger
228238

229-
> `string` | defaults to `hover`
239+
> `string` | defaults to `hover`
230240
231241
The event that triggers the tooltip. One of `click`, `hover`, `right-click`, `none`.
232242

233243
### getTriggerRef
234244

235-
> `function(HTMLElement) => void`
245+
> `function(HTMLElement) => void`
236246
237247
Function that can be used to obtain a trigger element reference.
238248

@@ -264,10 +274,10 @@ Recommended usage with hover trigger and no arrow element
264274

265275
### modifiers
266276

267-
> `object`
277+
> `object`
268278
269-
Modifiers passed directly to the underlying popper.js instance.
270-
For more information, refer to Popper.js’
279+
Modifiers passed directly to the underlying popper.js instance.
280+
For more information, refer to Popper.js’
271281
[modifier docs](https://popper.js.org/popper-documentation.html#modifiers)
272282

273283
Modifiers, applied by default:
@@ -283,8 +293,8 @@ Modifiers, applied by default:
283293
## Children and tooltip functions
284294

285295
This is where you render whatever you want. `react-popper-tooltip` uses two render props `children`
286-
and `tooltip`. `Children` prop is used to trigger the appearance of the tooltip and `tooltip`
287-
displays the tooltip itself.
296+
and `tooltip`. `Children` prop is used to trigger the appearance of the tooltip and `tooltip`
297+
displays the tooltip itself.
288298

289299
You use it like so:
290300

@@ -302,33 +312,32 @@ const tooltip = (
302312

303313
> See [the blog post about prop getters](https://blog.kentcdodds.com/how-to-give-rendering-control-to-users-with-prop-getters-549eaef76acf)
304314
305-
These functions are used to apply props to the elements that you render.
306-
It's advisable to pass all your props to that function rather than applying them on the element
315+
These functions are used to apply props to the elements that you render.
316+
It's advisable to pass all your props to that function rather than applying them on the element
307317
yourself to avoid your props being overridden (or overriding the props returned). For example
308318
`<button {...getTriggerProps({onClick: event => console.log(event))}>Click me</button>`
309319

310320
### children function
311321

312322
| property | type | description |
313323
| --------------- | -------------- | --------------------------------------------------------------------- |
324+
| triggerRef | `function ref` | returns the react ref you should apply to the trigger element. |
314325
| getTriggerProps | `function({})` | returns the props you should apply to the trigger element you render. |
315-
| triggerRef | `node` | returns the react ref you should apply to the trigger element. |
316-
317326

318327
### tooltip function
319328

320-
| property | type | description |
321-
| --------------- | -------------- | ---------------------------------------------------------------------- |
322-
| getTooltipProps | `function({})` | returns the props you should apply to the tooltip element you render. |
323-
| tooltipRef | `node` | return the react ref you should apply to the tooltip element. |
324-
| getArrowProps | `function({})` | return the props you should apply to the tooltip arrow element. |
325-
| arrowRef | `node` | return the react ref you should apply to the tooltip arrow element. |
326-
| placement | `string` | return the placement of the tooltip. |
329+
| property | type | description |
330+
| --------------- | -------------- | --------------------------------------------------------------------- |
331+
| arrowRef | `function ref` | return the react ref you should apply to the tooltip arrow element. |
332+
| tooltipRef | `function ref` | return the react ref you should apply to the tooltip element. |
333+
| getArrowProps | `function({})` | return the props you should apply to the tooltip arrow element. |
334+
| getTooltipProps | `function({})` | returns the props you should apply to the tooltip element you render. |
335+
| placement | `string` | return the dynamic placement of the tooltip. |
327336

328337
## Inspiration and Thanks!
329338

330-
This library is based on [react-popper](https://github.com/FezVrasta/react-popper), the official
339+
This library is based on [react-popper](https://github.com/FezVrasta/react-popper), the official
331340
react wrapper around [Popper.js](https://popper.js.org).
332341

333-
Using of render props, prop getters and doc style of this library are heavily inspired by
342+
Using of render props, prop getters and doc style of this library are heavily inspired by
334343
[downshift](https://github.com/paypal/downshift).

babel.config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
module.exports = {
2-
presets: [['@babel/env', {loose: true}], '@babel/react'],
3-
plugins: [
4-
['@babel/proposal-class-properties', {loose: true}],
5-
['transform-react-remove-prop-types', {removeImport: true}]
6-
]
2+
presets: ['@babel/typescript', '@babel/react', ['@babel/env', {loose: true}]],
3+
plugins: [['@babel/proposal-class-properties', {loose: true}]]
74
};

0 commit comments

Comments
 (0)