# @dawnlabs/tacklebox

> React UX components for handling common interactions

Latest version **0.0.11** (published 2019-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dawnlabs/tacklebox
pnpm add @dawnlabs/tacklebox
yarn add @dawnlabs/tacklebox
bun add @dawnlabs/tacklebox
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2019-06-27 |
| First published | 2019-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 164 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | dawnlabs |
| Maintainers | briandennis, jakedex, mfix22, rabaut |
| Keywords | react, ux, hooks, interactions, collection |

## Links

- npm: https://www.npmjs.com/package/@dawnlabs/tacklebox
- Repository: https://github.com/dawnlabs/tacklebox
- Issues: https://github.com/dawnlabs/tacklebox/issues
- npm.io page: https://npm.io/package/@dawnlabs/tacklebox

## Dependencies (3)

- [copy-to-clipboard](https://npm.io/package/copy-to-clipboard.md) ^3.2.0
- [react-fast-compare](https://npm.io/package/react-fast-compare.md) 2.0.4
- [react-click-outside](https://npm.io/package/react-click-outside.md) ^3.0.1

## 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

- 0.0.11 (latest) — 2019-06-27
- 0.0.11-0 (next) — 2019-06-27
- 0.0.10 — 2019-04-02
- 0.0.9 — 2019-04-02
- 0.0.8 — 2019-04-02
- 0.0.7 — 2019-04-01
- 0.0.6 — 2019-03-14
- 0.0.5 — 2019-03-11
- 0.0.4 — 2019-02-22
- 0.0.3 — 2019-02-19
- 0.0.2 — 2019-02-07
- 0.0.1 — 2019-02-07

## README

# Tackle Box 🎣

> Collection of React user-experience hooks + containers for common interactions

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)

## Getting Started

```bash
yarn add @dawnlabs/tacklebox
```

## Usage

### `useAsyncCallback`

> 🎣 `hook`

Takes any function and gives you a loading and error state. Good for handling
general asynchronous interactions.

```js
import { useAsyncCallback } from '@dawnlabs/tacklebox'

function MyAsyncButton(props) {
  const [onClick, { loading, error, data }] = useAsyncCallback(props.onClick)

  return (
    <>
      {error && <span>{error}!</span>}
      <button onClick={onClick}>{loading ? 'Saving...' : 'Save'}</button>
      {data && <span>Success! {data}</span>}
    </>
  )
}
```

### `useKeyboardListener`

> 🎣 `hook`

Pass it a keyboard key and a handler to automatically listen for keyboard clicks.

##### Example

```js
import { useKeyboardListener } from '@dawnlabs/tacklebox'

function Modal(props) {
  useKeyboardListener('Escape', props.onClose)

  return <div>Hello World</div>
}
```

### `useTempValue`

> `hook` 🎣

Hook that gives you a temporary state value that you can either commit with `submit` or revert with `reset`.

##### Example

```javascript
import { useTempValue } from '@dawnlabs/tacklebox'

function MyForm(props) {
  const initialName = props.name
  const { hasChanged, value, onInputChange, submit, reset } = useTempValue(initialName)

  return (
    <form onSubmit={e => e.preventDefault()}>
      <input value={value || ''} onChange={onInputChange} />
      <button disabled={!hasChanged} onClick={submit}>
        Submit
      </button>
      <button disabled={!hasChanged} onClick={reset}>
        Cancel
      </button>
    </form>
  )
}
```

### `useCopyTextHandler`

> `hook` 🎣

Creates an `onClick` handler that copies the text you pass in, and updates the `copied` field accordingly.
**Note**: you must pass `onClick` to a `<button>` in order to copy the text.

##### Example

```javascript
import { useCopyTextHandler } from '@dawnlabs/tacklebox'

const interval = 2 * 1000 // 2 seconds

function MyCopyButton() {
  const { onClick, copied } = useCopyTextHandler('https://github.com/dawnlabs/tacklebox', {
    interval
  })

  return <button onClick={onClick}>{copied ? 'COPIED!' : 'Copy URL'}</button>
}
```

### `useOnline`

> `hook` 🎣

Subscribes to whether the network is online or off

##### Example

```javascript
import { useOnline } from '@dawnlabs/tacklebox'

function MyComponent() {
  const online = useOnline()
  return <span>You are {online ? 'online' : 'offline'}</span>
}
```

### Modal

> `wrapper HOC` component

Class controlled Modal component with click-away and ESC-key to close

##### Example

```javascript
import {Modal} from '@dawnlabs/tacklebox'

<Modal open={this.state.open} onClickAway={() => this.setState({ open: false})}>
  <form>
    <input placeholder="Enter name here . . ." />
  </form>
</>
```

### License

MIT

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