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

Commit 8a034c6

Browse files
authored
Merge pull request #347 from atomiks/patch-1
docs: simplify and collapse render props into <details>
2 parents 2db0b0d + 38b8109 commit 8a034c6

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ React wrapper around [Popper](https://popper.js.org).
1212
**important note:** Popper is **not** a tooltip library, it's a _positioning
1313
engine_ to be used to build features such as (but not restricted to) tooltips.
1414

15-
# Install
15+
## Install
1616

1717
Via package managers:
1818

@@ -33,14 +33,14 @@ Via `script` tag (UMD library exposed as `ReactPopper`):
3333
<script src="https://unpkg.com/react-popper/dist/index.umd.js"></script>
3434
```
3535

36-
# Usage
36+
## Usage
3737

3838
> Using `[email protected]`? You can find its documentation
3939
> [clicking here](https://github.com/souporserious/react-popper/tree/v0.x)
4040
4141
`react-popper` provides two different APIs to help consume it:
4242

43-
## React Hooks
43+
### 1. React Hooks (recommended)
4444

4545
The `usePopper` hook can be used to quickly initialize a Popper, it requires a
4646
basic understanding of how the
@@ -72,7 +72,12 @@ const Example = () => {
7272
};
7373
```
7474

75-
## Render Props
75+
### 2. Render Props (legacy)
76+
77+
This is a legacy API for compatibility with v1.x users moving to Popper v2. We recommend using the `usePopper` Hook in new code.
78+
79+
<details>
80+
<summary>View details</summary>
7681

7782
The `Manager`, `Reference` and `Popper` render-props components offer an
7883
alternative API to initialize a Popper instance, they require a basic
@@ -103,9 +108,11 @@ const Example = () => (
103108
);
104109
```
105110

111+
</details>
112+
106113
## API documentation
107114

108-
### Hooks
115+
### `usePopper`
109116

110117
The `usePopper` hook provides an API almost identical to the ones of
111118
[`createPopper`](https://popper.js.org/docs/v2/constructors/#createpopper)
@@ -152,6 +159,11 @@ has been destroyed.
152159

153160
### Render Props
154161

162+
This is a legacy API for compatibility with v1.x users moving to Popper v2. We recommend using the `usePopper` Hook in new code.
163+
164+
<details>
165+
<summary>View details</summary>
166+
155167
The `Manager` component is a simple wrapper that needs to surround all the other
156168
`react-popper` components in order to make them communicate with each others.
157169

@@ -255,6 +267,8 @@ An object containing custom settings for the
255267
You can use this property to override their settings or to inject your custom
256268
ones.
257269
270+
</details>
271+
258272
## Usage with `ReactDOM.createPortal`
259273
260274
Popper.js is smart enough to work even if the **popper** and **reference**
@@ -266,7 +280,7 @@ React 16 alternative) to move the popper component somewhere else in the DOM.
266280
This can be useful if you want to position a tooltip inside an
267281
`overflow: hidden` container that you want to make overflow.
268282
269-
**Please note that you can also try `strategy="fixed"` to obtain a similar
283+
**Please note that you can also try `strategy: 'fixed'` to obtain a similar
270284
effect with less hassle.**
271285
272286
```jsx
@@ -300,16 +314,7 @@ const Example = () => {
300314
## Usage without a reference `HTMLElement`
301315
302316
Whenever you need to position a popper based on some arbitrary coordinates, you
303-
can provide `Popper` with a `referenceElement` property that is going to be used
304-
in place of the `referenceProps.getRef` React ref.
305-
306-
The `referenceElement` property must be an object with an interface compatible
307-
with an `HTMLElement` as described in the
308-
[Popper.js virtualElement documentation](https://popper.js.org/docs/v2/virtual-elements/),
309-
this implies that you may also provide a real HTMLElement if needed.
310-
311-
If `referenceElement` is defined, it will take precedence over any
312-
`referenceProps.ref` provided refs.
317+
can provide Popper with a [virtual element](https://popper.js.org/docs/v2/virtual-elements/).
313318
314319
```jsx
315320
import { usePopper } from 'react-popper';
@@ -330,8 +335,6 @@ const virtualReference = {
330335
},
331336
};
332337

333-
// This popper will be positioned relatively to the
334-
// virtual reference element defined above
335338
const Example = () => {
336339
const [popperElement, setPopperElement] = React.useState(null);
337340
const { styles, attributes } = usePopper(virtualReference, popperElement);

0 commit comments

Comments
 (0)