2.2.2 • Published 3 years ago

react-drawable-overlay v2.2.2

Weekly downloads
227
License
MIT
Repository
github
Last release
3 years ago

react-drawable-overlay

A package for wrapping an element with a drawable canvas.

NPM JavaScript Style Guide

Install

$ npm install --save react-drawable-overlay
$ yarn add react-drawable-overlay

Usage

import React, { Component } from "react"
import { DrawableOverlay, useStage } from "react-drawable-overlay"

const Content = () => {
  const stage = useStage()

  return (
    <React.Fragment>
      <div style={{ position: "relative", height: 500, width: 500 }}>
        {stage}
      </div>
      <p>
        Content that cannot be drawn on but still has access to the
        Context-values
      </p>
      <Toolbar />
    </React.Fragment>
  )
}

const Example = () => {
  return (
    <DrawableOverlay initialInDrawMode defaultBrushColor="#000">
      <Content />
    </DrawableOverlay>
  )
}

Props

PropTypeDefaultDescription
initialInDrawModebooleanfalseWhether or not you can draw on the stage.
defaultBrushColorstring#000000Hexadecimal color on the initial render.
childrennode/node[]undefinedAll children have access to the context.
heightOffsetnumber0Used to narrow down drawable area in y-axis.
widthOffsetnumber0Used to narrow down drawable area in x-axis.
onAddToHistoryfunction(string/undefined)undefinedCallback on brush stroke.

State Context

KeyTypeDescription
drawMode"brush"/"eraser"Current draw mode.
brushSizenumberCurrent size for the brush-tool.
eraserSizenumberCurrent size for the eraser-tool.
brushColorstringHexadecimal color.
inDrawModebooleanWhether or not the stage can be drawn on.

Utils Context

KeyTypeDescription
resetfunction()Clear canvas. This also resets history and currentHistoryIndex.
setInitialDrawingfunction(string)Set a base-64 image as the initial drawing. Takes a base-64 image as an argument.
setDrawModefunction("brush"/"eraser")Set drawMode.
setBrushSizefunction(number)Set brushSize.
setEraserSizefunction(number)Set eraserSize.
setBrushColorfunction(string)Set brushColor. Takes a hexadecimal color as an argument.
setInDrawModefunction(boolean)Set inDrawMode.

History Context

KeyTypeDescription
undofunction()Undo latest brush stroke or eraser stroke.
redofunction()Redo latest brush stroke or eraser stroke.
currentHistoryIndexnumberCurrent index in history.
historystring[]Array of base-64 images.

Example

See the example-folder for an example on how to use the package.

License

MIT © SAITS

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago