An open API service indexing awesome lists of open source software.

https://github.com/mfix22/actionsack

🎒React UX components for handling common interactions
https://github.com/mfix22/actionsack

Last synced: 3 months ago
JSON representation

🎒React UX components for handling common interactions

Awesome Lists containing this project

README

        

# Action Sack 🎒

> 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 actionsack
```

## Usage

### `useAsyncCallback`

> 🎣 `hook`

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

```js
import { useAsyncCallback } from 'actionsack'

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

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

### `useKeyboardListener`

> 🎣 `hook`

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

##### Example

```js
import { useKeyboardListener } from 'actionsack'

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

return

Hello World

}
```

### `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 'actionsack'

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

return (
e.preventDefault()}>


Submit


Cancel


)
}
```

### `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 `` in order to copy the text.

For more information about `options`, see [API](https://github.com/sudodoki/copy-to-clipboard#api).

##### Example

```javascript
import { useCopyTextHandler } from 'actionsack'

const options = {
interval: 2 * 1000, // 2 seconds
format: "text/html",
}

function MyCopyButton() {
const { onClick, copied } = useCopyTextHandler('https://github.com/mfix22/actionsack', options)

return {copied ? 'COPIED!' : 'Copy URL'}
}
```

### `useOnline`

> `hook` 🎣

Subscribes to whether the network is online or off

##### Example

```javascript
import { useOnline } from 'actionsack'

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

### `TimeWindow`

Show children after a certain amount of time, for a certain amount of time.

##### Example

```js
import { TimeWindow } from 'actionsack'

function MyMessage() {
return (

Timed Message!

)
}
```

### `Modal`

> `wrapper HOC` component

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

##### Example

```javascript
import {Modal} from 'actionsack'

this.setState({ open: false})}>



>
```

### License

MIT