# react-popover-hook

> Ultra lightweight React hook for popovers, dropdowns, etc...

Latest version **1.0.3** (published 2020-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-popover-hook
pnpm add react-popover-hook
yarn add react-popover-hook
bun add react-popover-hook
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-10-03 |
| First published | 2020-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Jake |
| Maintainers | jakech |
| Keywords | react, hooks, popover, dropdown |

## Links

- npm: https://www.npmjs.com/package/react-popover-hook
- Repository: https://github.com/jakech/react-popover-hook
- Homepage: https://github.com/jakech/react-popover-hook#readme
- Issues: https://github.com/jakech/react-popover-hook/issues
- npm.io page: https://npm.io/package/react-popover-hook

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-10-03
- 1.0.2 — 2020-10-03
- 1.0.1 — 2020-10-03
- 1.0.0 — 2020-10-03

## README

![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-popover-hook)

# react-popover-hook

-   No extraneous DOM, gives you complete style control
-   Ultra lightweight [~ 1 kB (gzip)](https://bundlephobia.com/result?p=react-popover-hook)
-   Good a11y support
-   TypeScript

## Usage

```jsx
const App = () => {
    const [open, trigger, content] = usePopover(false)
    return (
        <div>
            <button {...trigger}>Trigger</button>
            {open && <div {...content}>Popover content</div>}
        </div>
    )
}
```

## API

```js
const [open, trigger, content] = usePopover(false)
```

`usePopover` takes a `boolean` for it's default open/close state.

The return value is an array with 3 items. Like the `useState` build-in hook, this allow you to name these items per your usecase.

For demo purpose we will name and refer to these items as `open`, `trigger` and `content`.

## `open`

`boolean` value indicating the open/close state of the popover

## `trigger`

An object containing the props for the trigger Component. it can be directly spreaded on the Component being used as trigger of the popover.

```jsx
<button {...trigger}>Click to open</button>
```

| key             | type        | desc                                                           |
| --------------- | ----------- | -------------------------------------------------------------- |
| `ref`           | `React.Ref` | **! important !** attached this `ref` to the trigger component |
| `onClick`       | `function`  | toggle the popover open/close state.                           |
| `aria-haspopup` | `string`    | value set to `dialog`                                          |
| `aria-expanded` | `boolean`   | reflect the open and close state of popover                    |

**! important !** popover content position will be calculated by using the trigger position.

## `content`

An object containing the props for the Component that contains the popover's content. it can be directly spreaded on the Component that contains the popover's content.

```jsx
<div {...content}>
    <p>Whatever content</p>
</div>
```

| key     | type            | desc                                                           |
| ------- | --------------- | -------------------------------------------------------------- |
| `ref`   | `React.Ref`     | **! important !** attached this `ref` to the content component |
| `role`  | `string`        | value set to `dialog`                                          |
| `style` | `CSSProperties` | style object                                                   |

**! important !** popover content position will be calculated by using the trigger position.

---
_Source: https://npm.io/package/react-popover-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
