Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bgonp committed Mar 6, 2021
1 parent 65c3625 commit 632fb64
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# React Drawable

Simple package that provide React components to draw lines using mouse or touch events.

## Prerequisites

- React >= 16.8

## Install

`npm install react-drawable --save`

## Usage

Keep in mind this component **has no styles**, so you should set at least its size to be able to use it. **You should handle this by providing a className and setting styles to it**. Same if you want to be able to draw over some other element or something special. **Be creative!** 😉

### Simple:
```javascript
import * as React from 'react'
import { DrawProvider } from 'react-drawable'

export const Sample = () => <DrawProvider className="drawable" />
```

### With options:
```javascript
import * as React from 'react'
import { DrawProvider } from 'react-drawable'

export const Sample = () => {
const [paused, setPaused] = React.useState(false)
const [hidden, setHidden] = React.useState(false)

return (
<>
<DrawProvider
className="drawable"
color="#ba324f"
disabled={paused}
hidden={hidden}
thickness={20}
/>
<button onClick={() => setPaused(paused => !paused)}>PAUSE</button>
<button onClick={() => setHidden(hidden => !hidden)}>HIDE</button>
</>
)
}
```

### Reset and undo buttons:
```javascript
import * as React from 'react'
import { DrawContext, DrawProvider } from 'react-drawable'

const Buttons = () => {
const { reset, undo } = React.useContext(DrawContext)

return (
<>
<button onClick={reset}>RESET</button>
<button onClick={undo}>UNDO</button>
</>
)
}

export const Sample = () => (
<DrawProvider className="drawable">
<img src="background.png" />
<Buttons />
</DrawProvider>
)
```

0 comments on commit 632fb64

Please sign in to comment.