# react-text-selection-popover

> A component for rendering popovers according to your current text selection

Latest version **2.0.2** (published 2022-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-text-selection-popover
pnpm add react-text-selection-popover
yarn add react-text-selection-popover
bun add react-text-selection-popover
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-10-11 |
| First published | 2018-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 295 |
| Author | Julian Krispel-Samsel |
| Maintainers | juliankrispel |

## Links

- npm: https://www.npmjs.com/package/react-text-selection-popover
- Repository: https://github.com/juliankrispel/react-text-selection-popover
- Homepage: https://juliankrispel.github.io/react-text-selection-popover/
- Issues: https://github.com/juliankrispel/react-text-selection-popover/issues
- npm.io page: https://npm.io/package/react-text-selection-popover

## Dependencies (1)

- [use-text-selection](https://npm.io/package/use-text-selection.md) ^1.1.3

## Recent versions

- 2.0.2 (latest) — 2022-10-11
- 2.0.1 — 2021-02-05
- 2.0.0 — 2021-02-03
- 1.3.2 — 2019-07-24
- 1.3.1 — 2019-07-24
- 1.3.0 — 2019-04-01
- 1.2.5 — 2019-04-01
- 1.2.4 — 2019-03-04
- 1.2.3 — 2019-02-12
- 1.2.2 — 2018-11-09
- 1.2.1 — 2018-10-04
- 1.2.0 — 2018-09-19
- 1.1.1 — 2018-09-13
- 1.1.0 — 2018-09-12
- 1.0.3 — 2018-09-11
- … 14 more at https://npm.io/package/react-text-selection-popover/versions

## README

# react-text-selection-popover

A react component that lets you render a popover in relation to the current text selection. 

[![NPM](https://img.shields.io/npm/v/react-text-selection-popover.svg)](https://www.npmjs.com/package/react-text-selection-popover) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)


## Install

```bash
npm install --save react-text-selection-popover
```

## Usage

```tsx
import css from '@emotion/css'

<Popover
  render={
    ({ clientRect, isCollapsed, textContent }) => {
      if (clientRect == null || isCollapsed) return null

      // I'm using emotion for this example but you can use anything really
      const style = css`
        position: absolute;
        left: ${clientRect.left + clientRect.width / 2}px;
        top: ${clientRect.top - 40}px;
        margin-left: -75px;
        width: 150px;
        background: blue;
        font-size: 0.7em;
        pointer-events: none;
        text-align: center;
        color: white;
        border-radius: 3px;
      `

      return <div className={style}>
        Selecting {(textContent || '').length} characters
      </div>
    }
  }
/>
```

### Props

| name | type | description |
| --- | ---- | --- |
| `render`  | `({ clientRect, isCollapsed, textContent }) => {}` | __required__ Render prop for rendering your popover, see above for usage |
| `mount`     | `HTMLElement` |  Dom Element that Popover will be rendered into (This component uses [React Portals](https://reactjs.org/docs/portals.html). Defaults to `document.body` |
| `target`    | `HTMLElement` | Dom Element which the popover is constrained to |

# Shoutouts

This was originally written during some freelance work for [Spectrum](https://spectrum.chat/). Shoutout to their awesomeness for letting me do all my work for them in the open!

## Work with me?

I build editors for companies, or help their teams do so. Hit me up on [my website](http://jkrsp.com) to get in touch about a project.

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