Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit d85aba2

Browse files
authored
3.0 (#116)
1 parent 9777e8b commit d85aba2

17 files changed

+6947
-4437
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"rules": {
2323
"react/prop-types": "off",
2424
"no-unused-vars": ["error", { "ignoreRestSiblings": true }],
25-
"react-hooks/rules-of-hooks": "error"
25+
"react-hooks/rules-of-hooks": "error",
26+
"react/display-name": "off"
2627
}
2728
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
node_modules
23
coverage
34
.devserver

README.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
and popover library powered by Popper.js. This is a lightweight wrapper that
2121
lets you use it declaratively in React.
2222

23+
<!--
2324
## 💎 Examples
2425
2526
### Tooltips
@@ -30,6 +31,7 @@ lets you use it declaratively in React.
3031
### Popovers
3132
3233
- [Accessible Emoji Reaction Picker](https://codesandbox.io/s/1vzvoo9mwl)
34+
-->
3335

3436
## 🚀 Installation
3537

@@ -47,12 +49,14 @@ Requires React 16.8+
4749

4850
## 🖲 Usage
4951

50-
Wrap the `<Tippy />` component around the element, supplying the tooltip's
51-
content as the `content` prop. It can take a string or a tree of React elements.
52+
Import the `Tippy` component and the core CSS. Wrap the `<Tippy />` component
53+
around the element, supplying the tooltip's content as the `content` prop. It
54+
can take a string or a tree of React elements.
5255

5356
```jsx
5457
import React from 'react'
5558
import Tippy from '@tippy.js/react'
59+
import 'tippy.js/dist/tippy.css'
5660

5761
const StringContent = () => (
5862
<Tippy content="Hello">
@@ -101,22 +105,17 @@ element as a workaround.
101105

102106
```jsx
103107
<Tippy content="Tooltip">
104-
<span>
105-
<LegacyComponent>Unfortunately</LegacyComponent>
108+
<span tabindex="0">
109+
<LegacyComponent>Content</LegacyComponent>
106110
</span>
107111
</Tippy>
108112
```
109113

110-
> Although Tippy will add `tabindex` for you on the `<span>` which allows it to
111-
> receive focus, it may affect accessibility with regards to screenreaders,
112-
> since `<span>` is not traditionally focusable (unlike a `<button>` for
113-
> example).
114-
115114
## 🧬 Props
116115

117-
All of the native Tippy.js options can be passed as props.
116+
All of the native Tippy.js props can be passed to the component.
118117

119-
Visit [All Options](https://atomiks.github.io/tippyjs/all-options/) to view the
118+
Visit [All Props](https://atomiks.github.io/tippyjs/all-props/) to view the
120119
complete table.
121120

122121
```jsx
@@ -132,9 +131,9 @@ complete table.
132131
</Tippy>
133132
```
134133

135-
In addition, there are 4 more props added specifically for the React component.
134+
In addition, there are 3 more props added specifically for the React component.
136135

137-
### `className?: string` (v2.1)
136+
### `className?: string`
138137

139138
A React alternative to the `theme` prop. The className gets added to the tooltip
140139
element's class list as expected, without adding `-theme` as a suffix.
@@ -205,28 +204,28 @@ function App() {
205204
> **Note**: You should also set the `hideOnClick` prop to `false` if you don't
206205
> want the tippy to hide when the user clicks on the document somewhere.
207206
208-
### `onCreate?: (instance: Instance) => void`
209-
210-
Callback invoked when the tippy instance has been created. Use this when you
211-
need to store the tippy instance on the component.
207+
### Plugins
212208

213-
This should only be done for advanced (imperative) manipulation of the tippy
214-
instance – in most cases using props should suffice.
209+
Tippy.js splits certain props into separate pieces of code called plugins to
210+
enable treeshaking, so that users who don't need the prop's functionality are
211+
not burdened with the cost of it.
215212

216213
```jsx
214+
import Tippy from '@tippy.js/react'
215+
import { followCursor } from 'tippy.js'
216+
import 'tippy.js/dist/tippy.css'
217+
217218
function App() {
218-
const tippyInstance = useRef()
219219
return (
220-
<Tippy
221-
content="Tooltip"
222-
onCreate={instance => (tippyInstance.current = instance)}
223-
>
220+
<Tippy content="Tooltip" followCursor={true} plugins={[followCursor]}>
224221
<button />
225222
</Tippy>
226223
)
227224
}
228225
```
229226

227+
[Read more about plugins here](https://atomiks.github.io/tippyjs/plugins/).
228+
230229
### Default props
231230

232231
You can create a new component file that exports a wrapper component that has
@@ -264,7 +263,6 @@ export function Tooltip(props) {
264263
export function Popover(props) {
265264
return (
266265
<Tippy
267-
animateFill={false}
268266
interactive={true}
269267
interactiveBorder={10}
270268
animation="scale"
@@ -295,24 +293,25 @@ You can nest the components like so:
295293
</Tippy>
296294
```
297295

298-
## 📚 `<TippyGroup />`
296+
## 📚 `<TippySingleton />`
299297

300-
Wraps the [`tippy.group()`](https://atomiks.github.io/tippyjs/misc/#groups)
298+
Wraps the
299+
[`createSingleton()`](https://atomiks.github.io/tippyjs/addons/#singleton)
301300
method.
302301

303302
```jsx
304-
import Tippy, { TippyGroup } from '@tippy.js/react'
303+
import Tippy, { TippySingleton } from '@tippy.js/react'
305304

306305
function App() {
307306
return (
308-
<TippyGroup delay={1000}>
307+
<TippySingleton delay={1000}>
309308
<Tippy content="a">
310309
<button />
311310
</Tippy>
312311
<Tippy content="b">
313312
<button />
314313
</Tippy>
315-
</TippyGroup>
314+
</TippySingleton>
316315
)
317316
}
318317
```
@@ -322,7 +321,7 @@ function App() {
322321
<img src="https://img.shields.io/bundlephobia/minzip/@tippy.js/react.svg?color=%2373bd4b&style=for-the-badge" alt="Bundle size">
323322

324323
- `popper.js` ≈ 7 kB
325-
- `tippy.js`7.5 kB (including CSS)
324+
- `tippy.js`5.5 kB (including CSS)
326325
- `@tippy.js/react` ≈ 1 kB
327326

328327
If you're using Popper.js for other parts of your app, the added cost becomes

demo/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, { useState, useEffect } from 'react'
22
import ReactDOM from 'react-dom'
3-
import Tippy, { TippyGroup } from '../src'
3+
import Tippy, { TippySingleton } from '../src'
4+
import { followCursor } from 'tippy.js'
5+
6+
import 'tippy.js/dist/tippy.css'
47
import './index.css'
58

69
function ContentString() {
@@ -66,7 +69,7 @@ function VisibleProp() {
6669
)
6770
}
6871

69-
function Group() {
72+
function Singleton() {
7073
const [count, setCount] = useState(3)
7174

7275
let children = []
@@ -84,7 +87,15 @@ function Group() {
8487
}, 5000)
8588
}, [])
8689

87-
return <TippyGroup delay={500}>{children}</TippyGroup>
90+
return <TippySingleton delay={500}>{children}</TippySingleton>
91+
}
92+
93+
function FollowCursor() {
94+
return (
95+
<Tippy content="hi" followCursor={true} plugins={[followCursor]}>
96+
<button>followCursor</button>
97+
</Tippy>
98+
)
8899
}
89100

90101
function App() {
@@ -96,8 +107,10 @@ function App() {
96107
<h2>Special</h2>
97108
<EnabledProp />
98109
<VisibleProp />
99-
<h2>Group dynamic children</h2>
100-
<Group />
110+
<h2>Singleton dynamic children</h2>
111+
<Singleton />
112+
<h2>Plugins</h2>
113+
<FollowCursor />
101114
</>
102115
)
103116
}

index.d.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import * as React from 'react'
2-
import { default as tippyCore, Instance, Options, GroupOptions } from 'tippy.js'
2+
import { default as tippyCore, Instance, Props, Plugin } from 'tippy.js'
33

44
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
55

6-
export interface TippyProps extends Omit<Options, 'content'> {
6+
export interface TippyProps extends Omit<Props, 'content'> {
77
content: React.ReactChild | React.ReactChild[]
88
children: React.ReactElement<any>
9-
onCreate?: (instance: Instance) => void
10-
/** @deprecated Use `visible` instead */
11-
isVisible?: boolean
12-
/** @deprecated Use `enabled` instead */
13-
isEnabled?: boolean
149
visible?: boolean
1510
enabled?: boolean
1611
className?: string
12+
plugins?: Plugin[]
1713
}
1814

1915
declare const Tippy: React.ForwardRefExoticComponent<TippyProps>
2016
export default Tippy
2117

22-
export const tippy: typeof tippyCore;
18+
export const tippy: typeof tippyCore
2319

24-
export interface TippyGroupProps extends GroupOptions {
20+
export interface TippySingletonProps extends Props {
2521
children: Array<React.ReactElement<any>>
2622
}
2723

28-
export const TippyGroup: React.FunctionComponent<TippyGroupProps>
24+
export const TippySingleton: React.FunctionComponent<TippySingletonProps>

0 commit comments

Comments
 (0)