huanpenguin-tippy-react 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 atomiks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,420 @@
1
+ ### Fork of [Tippy-react](https://github.com/atomiks/tippyjs-react) with React 19 compatibility fixes
2
+
3
+ <div align="center">
4
+ <img src="https://github.com/atomiks/tippy.js-react/raw/master/logo.png" alt="Logo" height="105">
5
+ </div>
6
+
7
+ <div align="center">
8
+ <h1>Tippy.js for React</h1>
9
+ </div>
10
+
11
+ ⚠️⚠️⚠️
12
+
13
+ **If you're new here, we recommend using [Floating UI's React DOM Interactions package](https://floating-ui.com/docs/react-dom-interactions) instead of this library**. It offers a first class React experience rather than being a wrapper around a vanilla library and encourages much better accessibility practices with more flexibility.
14
+
15
+ If you want some out-of-the-box styling and animations, and are adding simple tooltips/popovers to your app, Tippy will still work fine. For more advanced/headless solutions, it's best to use Floating UI!
16
+
17
+ ⚠️⚠️⚠️
18
+
19
+ ---
20
+
21
+ [Tippy.js](https://github.com/atomiks/tippyjs/) is the complete tooltip,
22
+ popover, dropdown, and menu solution for the web, powered by Popper.
23
+
24
+ Tippy is an abstraction over Popper that provides common logic involved in all
25
+ types of elements that pop out on top of the UI, positioned next to a target or
26
+ reference element. This is a React wrapper for the core library, providing full
27
+ integration including headless rendering abilities.
28
+
29
+ ## 🚀 Installation
30
+
31
+ ```bash
32
+ # npm
33
+ npm i @tippyjs/react
34
+
35
+ # Yarn
36
+ yarn add @tippyjs/react
37
+ ```
38
+
39
+ CDN: https://unpkg.com/@tippyjs/react
40
+
41
+ ## 🖲 Usage
42
+
43
+ There are two ways to use this component:
44
+
45
+ - **Default**: With the built-in DOM rendering and optionally the default CSS.
46
+ This is complete "out of the box" behavior and requires no setup. If you want
47
+ something that just works, this is for you.
48
+ - **Headless**: With React's DOM rendering for improved usage with CSS-in-JS and
49
+ spring libraries. If you want greater control over your poppers to integrate
50
+ fully with design systems, this is for you.
51
+
52
+ Both may be used in conjunction.
53
+
54
+ ### Default Tippy
55
+
56
+ Import the `Tippy` component and (optionally) the core CSS. Wrap the `<Tippy />`
57
+ component around the element, supplying the tooltip's content as the `content`
58
+ prop. It can take a string or a tree of React elements.
59
+
60
+ ```jsx
61
+ import React from 'react';
62
+ import Tippy from '@tippyjs/react';
63
+ import 'tippy.js/dist/tippy.css'; // optional
64
+
65
+ const StringContent = () => (
66
+ <Tippy content="Hello">
67
+ <button>My button</button>
68
+ </Tippy>
69
+ );
70
+
71
+ const JSXContent = () => (
72
+ <Tippy content={<span>Tooltip</span>}>
73
+ <button>My button</button>
74
+ </Tippy>
75
+ );
76
+ ```
77
+
78
+ Default Tippy "just works" out of the box.
79
+
80
+ ### Headless Tippy
81
+
82
+ Render your own tippy element from scratch:
83
+
84
+ ```jsx
85
+ import React from 'react';
86
+ import Tippy from '@tippyjs/react/headless'; // different import path!
87
+
88
+ const HeadlessTippy = () => (
89
+ <Tippy
90
+ render={attrs => (
91
+ <div className="box" tabIndex="-1" {...attrs}>
92
+ My tippy box
93
+ </div>
94
+ )}
95
+ >
96
+ <button>My button</button>
97
+ </Tippy>
98
+ );
99
+ ```
100
+
101
+ `attrs` is an object containing `data-placement`, `data-reference-hidden`, and
102
+ `data-escaped` attributes. This allows you to conditionally style your tippy.
103
+
104
+ #### Headless animation
105
+
106
+ - [`framer-motion`](https://codesandbox.io/s/festive-fire-hcr47)
107
+ - [`react-spring`](https://codesandbox.io/s/vigilant-northcutt-7w3yr)
108
+
109
+ #### Headless arrow
110
+
111
+ To make Popper position your custom arrow, set a `data-popper-arrow` attribute
112
+ on it:
113
+
114
+ ```jsx
115
+ <Tippy
116
+ render={attrs => (
117
+ <Box {...attrs}>
118
+ Hello
119
+ <Arrow data-popper-arrow="" />
120
+ </Box>
121
+ )}
122
+ >
123
+ <button>Reference</button>
124
+ </Tippy>
125
+ ```
126
+
127
+ For details on styling the arrow from scratch,
128
+ [take a look at the Popper tutorial](https://popper.js.org/docs/v2/tutorial/#arrow).
129
+
130
+ **Note: your arrow must be an `HTMLElement` (not an `SVGElement`). To use an SVG
131
+ arrow, wrap it in a `<div>` tag with the `data-popper-arrow` attribute.**
132
+
133
+ You may also pass a ref to the element directly without the attribute using a
134
+ callback ref:
135
+
136
+ ```jsx
137
+ function App() {
138
+ const [arrow, setArrow] = useState(null);
139
+
140
+ return (
141
+ <Tippy
142
+ render={attrs => (
143
+ <Box {...attrs}>
144
+ Content
145
+ <Arrow ref={setArrow} />
146
+ </Box>
147
+ )}
148
+ popperOptions={{
149
+ modifiers: [
150
+ {
151
+ name: 'arrow',
152
+ options: {
153
+ element: arrow, // can be a CSS selector too
154
+ },
155
+ },
156
+ ],
157
+ }}
158
+ >
159
+ <button>Reference</button>
160
+ </Tippy>
161
+ );
162
+ }
163
+ ```
164
+
165
+ #### Headless root element
166
+
167
+ When rendering an element with the `render` prop, you're rendering the inner
168
+ element that the root popper (positioned) node wraps.
169
+
170
+ For advanced cases you can access the root element via `instance.popper`.
171
+
172
+ [Here's `moveTransition` with Framer Motion](https://codesandbox.io/s/tippyjs-react-framer-motion-j94mj).
173
+
174
+ ### Component children
175
+
176
+ If you want to use a component element as a child of the component, ensure you
177
+ forward the ref to the DOM node:
178
+
179
+ ```jsx
180
+ import React, {forwardRef} from 'react';
181
+
182
+ function ThisWontWork() {
183
+ return <button>Reference</button>;
184
+ }
185
+
186
+ const ThisWillWork = forwardRef((props, ref) => {
187
+ return <button ref={ref}>Reference</button>;
188
+ });
189
+
190
+ function App() {
191
+ return (
192
+ <Tippy content="Tooltip">
193
+ <ThisWillWork />
194
+ </Tippy>
195
+ );
196
+ }
197
+ ```
198
+
199
+ `styled-components` v4+ does this for you automatically, so it should be
200
+ seamless when using the `styled` constructor.
201
+
202
+ Workaround for old libraries that don't forward the ref is to use a `<span>`
203
+ wrapper tag:
204
+
205
+ ```jsx
206
+ <Tippy content="Tooltip">
207
+ <span tabIndex="0">
208
+ <LegacyComponent>Reference</LegacyComponent>
209
+ </span>
210
+ </Tippy>
211
+ ```
212
+
213
+ ## 🧬 Props
214
+
215
+ All of the native Tippy.js props can be passed to the component.
216
+
217
+ Visit [All Props](https://atomiks.github.io/tippyjs/v6/all-props/) to view the
218
+ complete list.
219
+
220
+ ```jsx
221
+ <Tippy content="Tooltip" interactive={true} interactiveBorder={20} delay={100}>
222
+ <button>Reference</button>
223
+ </Tippy>
224
+ ```
225
+
226
+ In addition, there are 3 more props added specifically for the React component.
227
+
228
+ ### `className?: string`
229
+
230
+ ```jsx
231
+ <Tippy content="Tooltip" className="hello world">
232
+ <button>Reference</button>
233
+ </Tippy>
234
+ ```
235
+
236
+ This allows you to use `styled(Tippy)` or the `css` prop in `styled-components`
237
+ or `emotion`.
238
+
239
+ > Note: Does not apply if using Headless Tippy.
240
+
241
+ ### `disabled?: boolean`
242
+
243
+ ```jsx
244
+ function App() {
245
+ const [disabled, setDisabled] = useState(false);
246
+
247
+ return (
248
+ <Tippy content="Tooltip" disabled={disabled}>
249
+ <button>Reference</button>
250
+ </Tippy>
251
+ );
252
+ }
253
+ ```
254
+
255
+ ### `visible?: boolean` (controlled mode)
256
+
257
+ Use React's state to fully control the tippy instead of relying on the native
258
+ `trigger` and `hideOnClick` props:
259
+
260
+ ```jsx
261
+ function App() {
262
+ const [visible, setVisible] = useState(true);
263
+ const show = () => setVisible(true);
264
+ const hide = () => setVisible(false);
265
+
266
+ return (
267
+ <Tippy content="Tooltip" visible={visible} onClickOutside={hide}>
268
+ <button onClick={visible ? hide : show}>Reference</button>
269
+ </Tippy>
270
+ );
271
+ }
272
+ ```
273
+
274
+ ### `reference?: React.RefObject | Element`
275
+
276
+ > Available from `v4.1.0`
277
+
278
+ If you can't place your reference element as a child inside `<Tippy />`, you can
279
+ use this prop instead. It accepts a React `RefObject` (`.current` property) or a
280
+ plain `Element`.
281
+
282
+ ```jsx
283
+ function App() {
284
+ const ref = useRef();
285
+
286
+ return (
287
+ <>
288
+ <button ref={ref} />
289
+ <Tippy content="Tooltip" reference={ref} />
290
+ </>
291
+ );
292
+ }
293
+ ```
294
+
295
+ ### Plugins
296
+
297
+ Tippy.js splits certain props into separate pieces of code called plugins to
298
+ enable tree-shaking, so that components or routes that don't need the prop's
299
+ functionality are not burdened with the bundle size cost of it. In addition,
300
+ they enable a neat way to extend the functionality of tippy instances.
301
+
302
+ ```jsx
303
+ import Tippy from '@tippyjs/react';
304
+ // ⚠️ import from 'tippy.js/headless' if using Headless Tippy
305
+ import {followCursor} from 'tippy.js';
306
+
307
+ function App() {
308
+ return (
309
+ <Tippy content="Tooltip" followCursor={true} plugins={[followCursor]}>
310
+ <button>Reference</button>
311
+ </Tippy>
312
+ );
313
+ }
314
+ ```
315
+
316
+ [Read more about plugins here](https://atomiks.github.io/tippyjs/v6/plugins/).
317
+
318
+ ## 🌈 Multiple tippies on a single element
319
+
320
+ You can nest the components like so:
321
+
322
+ ```jsx
323
+ <Tippy content="Tooltip" placement="bottom">
324
+ <Tippy content="Tooltip" placement="left">
325
+ <Tippy content="Tooltip" placement="right">
326
+ <Tippy content="Tooltip">
327
+ <button>Reference</button>
328
+ </Tippy>
329
+ </Tippy>
330
+ </Tippy>
331
+ </Tippy>
332
+ ```
333
+
334
+ ## Lazy mounting
335
+
336
+ By default, Tippy mounts your `content` or `render` elements into a container
337
+ element once created, even if the tippy isn't mounted on the DOM. In most cases,
338
+ this is fine, but in performance-sensitive scenarios or cases where mounting the
339
+ component should fire effects only when the tippy mounted, you can lazify the
340
+ component.
341
+
342
+ [View the following gists to optimize your `<Tippy />` if needed.](https://gist.github.com/atomiks/520f4b0c7b537202a23a3059d4eec908)
343
+
344
+ ## 📚 useSingleton
345
+
346
+ A Hook for the
347
+ [`createSingleton()`](https://atomiks.github.io/tippyjs/v6/addons/#singleton)
348
+ addon to re-use a single tippy element for many different reference element
349
+ targets.
350
+
351
+ [View on CodeSandbox](https://codesandbox.io/s/unruffled-pasteur-4yy99?file=/src/App.js)
352
+
353
+ ```jsx
354
+ import Tippy, {useSingleton} from '@tippyjs/react';
355
+
356
+ function App() {
357
+ const [source, target] = useSingleton();
358
+
359
+ return (
360
+ <>
361
+ {/* This is the tippy that gets used as the singleton */}
362
+ <Tippy singleton={source} delay={500} />
363
+
364
+ {/* These become "virtual" */}
365
+ <Tippy content="Hello" singleton={target}>
366
+ <button>Reference</button>
367
+ </Tippy>
368
+ <Tippy content="Bye" singleton={target}>
369
+ <button>Reference</button>
370
+ </Tippy>
371
+ </>
372
+ );
373
+ }
374
+ ```
375
+
376
+ `useSingleton()` takes an optional props argument:
377
+
378
+ ```js
379
+ const [source, target] = useSingleton({
380
+ disabled: true,
381
+ overrides: ['placement'],
382
+ });
383
+ ```
384
+
385
+ ### Headless singleton
386
+
387
+ The `render` prop takes the singleton content as a second parameter:
388
+
389
+ ```jsx
390
+ import Tippy, {useSingleton} from '@tippyjs/react/headless';
391
+
392
+ function App() {
393
+ const [source, target] = useSingleton();
394
+
395
+ return (
396
+ <>
397
+ <Tippy
398
+ singleton={source}
399
+ render={(attrs, content) => (
400
+ <div className="box" tabIndex="-1" {...attrs}>
401
+ {content}
402
+ </div>
403
+ )}
404
+ delay={500}
405
+ />
406
+
407
+ <Tippy content="Hello" singleton={target}>
408
+ <button>Reference</button>
409
+ </Tippy>
410
+ <Tippy content="Bye" singleton={target}>
411
+ <button>Reference</button>
412
+ </Tippy>
413
+ </>
414
+ );
415
+ }
416
+ ```
417
+
418
+ ## 📝 License
419
+
420
+ MIT